pg_squeeze

A tool to remove unused space from a relation.

Overview

PackageVersionCategoryLicenseLanguage
pg_squeeze1.9.1ADMINBSD 2-ClauseC
IDExtensionBinLibLoadCreateTrustRelocSchema
5040pg_squeezeNoYesYesYesNoNosqueeze
Relatedpg_repack pgfincore pg_prewarm pgstattuple pg_cooldown pgcozy amcheck pageinspect

Version

TypeRepoVersionPG VerPackageDeps
EXTPGDG1.9.11817161514pg_squeeze-
RPMPGDG1.9.11817161514pg_squeeze_$v-
DEBPGDG1.9.11817161514postgresql-$v-squeeze-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
PGDG 1.9.1
PGDG 1.9.1
PGDG 1.9.1
PGDG 1.9.1
PGDG 1.9.1
d12.aarch64
PGDG 1.9.1
PGDG 1.9.1
PGDG 1.9.1
PGDG 1.9.1
PGDG 1.9.1
d13.x86_64
PGDG 1.9.1
PGDG 1.9.1
PGDG 1.9.1
PGDG 1.9.1
PGDG 1.9.1
d13.aarch64
PGDG 1.9.1
PGDG 1.9.1
PGDG 1.9.1
PGDG 1.9.1
PGDG 1.9.1
u22.x86_64
u22.aarch64
u24.x86_64
u24.aarch64

Install

You can install pg_squeeze directly. First, make sure the PGDG repository is added and enabled:

pig repo add pgdg -u          # Add PGDG repo and update cache

Install the extension using pig or apt/yum/dnf:

pig install pg_squeeze;          # Install for current active PG version
pig ext install -y pg_squeeze -v 18  # PG 18
pig ext install -y pg_squeeze -v 17  # PG 17
pig ext install -y pg_squeeze -v 16  # PG 16
pig ext install -y pg_squeeze -v 15  # PG 15
pig ext install -y pg_squeeze -v 14  # PG 14
dnf install -y pg_squeeze_18       # PG 18
dnf install -y pg_squeeze_17       # PG 17
dnf install -y pg_squeeze_16       # PG 16
dnf install -y pg_squeeze_15       # PG 15
dnf install -y pg_squeeze_14       # PG 14
apt install -y postgresql-18-squeeze   # PG 18
apt install -y postgresql-17-squeeze   # PG 17
apt install -y postgresql-16-squeeze   # PG 16
apt install -y postgresql-15-squeeze   # PG 15
apt install -y postgresql-14-squeeze   # PG 14

Preload:

shared_preload_libraries = 'pg_squeeze';

Create Extension:

CREATE EXTENSION pg_squeeze;

Usage

pg_squeeze: A tool to remove unused space from a relation.

pg_squeeze requires wal_level = logical and must be added to shared_preload_libraries. It removes bloat from tables while allowing concurrent reads and writes, using logical decoding instead of triggers.

Register a Table for Scheduled Processing

Insert into squeeze.tables to enable periodic bloat checks:

INSERT INTO squeeze.tables (tabschema, tabname, schedule)
VALUES ('public', 'foo', ('{30}', '{22}', NULL, NULL, '{3, 5}'));

The schedule field uses a crontab-like format: (minutes, hours, days_of_month, months, days_of_week). The above checks table foo every Wednesday and Friday at 22:30.

Optional columns: free_space_extra (min % extra free space to trigger, default 50), min_size (min MB, default 8), vacuum_max_age (max time since last VACUUM, default 1h), max_retry (retry count, default 0), clustering_index (sort tuples by this index), rel_tablespace, ind_tablespaces, skip_analyze.

Ad-hoc Squeeze

SELECT squeeze.squeeze_table('public', 'pgbench_accounts');
SELECT squeeze.squeeze_table('public', 'mytable', 'my_cluster_idx', 'target_tablespace');

Start / Stop Workers

SELECT squeeze.start_worker();   -- start scheduler + squeeze workers
SELECT squeeze.stop_worker();    -- stop all workers for current database

Auto-start on cluster boot via postgresql.conf:

squeeze.worker_autostart = 'my_database your_database'
squeeze.worker_role = postgres

Monitoring

  • squeeze.log – one entry per successfully squeezed table (with started, finished, ins_initial, ins, upd, del)
  • squeeze.errors – errors during squeezing
  • squeeze.get_active_workers() – shows currently active squeeze workers and their progress

Configuration

  • squeeze.max_xlock_time – max exclusive lock time in ms (default unlimited)
  • squeeze.workers_per_database – number of concurrent squeeze workers (default 1)

Last Modified 2026-03-12: add pg extension catalog (95749bf)