New PostgreSQL Extension pg_repack Optimizes Tables Without Downtime

08 Jul 2024

PostgreSQL users frequently encounter the issue of database bloat, which can severely degrade performance. Traditional methods such as VACUUM FULL and CLUSTER can be quite disruptive, but pg_repack offers an online solution that minimizes downtime. Here, we delve into the installation and configuration of pg_repack on a PostgreSQL 14 setup running on Red Hat Enterprise Linux 9 (RHEL 9).

What is pg_repack?

pg_repack is a PostgreSQL extension designed to eliminate bloat from tables and indexes. Unlike CLUSTER and VACUUM FULL, pg_repack works online without requiring an exclusive lock on the tables being processed, making it a more efficient and less intrusive option.

Installation

  1. Download the RPM Package
    First, download the pg_repack RPM package for PostgreSQL 14 on RHEL 9:
    wget https://download.postgresql.org/pub/repos/yum/14/redhat/rhel-9-x86_64/pg_repack_14-1.5.0-1PGDG.rhel9.x86_64.rpm
  2. Install the RPM Package
    Next, install the downloaded RPM package:
    rpm -iv pg_repack_14-1.5.0-1PGDG.rhel9.x86_64.rpm
  3. Verify Installation
    Verify the installation by listing the files included in the package:
    rpm -ql pg_repack_14-1.5.0-1PGDG.rhel9.x86_64.rpm | grep bin
    Alternatively, use the find command to locate the pg_repack binary:
    find / -name pg_repack
  4. Update PATH Environment Variable
    Add the PostgreSQL bin directory to your PATH:
    export PATH=$PATH:/usr/pgsql-14/bin
    Make this change permanent by adding it to your ~/.bashrc file:
    echo 'export PATH=$PATH:/usr/pgsql-14/bin' >> ~/.bashrc
    source ~/.bashrc

Configuration

  1. Create the Extension
    Connect to your PostgreSQL database and create the pg_repack extension:
    psql -c "CREATE EXTENSION pg_repack" -d employee
  2. Verify pg_repack Availability
    To ensure pg_repack is available, list the PostgreSQL binaries:
    pg_re
    You should see pg_repack listed among the other PostgreSQL binaries:
    pg_receivewal   pg_recvlogical  pg_repack       pg_resetwal     pg_restore      pg_rewind
    If you don't see it, you may have forgotten to source your bashrc (source ~/.bashrc)

Usage

Basic Usage
To repack a specific database (e.g., employee), use the following command:

pg_repack -d employee

Advanced Options
pg_repack offers several options to customize its behavior. Here are some useful ones:

  • Repack all databases:
    pg_repack -a
  • Repack a specific table:
    pg_repack -t table_name -d employee
  • Repack tables in a specific schema:
    pg_repack -s schema_name -d employee
  • Move repacked tables to a new tablespace:
    pg_repack --tablespace=new_tablespace -d employee
  • Order by specific columns:
    pg_repack --order-by=column_name -d employee

For a complete list of options, refer to the pg_repack help:

pg_repack --help

Top charts for Desktop

uTorrent

uTorrent

Latest update uTorrent download for free for Windows PC or Android mobile

5
1032 reviews
7401550
downloads
Zona

Zona

Latest update Zona download for free for Windows PC or Android mobile

4
614 reviews
1701854
downloads
WinRAR

WinRAR

Streamline file management with fast compression, secure your documents, and save space.

5
735 reviews
730747
downloads
Minecraft

Minecraft

Shape environments, explore vast worlds, and survive against monsters with endless creativity.

5
750 reviews
491639
downloads

News and reviews for Desktop

0patch Bridges Security Gap for Windows 10 Post-Support

0patch, offering micropatches, addresses security needs for Windows 10 after Microsoft's support ended. Costs may impact long-term use.

Read more

Big Hops Introduces Unique Gameplay by Luckshot Games

Big Hops by Luckshot Games adds unique mechanics to platformer genre with engaging movement and collectibles.

Read more

Project Reforged: Sonic Revamp with Alpha Demo Released

Project Reforged, by Besky, offers a fan remake of Sonic and the Black Knight with new levels and mechanics in its alpha demo.

Read more

Cor3 Countdown Hints at New Space FPS by Tarkov Lead

Cor3, linked to Escape From Tarkov's Buyanov, teases potential space FPS with a countdown ending on 2026-02-01.

Read more

PDFSIDER Malware Bypasses EDR via PDF24 Exploits

PDFSIDER backdoor exploits PDF24 vulnerabilities, evading EDR. Analyzed by Resecurity, it impacts endpoint defenses.

Read more

Inkle Launches New PC Game: World War Investigation Sim

Inkle releases a PC game this week: a World War investigation sim. Other PC games include strategy, RPGs, and platformers. Expect diverse gameplay.

Read more

Microsoft Issues Emergency Windows 11 Shutdown Fix

Microsoft releases an out-of-band update for Windows 11 to resolve shutdown and remote login issues caused by a security update.

Read more

Torchlight Infinite's Vorax Update Hits Player Peak on Steam

Torchlight Infinite's Vorax season update sets a new player record on Steam, introducing innovative features and timing its release for maximum impact.

Read more

Explore Stunning Videogame Art from Dishonored to Avowed

PC Gamer writers discuss iconic art in games like Dishonored, Destiny, Elden Ring, and Avowed. Delve into rich visuals and memorable designs.

Read more

Heartopia Faces Mixed Reviews on Steam Launch

Heartopia launched on Steam in January 2026, drawing mixed reviews. Key issues include PC controls and monetization concerns.

Read more