Untuk mengaktifkan ekstensi pg_repack di database PostgreSQL, itu harus dikompilasi dari sumber. Ini cukup mudah dan sederhana untuk dikompilasi dari sumber pada setiap varian yang diinstal (sumber, rpm, biner) PostgreSQL, namun sedikit berbeda jika dengan format biner PostgreSQL [Penginstal Satu Klik] karena mereka adalah bundel biner pra-bangun dengan ketergantungan perpustakaan. Mari kita kompilasi dan lihat.
Pada Mesin Virtual CentOS 7, saya telah menginstal format biner PostgreSQL 9.4 (tautan unduhan) dan direktori home-nya “/opt/PostgreSQL/9.4/”. Selanjutnya kita perlu mengunduh sumber pg_repack dari situs resmi mereka.
[root@localhost ~]# git clone https://github.com/reorg/pg_repack.git
Sebelum kompilasi, pg_config dari PostgreSQL 9.4 harus diatur di PATH.
[root@localhost pg_repack]# export PATH=/opt/PostgreSQL/9.4/bin:$PATH
[root@localhost pg_repack]# type pg_config
pg_config is /opt/PostgreSQL/9.4/bin/pg_config
Sekarang kita baik untuk menjalankan perintah instalasi sumber "make" &"make install". Ayo jalankan "make"
[root@localhost ~]# cd pg_repack/
[root@localhost pg_repack]# make
make[1]: Entering directory `/root/pg_repack/bin'
....
....
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -O2 pg_repack.o pgut/pgut.o pgut/pgut-fe.o -L/opt/PostgreSQL/9.4/lib -lpq -L/opt/PostgreSQL/9.4/lib -L/opt/local/Current/lib -Wl,--as-needed -Wl,-rpath,'/opt/PostgreSQL/9.4/lib',--enable-new-dtags -lpgcommon -lpgport -lssl -lcrypto -lgssapi_krb5 -lz -ledit -lrt -lcrypt -ldl -lm -o pg_repack
/usr/bin/ld: cannot find -ledit
collect2: ld returned 1 exit status
make[1]: *** [pg_repack] Error 1
make[1]: Leaving directory `/root/pg_repack/bin'
make: *** [all] Error 2
Ups…!!, sepertinya ada kesalahan terkait dengan -ledit(libedit) library yang hilang di direktori lib PostgreSQL. Mari kita jalankan perintah yang sama "ld -ledit" dalam mode verbose (-verbose) untuk informasi lebih lanjut, mencoba dan gagal dengan perintah "make".
[root@localhost pg_repack]# ld -ledit -verbose
GNU ld version 2.20.51.0.2-5.42.el6 20100205
...
...
...
==================================================
attempt to open /usr/x86_64-redhat-linux/lib64/libedit.so failed
attempt to open /usr/x86_64-redhat-linux/lib64/libedit.a failed
attempt to open /usr/local/lib64/libedit.so failed
attempt to open /usr/local/lib64/libedit.a failed
attempt to open /lib64/libedit.so failed
attempt to open /lib64/libedit.a failed
attempt to open /usr/lib64/libedit.so failed
attempt to open /usr/lib64/libedit.a failed
attempt to open /usr/x86_64-redhat-linux/lib/libedit.so failed
attempt to open /usr/x86_64-redhat-linux/lib/libedit.a failed
attempt to open /usr/lib64/libedit.so failed
attempt to open /usr/lib64/libedit.a failed
attempt to open /usr/local/lib/libedit.so failed
attempt to open /usr/local/lib/libedit.a failed
attempt to open /lib/libedit.so failed
attempt to open /lib/libedit.a failed
attempt to open /usr/lib/libedit.so failed
attempt to open /usr/lib/libedit.a failed
ld: cannot find -ledit
Oke, sekarang jelas bahwa ia mencari perpustakaan libedit.so di direktori lib PostgreSQL [/opt/PostgreSQL/9.4/lib]. Mari kita periksa perpustakaan di direktori itu.
[root@localhost pg_repack]# cd /opt/PostgreSQL/9.4/lib
[root@localhost lib]# ls -l libedit*
-rwxr-xr-x. 1 root daemon 254702 Mar 22 23:32 libedit.so.0
Ah, kami memiliki "libedit.so.0" tetapi tidak "libedit.so" yang diperlukan oleh perintah "make". Membuat tautan simbolis seharusnya bisa dilakukan dengan cepat.
[root@localhost lib]# ln -s libedit.so.0 libedit.so
[root@localhost lib]# ls -l libedit*
lrwxrwxrwx. 1 root root 12 May 19 22:25 libedit.so -> libedit.so.0
-rwxr-xr-x. 1 root daemon 254702 Mar 22 23:32 libedit.so.0
Jalankan kembali perintah "make".
[root@localhost pg_repack]# make
make[1]: Entering directory `/root/pg_repack/bin'
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -O2 pg_repack.o pgut/pgut.o pgut/pgut-fe.o -L/opt/PostgreSQL/9.4/lib -lpq -L/opt/PostgreSQL/9.4/lib -L/opt/local/Current/lib -Wl,--as-needed -Wl,-rpath,'/opt/PostgreSQL/9.4/lib',--enable-new-dtags -lpgcommon -lpgport -lssl -lcrypto -lgssapi_krb5 -lz -ledit -lrt -lcrypt -ldl -lm -o pg_repack
/usr/bin/ld: warning: libssl.so.1.0.0, needed by /opt/PostgreSQL/9.4/lib/libpq.so, may conflict with libssl.so.10
/lib64/libldap_r-2.4.so.2: undefined reference to `ber_sockbuf_io_udp'
collect2: ld returned 1 exit status
make[1]: *** [pg_repack] Error 1
make[1]: Leaving directory `/root/pg_repack/bin'
make: *** [all] Error 2
Ups…!!! menarik, itu telah melewati kesalahan -ledit dan sekarang pelaporannya di perpustakaan libldap [ libldap_r-2.4.so.2 ]. Saya tidak yakin mengapa mencari di direktori /lib64 ketika pg_config saya menunjuk ke /opt/PostgreSQL/9.4/lib. Mari kita periksa apa yang kita miliki di kedua lokasi.
[root@localhost pg_repack]# ls -l /lib64/libldap*
lrwxrwxrwx. 1 root root 21 Jan 6 22:05 libldap-2.4.so.2 -> libldap-2.4.so.2.10.2
-rwxr-xr-x. 1 root root 329696 Oct 15 2014 libldap-2.4.so.2.10.2
lrwxrwxrwx. 1 root root 23 May 19 06:43 libldap_r-2.4.so.2 -> libldap_r-2.4.so.2.10.2
-rwxr-xr-x. 1 root root 351920 Oct 15 2014 libldap_r-2.4.so.2.10.2
[root@localhost pg_repack]# ls -l /opt/PostgreSQL/9.4/lib/libldap*
-rwxr-xr-x. 1 root daemon 404761 Mar 22 23:32 /opt/PostgreSQL/9.4/lib/libldap-2.4.so.2
-rwxr-xr-x. 1 root daemon 442657 Mar 22 23:32 /opt/PostgreSQL/9.4/lib/libldap_r-2.4.so.2
Tampaknya ada dua salinan "libldap_r-2.4.so.2", satu dalam bentuk tautan simbolis dan satu lagi sebagai salinan cetak. Saya menduga ini karena banyak salinan perpustakaan, mari hapus tautan simbolis dan simpan salinan cetak perpustakaan dan coba lagi.
[root@localhost lib64]# unlink libldap_r-2.4.so.2
[root@localhost pg_repack]# make
make[1]: Entering directory `/root/pg_repack/bin'
....
....
....
sed 's,REPACK_VERSION,1.3.1,g' pg_repack.sql.in > pg_repack--1.3.1.sql;
sed 's,REPACK_VERSION,1.3.1,g' pg_repack.control.in > pg_repack.control
make[1]: Leaving directory `/root/pg_repack/lib'
make[1]: Entering directory `/root/pg_repack/regress'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/root/pg_repack/regress'
wah…akhirnya udah dikompilasi. Jalankan “make install” untuk binari dan pustaka pg_repack.
[root@localhost pg_repack]# make install
make[1]: Entering directory `/root/pg_repack/bin'
/bin/mkdir -p '/opt/PostgreSQL/9.4/bin'
/usr/bin/install -c pg_repack '/opt/PostgreSQL/9.4/bin'
make[1]: Leaving directory `/root/pg_repack/bin'
make[1]: Entering directory `/root/pg_repack/lib'
/bin/mkdir -p '/opt/PostgreSQL/9.4/lib/postgresql'
/bin/mkdir -p '/opt/PostgreSQL/9.4/share/postgresql/extension'
/bin/mkdir -p '/opt/PostgreSQL/9.4/share/postgresql/extension'
/usr/bin/install -c -m 755 pg_repack.so '/opt/PostgreSQL/9.4/lib/postgresql/pg_repack.so'
/usr/bin/install -c -m 644 pg_repack.control '/opt/PostgreSQL/9.4/share/postgresql/extension/'
/usr/bin/install -c -m 644 pg_repack--1.3.1.sql pg_repack.control '/opt/PostgreSQL/9.4/share/postgresql/extension/'
make[1]: Leaving directory `/root/pg_repack/lib'
make[1]: Entering directory `/root/pg_repack/regress'
make[1]: Nothing to be done for `install'.
make[1]: Leaving directory `/root/pg_repack/regress'
Setelah kompilasi akan ada utilitas pg_repack di perpustakaan $PGHOME/bin dan pg_repack.so di direktori $PGHOME/lib/postgresql/.
[root@localhost pg_repack]# ls -l /opt/PostgreSQL/9.4/bin/pg_rep*
-rwxr-xr-x. 1 root root 84030 May 20 00:07 /opt/PostgreSQL/9.4/bin/pg_repack
[root@localhost postgresql]# ls -l /opt/PostgreSQL/9.4/lib/postgresql/pg_rep*
-rwxr-xr-x. 1 root root 31028 May 20 00:07 /opt/PostgreSQL/9.4/lib/postgresql/pg_repack.so
Sekarang kita siap untuk membuat ekstensi pg_repack di dalam database.
-bash-4.1$ psql
Password:
psql.bin (9.4.1)
Type "help" for help.
postgres=# select * from pg_available_extensions where name='pg_repack';
name | default_version | installed_version | comment
-----------+-----------------+-------------------+--------------------------------------------------------------
pg_repack | 1.3.1 | 1.3.1 | Reorganize tables in PostgreSQL databases with minimal locks
(1 row)
postgres=# create extension pg_repack;
CREATE EXTENSION
Demikian juga, saya telah mencoba untuk mengkompilasi dengan produk EnterpriseDB PostgresPlus Advanced Server 9.4[PPAS] paket biner yang dibuat sebelumnya. Menghadapi masalah perpustakaan serupa, maka saya telah menggunakan opsi tautan "LDFLAGS" yang menunjuk ke direktori perpustakaan dan dikompilasi.
[root@localhost ~]# export PATH=/opt/PostgresPlus/9.4AS/bin:$PATH
[root@localhost ~]# export LDFLAGS=-L/opt/PostgresPlus/9.4AS/lib
[root@localhost ~]# cd pg_repack/
[root@localhost pg_repack]# make
[root@localhost pg_repack]# make install
[root@localhost pg_repack]# ls -l /opt/PostgresPlus/9.4AS/bin/pg_rep*
-rwxr-xr-x. 1 root root 201877 May 15 11:06 /opt/PostgresPlus/9.4AS/bin/pg_repack
[root@localhost pg_repack]# ls -l /opt/PostgresPlus/9.4AS/lib/pg_rep*
-rwxr-xr-x. 1 root root 94516 May 15 11:06 /opt/PostgresPlus/9.4AS/lib/pg_repack.so
Keren, ini juga dikompilasi dengan lancar. Sekarang buat ekstensi di PPAS 9.4
-bash-4.1$ psql
Welcome
psql.bin (9.4.1.4)
Type "help" for help.
edb=# create extension pg_repack;
CREATE EXTENSION
edb=#
Terima kasih.