Files
Deepak Bisht 96924b8eee Merged PR 1672438: Support Compact in the vCore Backend engine
Yes
Feature
Yes
No

- Support compact database administration command behind the GUC `enableCompact`.

- Add support for compact command in backend using VACUUM FULL which is a blocking operation.
- Only one compact command can be run at a time on a specified collection.
- VACUUM FULL is run using libpq in a top level transaction as it it not supported inside functions or procedures.
- Add support of tracking compact command in current_op.
- `dryRun` estimation is based on the query defined [here at pgexperts](https://github.com/pgexperts/pgx_scripts/blob/master/bloat/table_bloat_check.sql), this can be a rough estimation and doesn't provided details about the space reclaimed by vacuuming RUM indexes of the collection.
- Read only users can't perform `compact` command.

----
New feature implementation to support the backend compact command.
This PR adds complete backend support for a blocking compact command that estimates table bloat and conditionally performs a VACUUM FULL operation on collection tables.
- `src/utils/storage_utils.c` and `include/utils/storage_utils.h`: Introduced a new bloat estimation utility returning collection bloat stats.
- `src/commands/compact.c`: Implemented the compact command including BSON command parsing, dry-run handling, and conditional execution of VACUUM FULL.
- `internal/pg_documentdb_distributed/src/test/regress/sql/command_compact.sql`: Added regression tests covering various compact command scenarios.
- `include/utils/feature_counter.h` and `src/infrastructure/feature_counter.c`: Updated feature counter mapping to include the new compact command feature.
<!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->

Related work items: #4237921
2025-06-05 10:31:32 +08:00

33 lines
967 B
C

/*-------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*
* include/utils/storage_utils.h
*
* Utilities that provide physical storage related metrics and information.
*
*-------------------------------------------------------------------------
*/
#include <postgres.h>
#include <nodes/parsenodes.h>
#ifndef DOCDB_STORAGE_UTILS_H
#define DOCDB_STORAGE_UTILS_H
#define BYTES_PER_MB (double) (1024 * 1024)
typedef struct CollectionBloatStats
{
/* Whether the PG stats are available or not for the collection */
bool nullStats;
/* Estimated bloats storage consumed by dead tuples for the colleciton in bytes based on PG relation's stats */
uint64 estimatedBloatStorage;
/* Estimated total collection size based on PG relation's stats */
uint64 estimatedTableStorage;
} CollectionBloatStats;
CollectionBloatStats GetCollectionBloatEstimate(uint64 collectionId);
#endif