Skip to main contentClaim $5 in free credit — one-time, per account. Claim $5 free
Krova CloudKrova Cloud
Database Hosting

PostgreSQL 19 REPACK: Budget the Rewrite Before Reclaiming Space

PostgreSQL 19 adds built-in REPACK. Separate reclaimable space from rewrite capacity, check concurrent-mode limits, and plan for the final lock before maintenance.

RB
Rohit Bhadani5 min read
Share
Database Hosting cover with PostgreSQL 19 REPACK headline, disk-headroom subtitle, and two frosted-glass database copies linked by a turquoise rewrite arrow.

Imagine you’ve removed a year of archived orders, but the PostgreSQL data volume still looks full. You notice PostgreSQL 19’s new REPACK command and wonder whether it can give that space back. Before you reach for the command, separate two questions: how much space might eventually be reclaimed, and how much room the rewrite needs while it runs.

Treat PostgreSQL 19 REPACK as a planned rewrite. Check the installed version, table eligibility, temporary disk headroom and application tolerance for the final lock before scheduling a rehearsal. A nearly full disk is a reason to pause that decision. This guide helps you prepare the maintenance plan; it does not estimate your reclaimable bytes.

The PostgreSQL project released version 19 on 19 November 2026. REPACK is a new built-in SQL command in that major release. This article covers that command, rather than instructions for the separate pg_repack extension. Installing a newer client does not upgrade the server.

First decide whether you need reusable space or a smaller file

Ordinary VACUUM generally makes old-row space reusable inside a table. It can return completely free trailing pages under particular conditions, but a large file after cleanup is not by itself evidence that VACUUM failed. PostgreSQL’s routine maintenance guide distinguishes this from a rewrite, which creates a compact replacement and needs extra space until it completes.

Back in the hypothetical orders database, ask what happens next. If incoming orders will reuse the space, shrinking the file may buy little. If the archive removal was permanent and the operating system needs the capacity, a rewrite deserves investigation. Those are different maintenance goals even when the disk chart looks identical.

If old transactions are preventing cleanup, follow Krova’s VACUUM transaction diagnostic first. A new rewrite command is not a reason to skip finding the cause of recurring growth.

Build two ledgers before reserving a window

Start with a read-only size observation. Replace public.orders with the intended table and use an account allowed to inspect it. Check the connected server version in the same session; these examples target PostgreSQL 19 and were not executed for this article.

SHOW server_version;

SELECT pg_size_pretty(pg_table_size('public.orders'::regclass)) AS table_bytes,
       pg_size_pretty(pg_indexes_size('public.orders'::regclass)) AS index_bytes,
       pg_size_pretty(pg_total_relation_size('public.orders'::regclass)) AS total_bytes;

The size-function reference defines pg_table_size as table storage including TOAST and auxiliary maps but excluding indexes. pg_indexes_size covers the table’s indexes; pg_total_relation_size combines them. These are current storage sizes. They do not tell you how much is dead space or predict the replacement’s final size.

Keep a capacity ledger for running the work and a separate reclaim estimate for its possible payoff. Don’t subtract hoped-for savings from the capacity ledger before the old files have gone.

The REPACK resource notes require free space at least equal to table plus index sizes. Index ordering can require an additional table-sized sort file. Concurrent changes also consume separate disk storage and memory beyond maintenance_work_mem. Concurrent mode uses a weaker lock for most work, then needs ACCESS EXCLUSIVE for the final swap.

For invented planning arithmetic, suppose the observed table is 24 GiB and its indexes total 8 GiB. The copy allowance starts at 32 GiB. A possible 24 GiB sort would bring those two components to 56 GiB, before concurrent-change storage, ordinary workload growth and your operating margin. These are assumptions, not a measured workload or a promise that 56 GiB is sufficient.

Map each allowance to the filesystem that will actually hold it, including relevant tablespaces and temporary-file locations. A free-space total from another volume cannot fund this rewrite. If you cannot explain where every temporary component fits, enlarge the rehearsal’s capacity or defer it.

Check eligibility and the application’s snapshot behavior

The command reference requires MAINTAIN privilege and rejects invalid indexes. Concurrent mode needs a primary key or index-based replica identity, available REPACK replication-slot capacity, and execution outside a transaction block. It excludes unlogged tables, partitioned tables, non-heap tables, materialized views, system/TOAST tables and tables marked user_catalog_table. Read the full version-specific restrictions before choosing the target.

There is also an application-level question. PostgreSQL’s MVCC caveat says concurrent REPACK is not MVCC-safe: after the rewrite commits, an older-snapshot transaction that had not accessed the table before the command started can see it as empty. That is a visibility caveat, not a claim that the rows were deleted.

Include long-running reports and transactions spanning several tables in the rehearsal. Decide with their owners whether the maintenance window and transaction lifecycle are acceptable. “Concurrent” alone cannot answer that question or promise uninterrupted requests.

Watch the phase, then verify the outcome

For an already approved rehearsal, a separate monitoring session can inspect the documented REPACK progress view. Use suitable monitoring permissions and interpret missing visibility cautiously.

SELECT pid, datname, relid::regclass AS relation,
       command, phase, heap_blks_total, heap_blks_scanned
FROM pg_stat_progress_repack
WHERE datname = current_database();

The progress documentation notes that initialization can wait for transactions, including ones that started during that wait. The catch-up phase includes waiting for the final exclusive lock. A scan counter reaching its total therefore does not mean the operation has finished. Record phase changes alongside disk usage, application latency and errors; avoid turning one counter into an overall completion percentage.

Before production, write down who can stop the rehearsal, what free-space floor and application-error threshold trigger that decision, and how recovery will be verified. Choose thresholds from the workload’s requirements. After successful completion, compare fresh relation sizes and filesystem free space, then run representative application checks. File shrinkage alone is an incomplete result.

If you self-host on a Krova Cube, you own the PostgreSQL version and maintenance plan. Krova’s PostgreSQL setup guide explains installation and restricted connectivity, but its distribution-package examples install earlier majors; they are not a PostgreSQL 19 upgrade procedure. Use a separate compatible test installation with disposable data to evaluate the new command.

Rehearse the maintenance decision on a Cube

Use a separate self-managed Linux environment to check PostgreSQL 19 eligibility, temporary storage and application behavior before planning a production rewrite.

Creation context: This AI-assisted article uses linked primary documentation and a hypothetical orders database. The arithmetic and SQL are illustrative; no database operation, benchmark or customer test was performed for this article. The cover is a generated illustration.

For AI agents:llms.txtsitemap

Related posts