Install PostgreSQL 8.4 Database Server pada Red Hat


Ini merupakan quick guide cara install server database PostgreSQL 8.4 (saat ini stable 8.4.7) pada CentOS, Fedora and Red Hat. Fedora 14, Fedora 13, CentOS 5,5 Dan Red Hat (RHEL) 5.5 memiliki database server PostgreSQL 8,4 sebagai defaultnya, jadi tidak membutuhkan repositori tambahan (extra). Secara pribadi, saya lebih suka menggunakan repo milik Postgres, karena versi terbaru dari PostgreSQL dapat dengan cepat dan mudah diinstal. Perintah berikut dijalankan sebagai “root” dan user “postgres”, jadi pertama-tama “su -” atau “sudo -i”.

Install Server Database PostgreSQL 8.4 Menggunakan Repo PostgreSQL

Install repositori PostgreSQL:

## CentOS
rpm -Uvh http://yum.pgrpms.org/reporpms/8.4/pgdg-centos-8.4-2.noarch.rpm

## Fedora
rpm -Uvh http://yum.pgrpms.org/reporpms/8.4/pgdg-fedora-8.4-2.noarch.rpm

## Red Hat
rpm -Uvh http://yum.pgrpms.org/reporpms/8.4/pgdg-redhat-8.4-2.noarch.rpm

Install postgresql dan paket postgresql-server dari  repo PostgreSQL:

yum install postgresql postgresql-server postgresql-contrib

Metode Alternatif Install PostgreSQL 8.4

Install postgresql dan paket postgresql-server pada CentOS 5.5 dan Red Hat (RHEL) 5.5:

yum install postgresql84 postgresql84-server postgresql84-contrib

Install postgresql dan  paket postgresql-server pada Fedora 12 dan Fedora 13:

yum install postgresql postgresql-server postgresql-contrib

Proses install di ClearOS 6.2 Beta 3

[root@system ~]# yum install postgresql postgresql-server postgresql-contrib
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * clearos: mirror2-houston.clearsdn.com
 * clearos-addons: mirror2-houston.clearsdn.com
 * clearos-extras: mirror2-houston.clearsdn.com
 * clearos-updates: mirror2-houston.clearsdn.com
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package postgresql.i686 0:8.4.9-1.el6_1.1 will be installed
--> Processing Dependency: postgresql-libs(x86-32) = 8.4.9-1.el6_1.1 for package: postgresql-8.4.9-1.el6_1.1.i686
--> Processing Dependency: libpq.so.5 for package: postgresql-8.4.9-1.el6_1.1.i686
---> Package postgresql-contrib.i686 0:8.4.9-1.el6_1.1 will be installed
--> Processing Dependency: libossp-uuid.so.16 for package: postgresql-contrib-8.4.9-1.el6_1.1.i686
---> Package postgresql-server.i686 0:8.4.9-1.el6_1.1 will be installed
--> Running transaction check
---> Package postgresql-libs.i686 0:8.4.9-1.el6_1.1 will be installed
---> Package uuid.i686 0:1.6.1-10.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package               Arch    Version               Repository            Size
================================================================================
Installing:
 postgresql            i686    8.4.9-1.el6_1.1       clearcore-current    2.7 M
 postgresql-contrib    i686    8.4.9-1.el6_1.1       clearcore-current    345 k
 postgresql-server     i686    8.4.9-1.el6_1.1       clearcore-current    3.3 M
Installing for dependencies:
 postgresql-libs       i686    8.4.9-1.el6_1.1       clearcore-current    200 k
 uuid                  i686    1.6.1-10.el6          clearcore-current     53 k

Transaction Summary
================================================================================
Install       5 Package(s)

Total download size: 6.6 M
Installed size: 29 M
Is this ok [y/N]: y
Downloading Packages:
(1/5): postgresql-8.4.9-1.el6_1.1.i686.rpm               | 2.7 MB     00:55
(2/5): postgresql-contrib-8.4.9-1.el6_1.1.i686.rpm       | 345 kB     00:08
(3/5): postgresql-libs-8.4.9-1.el6_1.1.i686.rpm          | 200 kB     00:02
(4/5): postgresql-server-8.4.9-1.el6_1.1.i686.rpm        | 3.3 MB     01:09
(5/5): uuid-1.6.1-10.el6.i686.rpm                        |  53 kB     00:01
--------------------------------------------------------------------------------
Total                                            46 kB/s | 6.6 MB     02:27
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : postgresql-libs-8.4.9-1.el6_1.1.i686                         1/5
  Installing : postgresql-8.4.9-1.el6_1.1.i686                              2/5
  Installing : uuid-1.6.1-10.el6.i686                                       3/5
  Installing : postgresql-contrib-8.4.9-1.el6_1.1.i686                      4/5
  Installing : postgresql-server-8.4.9-1.el6_1.1.i686                       5/5

Installed:
  postgresql.i686 0:8.4.9-1.el6_1.1
  postgresql-contrib.i686 0:8.4.9-1.el6_1.1
  postgresql-server.i686 0:8.4.9-1.el6_1.1

Dependency Installed:
  postgresql-libs.i686 0:8.4.9-1.el6_1.1        uuid.i686 0:1.6.1-10.el6

Complete!

Untuk cek paket instalasi Postgres, bisa menggunakan perintah # yum list postgres*

[root@system ~]# yum list postgres*
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * clearos: mirror2-houston.clearsdn.com
 * clearos-addons: mirror2-houston.clearsdn.com
 * clearos-extras: mirror2-houston.clearsdn.com
 * clearos-updates: mirror2-houston.clearsdn.com
Installed Packages
postgresql.i686                      8.4.9-1.el6_1.1          @clearcore-current
postgresql-contrib.i686              8.4.9-1.el6_1.1          @clearcore-current
postgresql-libs.i686                 8.4.9-1.el6_1.1          @clearcore-current
postgresql-server.i686               8.4.9-1.el6_1.1          @clearcore-current
Available Packages
postgresql-devel.i686                8.4.9-1.el6_1.1          clearcore-current
postgresql-docs.i686                 8.4.9-1.el6_1.1          clearcore-current
postgresql-jdbc.i686                 8.4.701-3.el6            clearcore-current
postgresql-jdbc.noarch               8.4.702-1PGDG.rhel6      pgdg84
postgresql-odbc.i686                 08.04.0200-1.el6         clearcore-current
postgresql-plperl.i686               8.4.9-1.el6_1.1          clearcore-current
postgresql-plpython.i686             8.4.9-1.el6_1.1          clearcore-current
postgresql-pltcl.i686                8.4.9-1.el6_1.1          clearcore-current
postgresql-test.i686                 8.4.9-1.el6_1.1          clearcore-current
postgresql84.i686                    8.4.11-1PGDG.rhel6       pgdg84
postgresql84-contrib.i686            8.4.11-1PGDG.rhel6       pgdg84
postgresql84-debuginfo.i686          8.4.11-1PGDG.rhel6       pgdg84
postgresql84-devel.i686              8.4.11-1PGDG.rhel6       pgdg84
postgresql84-docs.i686               8.4.11-1PGDG.rhel6       pgdg84
postgresql84-jdbc.i686               8.4.703-1PGDG.rhel6      pgdg84
postgresql84-jdbc-debuginfo.i686     8.4.703-1PGDG.rhel6      pgdg84
postgresql84-libs.i686               8.4.11-1PGDG.rhel6       pgdg84
postgresql84-odbc.i686               08.04.0200-1PGDG.rhel6   pgdg84
postgresql84-odbc-debuginfo.i686     08.04.0200-1PGDG.rhel6   pgdg84
postgresql84-plperl.i686             8.4.11-1PGDG.rhel6       pgdg84
postgresql84-plpython.i686           8.4.11-1PGDG.rhel6       pgdg84
postgresql84-pltcl.i686              8.4.11-1PGDG.rhel6       pgdg84
postgresql84-python.i686             4.0-1PGDG.rhel6          pgdg84
postgresql84-python-debuginfo.i686   4.0-1PGDG.rhel6          pgdg84
postgresql84-server.i686             8.4.11-1PGDG.rhel6       pgdg84
postgresql84-test.i686               8.4.11-1PGDG.rhel6       pgdg84
[root@system ~]# clear
[root@system ~]# yum list postgres*
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * clearos: mirror2-houston.clearsdn.com
 * clearos-addons: mirror2-houston.clearsdn.com
 * clearos-extras: mirror2-houston.clearsdn.com
 * clearos-updates: mirror2-houston.clearsdn.com
Installed Packages
postgresql.i686                      8.4.9-1.el6_1.1          @clearcore-current
postgresql-contrib.i686              8.4.9-1.el6_1.1          @clearcore-current
postgresql-libs.i686                 8.4.9-1.el6_1.1          @clearcore-current
postgresql-server.i686               8.4.9-1.el6_1.1          @clearcore-current
Available Packages
postgresql-devel.i686                8.4.9-1.el6_1.1          clearcore-current
postgresql-docs.i686                 8.4.9-1.el6_1.1          clearcore-current
postgresql-jdbc.i686                 8.4.701-3.el6            clearcore-current
postgresql-jdbc.noarch               8.4.702-1PGDG.rhel6      pgdg84
postgresql-odbc.i686                 08.04.0200-1.el6         clearcore-current
postgresql-plperl.i686               8.4.9-1.el6_1.1          clearcore-current
postgresql-plpython.i686             8.4.9-1.el6_1.1          clearcore-current
postgresql-pltcl.i686                8.4.9-1.el6_1.1          clearcore-current
postgresql-test.i686                 8.4.9-1.el6_1.1          clearcore-current
postgresql84.i686                    8.4.11-1PGDG.rhel6       pgdg84
postgresql84-contrib.i686            8.4.11-1PGDG.rhel6       pgdg84
postgresql84-debuginfo.i686          8.4.11-1PGDG.rhel6       pgdg84
postgresql84-devel.i686              8.4.11-1PGDG.rhel6       pgdg84
postgresql84-docs.i686               8.4.11-1PGDG.rhel6       pgdg84
postgresql84-jdbc.i686               8.4.703-1PGDG.rhel6      pgdg84
postgresql84-jdbc-debuginfo.i686     8.4.703-1PGDG.rhel6      pgdg84
postgresql84-libs.i686               8.4.11-1PGDG.rhel6       pgdg84
postgresql84-odbc.i686               08.04.0200-1PGDG.rhel6   pgdg84
postgresql84-odbc-debuginfo.i686     08.04.0200-1PGDG.rhel6   pgdg84
postgresql84-plperl.i686             8.4.11-1PGDG.rhel6       pgdg84
postgresql84-plpython.i686           8.4.11-1PGDG.rhel6       pgdg84
postgresql84-pltcl.i686              8.4.11-1PGDG.rhel6       pgdg84
postgresql84-python.i686             4.0-1PGDG.rhel6          pgdg84
postgresql84-python-debuginfo.i686   4.0-1PGDG.rhel6          pgdg84
postgresql84-server.i686             8.4.11-1PGDG.rhel6       pgdg84
postgresql84-test.i686               8.4.11-1PGDG.rhel6       pgdg84

Konfigurasi Server Database PostgreSQL 8.4

Inisialisasi cluster dengan perintah initdb:

service postgresql initdb
## OR ##
/etc/init.d/postgresql initdb

Edit file /var/lib/pgsql/data/postgresql.conf:

nano -w /var/lib/pgsql/data/postgresql.conf

Seting server PostgreSQL agar memperhatikan (listen) semua alamat dan Rubah port PostgreSQL (default is 5432). Tambahkan/Uncomment/Edit baris berikut:

listen_addresses = '*'
port = 5432

Edit /var/lib/pgsql/data/pg_hba.conf file:

nano -w /var/lib/pgsql/data/pg_hba.conf

Tambahkan (Example) local network anda dengan md5 passwords:

# Local networks
host	all	all	xx.xx.xx.xx/xx	md5
# Example
host	all	all	10.20.4.0/24	md5

Start/Restart PostgreSQL Server:

service postgresql start
## OR ##
/etc/init.d/postgresql start

Rubah menjadi user postgres:

su postgres

Buat database test (sebagai user postgres):

createdb test

Login database test (sebagai user postgres):

psql test

Buat Role “testuser” baru  menggunakan Superuser dan Password:

CREATE ROLE testuser WITH SUPERUSER LOGIN PASSWORD 'test';

Buka Port PostgreSQL (5432) di Iptables Firewall (sebagai user root)

Edit /etc/sysconfig/iptables file:

nano -w /etc/sysconfig/iptables

Tambahkan baris berikut sebelum COMMIT:

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 5432 -j ACCEPT

Restart Iptables Firewall:

service iptables restart
## OR ##
/etc/init.d/iptables restart

Tes koneksi remot:

psql -h dbserver -U testuser test

Sumber: www.if-not-true-then-false.com

One response to “Install PostgreSQL 8.4 Database Server pada Red Hat

  1. asepwaluya July 10, 2012 at 11:53 am

    Reblogged this on alGhozaly Computer and commented:

    tes blog

Leave a comment