tencent cloud

TencentDB for PostgreSQL

Release Notes and Announcements
Release Notes
Product Announcements
Product Introduction
Overview
Features
Strengths
Scenarios
Information Security
Regions and AZs
Product Feature List
Large version lifecycle description
MSSQL Compatible Version
Billing
Billing Overview
Instance Type and Specification
Purchase Methods
Refund
Overdue Payments
Backup Space Billing
Database Audit Billing Overview
Getting Started
Creating TencentDB for PostgreSQL Instance
Connecting to TencentDB for PostgreSQL Instance
Managing TencentDB for PostgreSQL Instance
Importing Data
Migrating Data with DTS
Kernel Version Introduction
Kernel Version Overview
Kernel Version Release Notes
Viewing Kernel Version
Proprietary Kernel Features
Database Audit
Audit Service Description
Activating Audit Service
View Audit Logs
Modify audit services
Audit Performance Description
User Guide
Instance Management
Upgrading Instance
CPU Elastic Scaling
Read-Only Instance
Account Management
Database Management
Parameter Management
Log Management and Analysis
Backup and Restoration
Data Migration
Extension Management
Network Management
Access Management
Data Security
Tenant and Resource Isolation
Security Groups
Monitoring and Alarms
Tag
AI Practice
Using the Tencentdb_ai Plug-In to Call Large Models
Building Ai Applications with the Tencentdb Ai Plug-In
Combining Supabase to Quickly Build Backend Service Based on TencentDB for PostgreSQL
Use Cases
postgres_fdw Extension for Cross-database Access
Automatically Creating Partition in PostgreSQL
Searching in High Numbers of Tags Based on pg_roaringbitmap
Querying People Nearby with One SQL Statement
Configuring TencentDB for PostgreSQL as GitLab's External Data Source
Supporting Tiered Storage Based on cos_fdw Extension
Implement Read/Write Separation via pgpool
Implementing Slow SQL Analysis Using the Auto_explain Plugin
Using pglogical for Logical Replication
Using Debezium to Collect PostgreSQL Data
Set Up a Remote Disaster Recovery Environment for PostgreSQL Locally on CVM
Read-Only Instance and Read-Only Group Practical Tutorial
How to Use SCF for Scheduled Database Operations
Fix Table Bloat
Performance White Paper
Test Methods
Test Results
API Documentation
History
Introduction
API Category
Making API Requests
Instance APIs
Read-only Replica APIs
Backup and Recovery APIs
Parameter Management APIs
Security Group APIs
Performance Optimization APIs
Account APIs
Specification APIs
Network APIs
Data Types
Error Codes
FAQs
Service Agreement
Service Level Agreement
Terms of Service
Glossary
Contact Us

Fix Table Bloat

PDF
포커스 모드
폰트 크기
마지막 업데이트 시간: 2026-03-11 15:07:27
TencentDB for PostgreSQL supports online tablespace cleanup using the pg_repack plugin, effectively resolving table bloat caused by operations like heavy full-table updates. Unlike CLUSTER and VACUUM, pg_repack runs online without requiring exclusive locks on processed tables during the process. Meanwhile, pg_repack starts up with high efficiency, performing comparably to direct use of CLUSTER. This document details how to handle table bloat with pg_repack. For more usage scenarios, refer to the official documentation.
Note:
Note: pg_repack requires additional storage space. For a full table repack, the remaining storage space must be at least twice the table size. Please upgrade your TencentDB for PostgreSQL instance configuration in advance.
pg_repack cannot operate temporary tables or GiST indexes.
pg_repack holds an ACCESS SHARE lock during operation, preventing DDL execution on tables being repacked.
Rebuilding tables and indexes occupies considerable disk I/O. Please execute during off-peak hours.
The target table must have a PRIMARY KEY or at least a UNIQUE index on NOT NULL columns.

Prerequisites

There is one TencentDB for PostgreSQL instance. To create one, see Create a PostgreSQL instance.
The instance has installed the pg_repack plug-in. For installation, refer to How to create a plug-in in a TencentDB for PostgreSQL instance.
There is one Cloud Virtual Machine (CVM), which is in the same VPC as the TencentDB for PostgreSQL instance. For Linux CVM configuration, see Quick Configuration for Linux CVM.
The CVM instance has installed the psql client. For detailed installation instructions, refer to PostgreSQL official documentation.

Installing Client

Before using, install the client on the CVM. Click Installation package download link, upload the installation package, and install.
unzip pg_repack-1.5.2.zip
cd pg_repack-1.5.2
make && make install

Clearing a Single Table

-- Check but not execute
pg_repack -k --dry-run --no-order -h 10.*.*.* -p 5432 -U user -d database -t schema1.table1
-- Check and execute
pg_repack -k --no-order -h 10.*.*.* -p 5432 -U user -d database -t schema1.table1

Cleaning a Single Schema

-- Check but not execute
pg_repack -k --dry-run --no-order -h 10.*.*.* -p 5432 -U user -d database -c schema
-- Check and execute
pg_repack -k --no-order -h 10.*.*.* -p 5432 -U user -d database -c schema

Clearing a Single Database

-- Check but not execute
pg_repack -k --dry-run --no-order -h 10.*.*.* -p 5432 -U user -d database
-- Check and execute
pg_repack -k --no-order -h 10.*.*.* -p 5432 -U user -d database

Clearing the Entire Instance (Only Databases with Pg_repack Plug-In Installed)

-- Check but not execute
pg_repack -k --dry-run --no-order -h 10.*.*.* -p 5432 -U user -a
-- Check and execute
pg_repack -k --no-order -h 10.*.*.* -p 5432 -U user -a

Checking the Cleanup Effect

-- View the top library size, sql as follows:
select datname,pg_size_pretty(pg_database_size(datname)) from pg_database order by pg_database_size(datname) desc;
-- View the top table size in the database, sql as follows:
SELECT relname AS table_name, pg_size_pretty(pg_total_relation_size(relid)) AS total_size FROM pg_catalog.pg_statio_user_tables ORDER BY pg_total_relation_size(relid) DESC;
-- View the size of a specific table, sql as follows:
select pg_size_pretty(pg_total_relation_size('pgtest'));

도움말 및 지원

문제 해결에 도움이 되었나요?

피드백