Showing posts with label Postgres. Show all posts
Showing posts with label Postgres. Show all posts

Wednesday, 26 September 2012

How to configure postgres in rhel 6.3 / centos 6.3


-->
[root@station1 ~]# yum install postgresql*

Initializing the data first

root@station1 ~]# /etc/init.d/postgresql initdb
Initializing database: [ OK ]

Set PostgreSQL Environment

[root@station1 ~]# vim /var/lib/pgsql/.bash_profile
1 [ -f /etc/profile ] && source /etc/profile
2
3 PGDATA=/var/lib/pgsql/data
4 export PGDATA
5 PATH=$PATH:$HOME/bin:/usr/bin
6 export PATH
[root@station1 ~]# service postgresql start
Starting postgresql service: [ OK ]

Set postgres Password

[root@station1 ~]# su - postgres
-bash-4.1$ psql postgres postgres
psql (8.4.11)
Type "help" for help.
postgres=# alter user postgres with password 'postgres';
ALTER ROLE
postgres=#

Configure PostgreSQL pg_hba.conf File

[root@station1 ~]# vim /var/lib/pgsql/data/pg_hba.conf
70 local all all md5
71 # IPv4 local connections:
72 host all all 127.0.0.1/32 md5
73 # IPv6 local connections:
74 host all all ::1/128 md5

In order for the change to take effect, reload the pg_hba.conf file.

As with any command, there are several ways you can reload the pg_hba.conf file.

Method 1: From the shell using pg_ctl reload:
[root@station1 ~]# su - postgres
-bash-4.1$ pg_ctl reload
server signaled
-bash-4.1$

Method 2: From psql using pg_reload_conf();
[root@station1 ~]# su - postgres
-bash-4.1$ psql postgres postgres
Password for user postgres:
psql (8.4.11)
Type "help" for help.
postgres=# SELECT pg_reload_conf();
pg_reload_conf
----------------
t
(1 row)
postgres=#

Method 3: From the shell using -c switch to run select pg_reload_conf();
[root@station1 ~]# su - postgres
-bash-4.1$ psql postgres postgres -c "select pg_reload_conf();"
Password for user postgres:
pg_reload_conf
----------------
t
(1 row)
-bash-4.1$