postgresqlpostgresql-15pg-repack

How to install and run pg_reack on postgres with pg_reack version v1.4.8?


I recently upgraded PostgreSQL from v12.14 to v15.2. During the upgrade, I also had to update the pg_repack extension from v1.4.5 to v1.4.8. However, when I attempted to run pg_repack, I encountered the error: "pg_repack failed with error: program 'pg_repack 1.4.5' does not match database library 'pg_repack 1.4.8'".

I followed the steps outlined in this document, but it's not as straightforward as it's described here. https://reorg.github.io/pg_repack/#installation


Solution

  • At last, I discovered a solution to resolve this problem. Note: The steps below were executed on an Ubuntu system (v22.04) without any previous installation.

    sudo apt-get update 
    sudo apt-get install postgresql-server-dev-all
    
    sudo apt-get install postgresql-common 
    sudo apt-get install pgxnclient
    sudo apt install gcc
    sudo su
    export PATH=/usr/lib/postgresql/14/bin:$PATH
    sudo apt-get install liblz4-dev
    export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
    sudo apt-get install libreadline-dev
    export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
    sudo apt-get install zlib1g-dev
    export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
    pgxn install pg_repack
    
    # Now you are ready to run pg_repack using following command
    pg_repack -h <HOST-NAME> -p <PORT NUMBER> -d <DATABASE NAME> -U <USERNAME> -k
    

    Note:

    Edit the .bashrc file to include the following environment variable.

    export PATH=/usr/lib/postgresql/14/bin:$PATH
    export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
    export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
    export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
    

    Refer to this blog to learn more about pg_repack and its available parameters.

    Update:-

    You can also use my Docker image if you'd prefer not to set up pg_repack locally.

    Docker Image URL :- https://hub.docker.com/r/sreakshaybhadange/pg_repack

    Command to use

    docker run -e PGPASSWORD="<PASSWORD>" sreakshaybhadange/pg_repack:v1.4.9 pg_repack -h <DATABASE-HOST-URL> -d <DATABASE-NAME> -U <USER-NAME> -p <PORT> -j <NUMBER-OF-WORKERS> -k