Wednesday, 28 October 2009

Menginstall postgreSQL di linux

Instalasi PostgreSQL

Tahap-tahapan Installasi PostgreSQL ini dalam bentuk Source.
Pertama-tama Download PostgreSQL Disini.
Karena dalam menginstal ini menggunakan user biasa maka dari itu kita harus membuatnya terlebih dahulu, berikut perintah untuk membuat user baru:


[root@localhost ~]# useradd pebriana
[root@localhost ~]# passwd pebriana
Changing password for user pebriana.
New UNIX password:
BAD PASSWORD: it is WAY too short
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@localhost ~]#


Tentukan lokasi instalasi PostgreSQL, misal di direktori /home/pebriana/ kemudian masuk sebagai user biasa,


[root@localhost ~]# su - pebriana
[pebriana@localhost ~]$


Ekstrak paket tarball (postgresql-8.0.0.tar.gz) hasil download dan diletakan di home direktori, dengan menjalankan perintah berikut ini:


[pebriana@localhost ~] tar -xzvf postgresql-8.4.1.tar.gz


pindah ke direktori hasil extrak tadi:


[pebriana@localhost ~]$ cd postgresql-8.4.1
[pebriana@localhost postgresql-8.4.1]$ ls
aclocal.m4 configure contrib doc HISTORY Makefile src
config configure.in COPYRIGHT GNUmakefile.in INSTALL README


Jalankan perintah berikut untuk configure PostgreSQL yang akan di install pada direktori /home/pebriana/pgsql:


[pebriana@localhost postgresql-8.4.1]$ ./configure –prefix=/home/pebriana/pgsql


Jalankan perintah make


[pebriana@localhost postgresql-8.4.1]$ make


tunggu beberapa saat Pada bagian akhir proses ini, jika tidak terjadi hal-hal yang tak diinginkan, seperti kurang beberapa library pendukung untuk install PostgreSQL atau proses make berjalan lancar akan muncul baris berikut ini:


make[1]: Leaving directory `/home/pebriana/postgresql-8.4.1/config'
All of PostgreSQL successfully made. Ready to install.


Berarti anda siap untuk instal PostgreSQL

Login sebagai root, kemudian jalankan proses installasi PostgreSQL


[pebriana@localhost ~]$ su
password:
[root@localhost ~]# make install


jika muncul seperti tampilan berikut ini. berarti PostgreSQL telah berhasil terinstal di Linux anda.

make[1]: Leaving directory `/home/pebriana/postgresql-8.4.1/config'
PostgreSQL installation complete.



Direktori data
Pada direktori data ini nantinya akan di simpan file-file konfigurasi PostgreSQL dan binary dari data anda.
untuk membuat direktori data berikut ini langkah-langkahnya:

[root@localhost ~]# su pebriana
password:
[pebriana@localhost ~]$ mkdir /home/pebriana/pgsqldata


ubah izin akses kepemilikan direktori data menjadi user yang anda inginkan.


[pebriana@localhost ~]$ chown pebriana.pebriana /home/pebriana/pgsqldata


Inisialisasi direktori data,

[pebriana@localhost ~]$ /home/pebriana/pgsql/bin/initdb -D /home/pebriana/pgsqldata/

The files belonging to this database system will be owned by user "pebriana".
This user must also own the server process.

fixing permissions on existing directory /home/pebriana/pgsqldata ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 32MB
creating configuration files ... ok
creating template1 database in /home/pebriana/pgsqldata/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:

/home/pebriana/pgsql/bin/postgres -D /home/pebriana/pgsqldata
or
/home/pebriana/pgsql/bin/pg_ctl -D /home/pebriana/pgsqldata -l logfile start


Jalankan service PostgreSQL:

[pebriana@localhost ~]$ /home/pebriana/pgsql/bin/pg_ctl -D /home/pebriana/pgsqldata -l logfile start
server starting


Mematikan Service PostgreSQL:

[pebriana@localhost ~]$ /home/pebriana/pgsql/bin/pg_ctl -D /home/pebriana/pgsqldata -l logfile start
waiting for server to shut down.... done
server stopped



Password Security dan konfigurasi file PostgreSQL

login sebagai user pebriana (user system) dan login ke databases pebriana (template1)

[pebriana@localhost ~]$ psql template1

Welcome to psql 8.1.11 (server 8.4.1), 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

WARNING: You are connected to a server with major version 8.4,
but your psql client is major version 8.1. Some backslash commands,
such as \d, might not work properly.
template1=#


Dari konsole database template1, jalankan perintah SQL untuk mengubah password user postgres. Kemudian keluar dari user terminal interactive PostgreSQL


template1=# alter user pebriana with password '12345';
ALTER ROLE
template1=# \q


konfigurasi file pg_hba.conf dan postgresql.conf yang berada di direktori data.
Edit file /home/pebriana/pgsqldata/pg_hba.conf pada 10 baris terakhir file ini, menjadi :


[pebriana@localhost ~]$ cd pgsqldata
[pebriana@localhost pgsqldata]$ vim pg_hba.conf


Installasi PostgreSQL

simpan dengan perintah wq

Edit file /home/pebriana/pgsqldata/postgresql.conf untuk TCP/IP connection, dengan cukup mengubah bagian berikut atau tepatnya mengaktifkan property berikut:


[pebriana@localhost pgsqldata]$ vim postgresql.conf


PostgreSQL
ganti localhost dengan * kemudian simpan dengan perintah wq
Setelah Selesai restart service PostgreSQL anda


[pebriana@localhost pgsqldata]$ /home/pebriana/pgsql/bin/pg_ctl -D /home/pebriana/pgsqldata -l logfile restart


Buat User database PostgreSQL
Untuk membuat user baru pada database PostgreSQL haruslah yang membuat user postgres

Jalankan perintah berikut untuk buat user database PostgreSQL ( anda tidak harus sebagai root ) Misalkan user baru = apri.

[pebriana@localhost pgsqldata]$ createuser apri -P -U pebriana


option -p pada command diatas untuk sekaligus membuat password user baru,
sedangkan option -U postgres berarti hanya user postgres yang berhak membuat user baru
Selanjutnya anda diminta untuk memasukan password user_baru kemudian
apakah user_baru boleh membuat database ? ya
apakah user_baru boleh create user baru ? tentu saja tidak
Setelah itu masukan password dari user postgres pada database PostgreSQL


Enter password for new role:
Enter it again:
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) y
Shall the new role be allowed to create more new roles? (y/n) n
CREATE ROLE


Membuat database
Berikut perintah user database untuk create database baru

[pebriana@localhost pgsqldata]$ createdb tes -U apri
password:
CREATE DATABASE

Perintah diatas berarti membuat database tes dimana pemilik database tersebut adalah user database apri.
Login ke database dengan PostgreSQL
Untuk login ke database PostgreSQL jalankan perintah berikut ini:

[pebriana@localhost pgsqldata]$ psql tes -U apri
Welcome to psql 8.1.11 (server 8.4.1), 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

WARNING: You are connected to a server with major version 8.4,
but your psql client is major version 8.1. Some backslash commands,
such as \d, might not work properly.

tes=>


Menghapus Database
Berikut perintah user database untuk menghapus/drop database

[pebriana@localhost pgsqldata]$ dropdb tes -U apri

Perintah diatas berarti menghapus database tes.

No comments:

Post a Comment