Mirip dengan mySQL, postgreSQL sangat terkenal dan dikemas dengan fitur basis data sumber terbuka dan gratis .
Sebelumnya kita telah membahas beberapa instalasi termasuk instalasi LAMP stack, instalasi Apache2 dari sumber, instalasi PHP5 dari sumber dan instalasi mySQL.
Pada artikel ini, mari kita tinjau cara menginstal database postgreSQL di Linux dari kode sumber.
Langkah 1:Unduh kode sumber postgreSQL
Dari situs unduhan postgreSQL, pilih situs mirror yang terletak di negara Anda.
# wget http://wwwmaster.postgresql.org/redir/198/f/source/v8.3.7/postgresql-8.3.7.tar.gz
Langkah 2:Instal postgreSQL
# tar xvfz postgresql-8.3.7.tar.gz # cd postgresql-8.3.7 # ./configure checking for sgmlspl... no configure: creating ./config.status config.status: creating GNUmakefile config.status: creating src/Makefile.global config.status: creating src/include/pg_config.h config.status: creating src/interfaces/ecpg/include/ecpg_config.h config.status: linking ./src/backend/port/tas/dummy.s to src/backend/port/tas.s config.status: linking ./src/backend/port/dynloader/linux.c to src/backend/port/dynloader.c config.status: linking ./src/backend/port/sysv_sema.c to src/backend/port/pg_sema.c config.status: linking ./src/backend/port/sysv_shmem.c to src/backend/port/pg_shmem.c config.status: linking ./src/backend/port/dynloader/linux.h to src/include/dynloader.h config.status: linking ./src/include/port/linux.h to src/include/pg_config_os.h config.status: linking ./src/makefiles/Makefile.linux to src/Makefile.port # make make[3]: Leaving directory `/usr/save/postgresql-8.3.7/contrib/spi' rm -rf ./testtablespace mkdir ./testtablespace make[2]: Leaving directory `/usr/save/postgresql-8.3.7/src/test/regress' make[1]: Leaving directory `/usr/save/postgresql-8.3.7/src' make -C config all make[1]: Entering directory `/usr/save/postgresql-8.3.7/config' make[1]: Nothing to be done for `all'. make[1]: Leaving directory `/usr/save/postgresql-8.3.7/config' All of PostgreSQL successfully made. Ready to install. # make install make -C test/regress install make[2]: Entering directory `/usr/save/postgresql-8.3.7/src/test/regress' /bin/sh ../../../config/install-sh -c pg_regress '/usr/local/pgsql/lib/pgxs/src/test/regress/pg_regress' make[2]: Leaving directory `/usr/save/postgresql-8.3.7/src/test/regress' make[1]: Leaving directory `/usr/save/postgresql-8.3.7/src' make -C config install make[1]: Entering directory `/usr/save/postgresql-8.3.7/config' mkdir -p -- /usr/local/pgsql/lib/pgxs/config /bin/sh ../config/install-sh -c -m 755 ./install-sh '/usr/local/pgsql/lib/pgxs/config/install-sh' /bin/sh ../config/install-sh -c -m 755 ./mkinstalldirs '/usr/local/pgsql/lib/pgxs/config/mkinstalldirs' make[1]: Leaving directory `/usr/save/postgresql-8.3.7/config' PostgreSQL installation complete.
PostgreSQL ./konfigurasi opsi
Berikut adalah berbagai opsi yang dapat diteruskan ke ./configure:
- –prefix=PREFIX menginstal file arsitektur-independen di PREFIX. Lokasi instalasi default adalah /usr/local/pgsql
- –enable-integer-datetimes aktifkan dukungan tanggal/waktu integer 64-bit
- –enable-nls[=LANGUAGES] aktifkan Dukungan Bahasa Asli
- –disable-shared jangan buat library bersama
- –disable-rpath jangan menyematkan jalur penelusuran pustaka bersama di file yang dapat dieksekusi
- –disable-spinlocks jangan gunakan spinlock
- –enable-debug build dengan simbol debug (-g)
- –enable-profiling build dengan profil yang diaktifkan
- –enable-dtrace build dengan dukungan DTrace
- –enable-depend aktifkan pelacakan ketergantungan otomatis
- –enable-cassert aktifkan pemeriksaan pernyataan (untuk debugging)
- –enable-thread-safety menjadikan library klien thread-safe
- –enable-thread-safety-force memaksa thread-safety meskipun pengujian thread gagal
- –disable-largefile menghilangkan dukungan untuk file besar
- –with-docdir=DIR instal dokumentasi di DIR [PREFIX/doc]
- –tanpa-docdir jangan instal dokumentasi
- –with-includes=DIRS mencari file header tambahan di DIRS
- –with-libraries=DIRS mencari library tambahan di DIRS
- –with-libs=DIRS ejaan alternatif –with-libraries
- –with-pgport=PORTNUM ubah nomor port default [5432]
- –dengan-tcl membangun modul Tcl (PL/Tcl)
- –with-tclconfig=DIR tclConfig.sh ada di DIR
- –with-perl membangun modul Perl (PL/Perl)
- –with-python membangun modul Python (PL/Python)
- –with-gssapi build dengan dukungan GSSAPI
- –with-krb5 build dengan dukungan Kerberos 5
- –with-krb-srvnam=NAME nama utama layanan default di Kerberos [postgres]
- –with-pam build dengan dukungan PAM
- –with-ldap build dengan dukungan LDAP
- –with-bonjour build dengan dukungan Bonjour
- –with-openssl build dengan dukungan OpenSSL
- –tanpa-readline jangan gunakan GNU Readline atau BSD Libedit untuk mengedit
- –with-libedit-preferred lebih memilih BSD Libedit daripada GNU Readline
- –with-ossp-uuid menggunakan library UUID OSSP saat membuat contrib/uuid-ossp
- –with-libxml build dengan dukungan XML
- –with-libxslt gunakan dukungan XSLT saat membuat contrib/xml2
- –with-system-tzdata=DIR menggunakan data zona waktu sistem dalam DIR
- –tanpa-zlib jangan gunakan Zlib
- –with-gnu-ld asumsikan compiler C menggunakan GNU ld [default=no]
Masalah Instalasi PostgreSQL1:
Anda mungkin menemukan pesan kesalahan berikut saat melakukan ./configure selama instalasi postgreSQL.
# ./configure checking for -lreadline... no checking for -ledit... no configure: error: readline library not found If you have readline already installed, see config.log for details on the failure. It is possible the compiler isn't looking in the proper directory. Use --without-readline to disable readline support.
Solusi Instalasi PostgreSQL1:
Instal readline-devel dan libtermcap-devel untuk mengatasi masalah di atas.
# rpm -ivh libtermcap-devel-2.0.8-46.1.i386.rpm readline-devel-5.1-1.1.i386.rpm warning: libtermcap-devel-2.0.8-46.1.i386.rpm: Header V3 DSA signature: NOKEY, key ID 1e5e0159 Preparing... ########################################### [100%] 1:libtermcap-devel ########################################### [ 50%] 2:readline-devel ########################################### [100%]
Langkah 3:Verifikasi struktur direktori postgreSQL
Setelah instalasi, pastikan direktori bin, doc, include, lib, man dan share dibuat di bawah direktori /usr/local/pgsql default seperti yang ditunjukkan di bawah ini.
# ls -l /usr/local/pgsql/ total 24 drwxr-xr-x 2 root root 4096 Apr 8 23:25 bin drwxr-xr-x 3 root root 4096 Apr 8 23:25 doc drwxr-xr-x 6 root root 4096 Apr 8 23:25 include drwxr-xr-x 3 root root 4096 Apr 8 23:25 lib drwxr-xr-x 4 root root 4096 Apr 8 23:25 man drwxr-xr-x 5 root root 4096 Apr 8 23:25 share
Langkah 4:Buat akun pengguna postgreSQL
# adduser postgres # passwd postgres Changing password for user postgres. New UNIX password: Retype new UNIX password: passwd: all authentication tokens updated successfully.
Langkah 5:Buat direktori data postgreSQL
Buat direktori data postgres dan jadikan pengguna postgres sebagai pemiliknya.
# mkdir /usr/local/pgsql/data # chown postgres:postgres /usr/local/pgsql/data # ls -ld /usr/local/pgsql/data drwxr-xr-x 2 postgres postgres 4096 Apr 8 23:26 /usr/local/pgsql/data
Langkah 6:Inisialisasi direktori data postgreSQL
Sebelum Anda dapat mulai membuat database postgreSQL apa pun, direktori data kosong yang dibuat pada langkah di atas harus diinisialisasi menggunakan perintah initdb seperti yang ditunjukkan di bawah ini.
# su - postgres # /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data/ The files belonging to this database system will be owned by user postgres This user must also own the server process. The database cluster will be initialized with locale en_US.UTF-8. The default database encoding has accordingly been set to UTF8. The default text search configuration will be set to "english". fixing permissions on existing directory /usr/local/pgsql/data ... ok creating subdirectories ... ok selecting default max_connections ... 100 selecting default shared_buffers/max_fsm_pages ... 32MB/204800 creating configuration files ... ok creating template1 database in /usr/local/pgsql/data/base/1 ... ok initializing pg_authid ... ok initializing dependencies ... ok creating system views ... ok loading system objects' descriptions ... ok creating conversions ... ok creating dictionaries ... ok setting privileges on built-in objects ... ok creating information schema ... ok vacuuming database template1 ... ok copying template1 to template0 ... ok copying template1 to postgres ... ok WARNING: enabling "trust" authentication for local connections You can change this by editing pg_hba.conf or using the -A option the next time you run initdb. Success. You can now start the database server using: /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data or /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
Langkah 7:Validasi direktori data postgreSQL
Pastikan semua file konfigurasi DB postgres (Misalnya, postgresql.conf) dibuat di bawah direktori data seperti yang ditunjukkan di bawah ini.
$ ls -l /usr/local/pgsql/data total 64 drwx------ 5 postgres postgres 4096 Apr 8 23:29 base drwx------ 2 postgres postgres 4096 Apr 8 23:29 global drwx------ 2 postgres postgres 4096 Apr 8 23:29 pg_clog -rw------- 1 postgres postgres 3429 Apr 8 23:29 pg_hba.conf -rw------- 1 postgres postgres 1460 Apr 8 23:29 pg_ident.conf drwx------ 4 postgres postgres 4096 Apr 8 23:29 pg_multixact drwx------ 2 postgres postgres 4096 Apr 8 23:29 pg_subtrans drwx------ 2 postgres postgres 4096 Apr 8 23:29 pg_tblspc drwx------ 2 postgres postgres 4096 Apr 8 23:29 pg_twophase -rw------- 1 postgres postgres 4 Apr 8 23:29 PG_VERSION drwx------ 3 postgres postgres 4096 Apr 8 23:29 pg_xlog -rw------- 1 postgres postgres 16592 Apr 8 23:29 postgresql.conf
Langkah 8:Mulai database postgreSQL
Gunakan perintah postgres postmaster untuk memulai server postgreSQL di latar belakang seperti yang ditunjukkan di bawah ini.
$ /usr/local/pgsql/bin/postmaster -D /usr/local/pgsql/data >logfile 2>&1 & [1] 2222 $ cat logfile LOG: database system was shut down at 2009-04-08 23:29:50 PDT LOG: autovacuum launcher started LOG: database system is ready to accept connections
Langkah 9:Buat DB postgreSQL dan uji instalasi
Buat database uji dan sambungkan untuk memastikan instalasi berhasil seperti yang ditunjukkan di bawah ini. Setelah Anda mulai menggunakan database, lakukan pencadangan sesering yang disebutkan dalam artikel cara mencadangkan dan memulihkan PostgreSQL.
$ /usr/local/pgsql/bin/createdb test $ /usr/local/pgsql/bin/psql test Welcome to psql 8.3.7, the PostgreSQL interactive terminal. Type: \copyright for distribution terms \h for help with SQL commands \? for help with psql commands \g or terminate with semicolon to execute query \q to quit test=#