pg_squeeze
pg_squeeze : A tool to remove unused space from a relation.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 5040 | pg_squeeze | pg_squeeze | 1.9.6 |
ADMIN | PostgreSQL | C |
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
| --sLd-- | No | Yes | Yes | Yes | no | no |
| Relationships | |
|---|---|
| Schemas | squeeze |
| See Also | pg_repack pgstattuple pg_dirtyread pg_rewrite pg_column_tetris |
Packages
| Linux / PG | PG19 | PG18 | PG17 | PG16 | PG15 |
|---|---|---|---|---|---|
| el8.x86_64 | N/A | PGDG 1.9.6 | PGDG 1.9.6 | PGDG 1.9.6 | PGDG 1.9.6 |
| el8.aarch64 | N/A | PGDG 1.9.6 | PGDG 1.9.6 | PGDG 1.9.6 | PGDG 1.9.6 |
| el9.x86_64 | PGDG 1.9.6 | PGDG 1.9.6 | PGDG 1.9.6 | PGDG 1.9.6 | PGDG 1.9.6 |
| el9.aarch64 | PGDG 1.9.6 | PGDG 1.9.6 | PGDG 1.9.6 | PGDG 1.9.6 | PGDG 1.9.6 |
| el10.x86_64 | PGDG 1.9.6 | PGDG 1.9.6 | PGDG 1.9.6 | PGDG 1.9.6 | PGDG 1.9.6 |
| el10.aarch64 | PGDG 1.9.6 | PGDG 1.9.6 | PGDG 1.9.6 | PGDG 1.9.6 | PGDG 1.9.6 |
| d12.x86_64 | PGDG 1.9.4 | PGDG 1.9.4 | PGDG 1.9.4 | PGDG 1.9.4 | PGDG 1.9.4 |
| d12.aarch64 | PGDG 1.9.4 | PGDG 1.9.4 | PGDG 1.9.4 | PGDG 1.9.4 | PGDG 1.9.4 |
| d13.x86_64 | PGDG 1.9.4 | PGDG 1.9.4 | PGDG 1.9.4 | PGDG 1.9.4 | PGDG 1.9.4 |
| d13.aarch64 | PGDG 1.9.4 | PGDG 1.9.4 | PGDG 1.9.4 | PGDG 1.9.4 | PGDG 1.9.4 |
| u22.x86_64 | PGDG 1.9.4 | PGDG 1.9.4 | PGDG 1.9.4 | PGDG 1.9.4 | PGDG 1.9.4 |
| u22.aarch64 | PGDG 1.9.4 | PGDG 1.9.4 | PGDG 1.9.4 | PGDG 1.9.4 | PGDG 1.9.4 |
| u24.x86_64 | PGDG 1.9.4 | PGDG 1.9.4 | PGDG 1.9.4 | PGDG 1.9.4 | PGDG 1.9.4 |
| u24.aarch64 | PGDG 1.9.4 | PGDG 1.9.4 | PGDG 1.9.4 | PGDG 1.9.4 | PGDG 1.9.4 |
| u26.x86_64 | PGDG 1.9.4 | PGDG 1.9.4 | PGDG 1.9.4 | PGDG 1.9.4 | PGDG 1.9.4 |
| u26.aarch64 | PGDG 1.9.4 | PGDG 1.9.4 | PGDG 1.9.4 | PGDG 1.9.4 | PGDG 1.9.4 |
Source
github.com/cybertec-postgresql/pg_squeeze
Install
Make sure PGDG repo available:
Install this extension with pig:
Config this extension to shared_preload_libraries:
Create this extension with:
Usage
Sources:
pg_squeeze removes bloat from a table and its indexes while allowing concurrent reads and writes. It copies live tuples to new storage and applies concurrent changes through logical decoding, avoiding the long exclusive lock of VACUUM FULL. Use it only after sizing replication slots, disk space, and the table’s replica identity.
Configure and Install
Add pg_squeeze to any existing library lists. On PostgreSQL releases with output_plugin_libraries, that list must permit pg_squeeze so logical decoding can start. Restart PostgreSQL, then create the extension:
The table must have an identity index. A primary key works with the default replica identity; otherwise select a suitable unique index with ALTER TABLE ... REPLICA IDENTITY USING INDEX.
Run an Ad-Hoc Squeeze
The function starts background work and is not transactional in the ordinary SQL-function sense. Monitor the operation rather than assuming a surrounding ROLLBACK cancels it.
Schedule Tables and Monitor Work
The schedule tuple contains minutes, hours, days of month, months, and days of week. Registration also supports thresholds and placement options such as free_space_extra, min_size, vacuum_max_age, max_retry, clustering_index, relation/index tablespaces, and skip_analyze.
Start or stop scheduled processing as a superuser:
For automatic startup, configure a worker role with superuser privileges:
Version 1.9.6 and Operational Caveats
- Version 1.9.6 includes the 1.9.5 fixes for exclusion constraints and PostgreSQL 19 compatibility. Its configuration also accounts for
output_plugin_libraries; check that setting when upgrading PostgreSQL. - Version 1.9.4 fixes unsafe quoting in dynamically constructed
ANALYZE, log, and error statements, including a superuser SQL-injection path. Upgrade earlier 1.9 builds promptly. - A full-table squeeze needs free disk space of roughly twice the combined size of the target table and its indexes.
- Disruptive DDL,
VACUUM FULL,CLUSTER, orTRUNCATEcan make an in-progress squeeze abort. Coordinate schema changes and usemax_retrydeliberately. - Like other online rewrite tools,
pg_squeezechanges row visibility and has documented MVCC caveats for concurrent sessions that retain old snapshots. - Configure
pg_squeezeinshared_preload_librarieson the new cluster beforepg_upgradeor dump/restore of a database containing the extension. - On PostgreSQL versions before 19, keep
wal_level = logical. The upstream PostgreSQL 19 configuration no longer requires that setting.