1

I've installed PGXN Client but everytime I run

$ pgxn install pg_repack

make[1]: Entering directory '/tmp/tmpniazqt/pg_repack-1.4.4/bin' gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -g -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -fno-omit-frame-pointer -I/usr/include/postgresql -DREPACK_VERSION=1.4.4 -I. -I./ -I/usr/include/postgresql/11/server -I/usr/include/postgresql/internal -Wdate-time -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -I/usr/include/libxml2 -I/usr/include/mit-krb5 -c -o pg_repack.o pg_repack.c gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -g -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -fno-omit-frame-pointer -I/usr/include/postgresql -DREPACK_VERSION=1.4.4 -I. -I./ -I/usr/include/postgresql/11/server -I/usr/include/postgresql/internal -Wdate-time -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -I/usr/include/libxml2 -I/usr/include/mit-krb5 -c -o pgut/pgut.o pgut/pgut.c gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -g -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -fno-omit-frame-pointer -I/usr/include/postgresql -DREPACK_VERSION=1.4.4 -I. -I./ -I/usr/include/postgresql/11/server -I/usr/include/postgresql/internal -Wdate-time -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -I/usr/include/libxml2 -I/usr/include/mit-krb5 -c -o pgut/pgut-fe.o pgut/pgut-fe.c gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -g -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -fno-omit-frame-pointer pg_repack.o pgut/pgut.o pgut/pgut-fe.o -L/usr/lib/x86_64-linux-gnu -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -L/usr/lib/llvm-6.0/lib -L/usr/lib/x86_64-linux-gnu/mit-krb5 -Wl,--as-needed -L/usr/lib/x86_64-linux-gnu -lpq -L/usr/lib/postgresql/11/lib -lpgcommon -lpgport -lpthread -lssl -lcrypto -lz -lrt -lcrypt -ldl -lm -o pg_repack /usr/bin/ld: cannot find -lz collect2: error: ld returned 1 exit status /usr/lib/postgresql/11/lib/pgxs/src/makefiles/pgxs.mk:430: recipe for target 'pg_repack' failed make[1]: * [pg_repack] Error 1 make[1]: Leaving directory '/tmp/tmpniazqt/pg_repack-1.4.4/bin' Makefile:35: recipe for target 'all' failed make: * [all] Error 2 ERROR: command returned 2: make PG_CONFIG=/usr/bin/pg_config all

I also tried installing it by downloading the pg_repack.zip but still get the same error.

I guess there's something in the makefile that I need to edit. But I can't seem to point out what it is.

Thank you in advance!

mengmeng
  • 1,266
  • 2
  • 22
  • 46
  • The actual error appears to be [`/usr/bin/ld: cannot find -lz`](https://stackoverflow.com/questions/3373995/usr-bin-ld-cannot-find-lz), which means that it can't find the `zlib` library. Are you sure you need to build it yourself, though? The [docs](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Appendix.PostgreSQL.CommonDBATasks.html#Appendix.PostgreSQL.CommonDBATasks.pg_repack) suggest that `pg_repack` is available by default in RDS instances (and I didn't think they let you install custom extensions anyway...). – Nick Barnes Jul 23 '19 at 10:41
  • hi! for some reason this is fixed using this command `sudo apt-get install zlib1g-dev` – mengmeng Jul 24 '19 at 02:11
  • not connected to the extension at all but... that fixed it haha – mengmeng Jul 24 '19 at 02:11

1 Answers1

1

Below are the steps, we can follow to setup pg_repack

  1. Install pg_repack extension: Connect to your RDS/Database and execute CREATE EXTENSION pg_repack.
  2. Install pg_repack on the server or localhost using sudo apt-get install postgresql-12-repack
  3. Run pg_repack with dry-run using the command pg_repack --dry-run -d <DATABASE NAME> --table <TABLE NAME> This command will print what would have been repacked
  4. pg_repack -d <DATABASE_NAME> -U <USERNAME> -h <DATABASE_HOST_URL> -p <DATABASE_PORT> -k

For more details check this blog

Update:

If you encounter difficulties installing pg_repack (v1.4.8) with the latest PostgreSQL version (v15), refer to this solution.