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.