Rebuild PostgreSQL Database using pg_repack

VACUUM FULL tablename;
  1. Connect to your target database and install pg_repack extension using CREATE EXTENSION pg_repack;
  2. Install pg_repack on server or localhost using sudo apt-get install postgresql-12-repack
  3. We can execute the below command from the terminal.
pg_repack -d <DATABASE_NAME> -U <USERNAME> -h <DATABASE_HOST_URL> -p <DATABASE_PORT> -k
  • -k :- flag is to remove the superuser check
  • -j <COUNT> :- Number of parallel jobs
  • — table <table-name> :- Specify table name (Note: for entire database remove do not add this flag in command)
  • — table <table1> — table <table2> :- Use these flags if you want to repack multiple tables.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store