Compiling pg_repack extension on binary format of PostgreSQL installation

This blog is about compiling pg_repack extension on binary format of PostgreSQL installation. Most of you know, pg_repack extension is one of well known PostgreSQL extensions, its especially used for reclaiming space[bloats] ONLINE without holding an EXCLUSIVE LOCK on Tables/Indexes.

To enable pg_repack extension in PostgreSQL database, it should be compiled from sources. Its quite easy and simple to compile from source on any installed variants(source,rpm,binary) of PostgreSQL, however its slightly different if it is with binary format of PostgreSQL [One Click Installer] as they are pre-built binary bundle with dependency libraries. Let’s compile and see.

On CentOS 7 Virtual Machine, I have installed binary format of PostgreSQL 9.4(download link) and its home directory “/opt/PostgreSQL/9.4/”. Next we need to download pg_repack source from their official site.

Before compiling, pg_config of PostgreSQL 9.4 should be set in the PATH.

Now we are good to execute source installation commands “make” & “make install”. Let’s execute “make”

Oops 1…!!, seems there’s an error related to -ledit(libedit) library missing in PostgreSQL lib directory. Lets run same command “ld -ledit” in verbose mode (-verbose) for more information, tried and failed by “make” command.

Okay, now its clear that its looking for libedit.so library in PostgreSQL lib directory [/opt/PostgreSQL/9.4/lib]. Lets check for library in that directory.

Ah,we have “libedit.so.0” but not “libedit.so” required by “make” command. Creating a symbolic link should be a quick fix.

Re-run “make” command.

Oops 2…!!! interesting, it has passed -ledit error and now its reporting on libldap library [ libldap_r-2.4.so.2 ]. Am not sure why its looking in /lib64 directory when my pg_config points to /opt/PostgreSQL/9.4/lib. Lets check what we have in both the location.

Seems there are two copies of “libldap_r-2.4.so.2”, one in the form of symbolic link and another as a hard copy. Am guessing its due to multiple library copies, lets remove symbolic link and retain a hard copy of library and try again.

wow… finally,  it has compiled. Run “make install” for the pg_repack binaries and libraries.

After compilation there will be pg_repack utility in $PGHOME/bin and pg_repack.so library in $PGHOME/lib/postgresql/ directory.

Now we are set to create pg_repack extension inside the database.

Likewise, I have attempted to compile with EnterpriseDB product PostgresPlus Advanced Server 9.4[PPAS] a pre-built binary package. Faced similar library issues, hence I have used linker option “LDFLAGS” pointing to library directory and compiled.

Cool,this too compiled smoothly. Now create extension in PPAS 9.4

Thank you.

–Raghav

2 Replies to “Compiling pg_repack extension on binary format of PostgreSQL installation”

  1. Hello, may be you can help me with my installation issue of repack?
    We are migrating from postgres 9.1 to 9.3 & I've decided to install pg_repack
    So I've downloaded, unpacked re_pack v1.3.3
    Set the pg_config of PostgreSQL 9.3 in the PATH, so that typing pg_config gives me:
    pg_config is /usr/lib/postgresql/9.3/bin/pg_config
    But when I'm doing make, I receive:
    Entering directory `/root/pg_repack-1.3.3/lib'
    gcc -g -O2 -fstack-protector –param=ssp-buffer-size=4 -Wformat -Werror=format-security -I/usr/include/mit-krb5 -fPIC -pie -DLINUX_OOM_SCORE_ADJ=0 -fno-omit-frame-pointer -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g -fpic -shared -Wl,–version-script=exports.list -o pg_repack.so repack.o pgut/pgut-be.o pgut/pgut-spi.o -L/usr/lib/x86_64-linux-gnu -Wl,-z,relro -Wl,-z,now -Wl,–as-needed -L/usr/lib/mit-krb5 -L/usr/lib/x86_64-linux-gnu/mit-krb5 -L/usr/lib -Wl,–as-needed

    /usr/bin/ld:exports.list:2: syntax error in VERSION script
    collect2: error: ld returned 1 exit status
    How can I overcome this mistake?
    I'll be tankfull for your help.

  2. Hello, may be you can help me with my installation issue of repack?
    We are migrating from postgres 9.1 to 9.3 & I&#39ve decided to install pg_repack
    So I&#39ve downloaded, unpacked re_pack v1.3.3
    Set the pg_config of PostgreSQL 9.3 in the PATH, so that typing pg_config gives me:
    pg_config is /usr/lib/postgresql/9.3/bin/pg_config
    But when I&#39m doing make, I receive:
    Entering directory `/root/pg_repack-1.3.3/lib&#39
    gcc -g -O2 -fstack-protector –param=ssp-buffer-size=4 -Wformat -Werror=format-security -I/usr/include/mit-krb5 -fPIC -pie -DLINUX_OOM_SCORE_ADJ=0 -fno-omit-frame-pointer -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g -fpic -shared -Wl,–version-script=exports.list -o pg_repack.so repack.o pgut/pgut-be.o pgut/pgut-spi.o -L/usr/lib/x86_64-linux-gnu -Wl,-z,relro -Wl,-z,now -Wl,–as-needed -L/usr/lib/mit-krb5 -L/usr/lib/x86_64-linux-gnu/mit-krb5 -L/usr/lib -Wl,–as-needed

    /usr/bin/ld:exports.list:2: syntax error in VERSION script
    collect2: error: ld returned 1 exit status
    How can I overcome this mistake?
    I&#39ll be tankfull for your help.

Leave a Reply