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
6382073
downloads
Zona

Zona

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

4
614 reviews
1268515
downloads
WinRAR

WinRAR

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

5
735 reviews
495241
downloads
Minecraft

Minecraft

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

5
750 reviews
453492
downloads

News and reviews for Desktop

Pillars of Eternity Introduces New Turn-Based Mode

Obsidian unveils Pillars of Eternity's turn-based mode, launching beta on 2023-11-05. Aims at improved gameplay flexibility.

Read more

Arc Raiders Adds New Social Dynamics in Solo Queue

Arc Raiders players find success through communication in solo queue, transforming gameplay with increased cooperation and engagement.

Read more

Critical GDI Flaws Patched in Microsoft Windows

Microsoft uncovers and patches critical GDI flaws allowing remote code execution in Windows. Impacts extend to Microsoft Office for Mac and Android.

Read more

Zeekerss Launches 10-Year Text Adventure 'Welcome to the Dark Place'

Zeekerss releases 'Welcome to the Dark Place', blending text adventure techniques with bespoke audio for a unique gaming experience.

Read more

Design Director Plans Saints Row Prequel Pitch

Original Saints Row's Chris Stockman explores new prequel pitch focused on early series tone, rejecting VR approach.

Read more

Breach Wizards Levels Up with Community Expansion

Tactical Breach Wizards embraces a challenging new level pack. Discounted 40% until 2023-11-09. Includes 'less-than-lethal' pyromancer, Bori.

Read more

Stalker 2 Leaving Game Pass on 2025-11-15

Stalker 2 and Frostpunk exit Game Pass on 2025-11-15. Subscribers have limited time to play these titles before they're removed.

Read more

New PC Bang Spotted in Pyongyang With Asus ROG Setup

North Korea's new PC bang has emerged in Pyongyang, featuring Asus ROG gear and AAA games, suggesting limited, elite access.

Read more

Launches: Europa Universalis 5 and Football Manager 26 Expand PC Games Lineup

New PC games launched this week include Europa Universalis 5 and Football Manager 26, adding variety to the market with strategy and sports simulators.

Read more

Five New Steam Games Released: Notable Titles for November 2025

Explore five new Steam games launched in late October 2025, ranging from narrative adventures to twin-stick shooters and trading simulations.

Read more