PostgreSQL is an open source and powerful database system, its executes on all major operating system like, Linux, Unix, HP-UX, Mac, etc...
This post describes to install the postgreSQL in Fedora or centOS operating system.

Install:

To install Postgresql execute below command,

# sudo yum install postgresql-server postgresql-contrib

Enable:

Once the installation process has been completed, enable a service to be started on bootup time. 
 
# sudo systemctl enable postgresql
ln -s '/usr/lib/systemd/system/postgresql.service' '/etc/systemd/system/multi-user.target.wants/postgresql.service'


Start :

To start your postgresql execute below command,
 
# sudo systemctl start postgresql
Job for postgresql.service failed. See 'systemctl status postgresql.service' and 'journalctl -xn' for details.


If you could not start execute the journalctl-xn to error,
 
#  journalctl -xn 

-- Logs begin at Wed 2015-01-07 02:24:43 IST, end at Wed 2015-01-07 15:25:21 IST. --
Jan 07 15:24:32 localhost.localdomain systemd[1]: Reached target Sound Card.
-- Subject: Unit sound.target has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit sound.target has finished starting up.
--
-- The start-up result is done.
Jan 07 15:25:02 localhost.localdomain sudo[26741]: root : TTY=pts/8 ; PWD=/opt/lampp ; USER=root ; COMMAND=/bin/systemctl start postgresql
Jan 07 15:25:02 localhost.localdomain systemd[1]: Starting PostgreSQL database server...
-- Subject: Unit postgresql.service has begun with start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit postgresql.service has begun starting up.
Jan 07 15:25:03 localhost.localdomain postgresql-check-db-dir[26744]: "/var/lib/pgsql/data" is missing or empty.
Jan 07 15:25:03 localhost.localdomain postgresql-check-db-dir[26744]: Use "postgresql-setup initdb" to initialize the database cluster.
Jan 07 15:25:03 localhost.localdomain postgresql-check-db-dir[26744]: See /usr/share/doc/postgresql/README.rpm-dist for more information.
Jan 07 15:25:03 localhost.localdomain systemd[1]: postgresql.service: control process exited, code=exited status=1
Jan 07 15:25:03 localhost.localdomain systemd[1]: Failed to start PostgreSQL database server.
-- Subject: Unit postgresql.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit postgresql.service has failed.
--
-- The result is failed.
Jan 07 15:25:03 localhost.localdomain systemd[1]: Unit postgresql.service entered failed state.
Jan 07 15:25:21 localhost.localdomain kernel: CPU1: Core temperature/speed normal


Initialization the database using the below command
 
# sudo postgresql-setup initdb
Initializing database ... OK


configuration file path located at : /var/lib/pgsql/data/pg_hba.conf

Databases located  at /var/lib/pgsql/data
 
# cd /var/lib/pgsql/data

# ls

base    pg_clog      pg_ident.conf  pg_multixact  pg_serial     pg_stat      pg_subtrans  pg_twophase  pg_xlog
global  pg_hba.conf  pg_log         pg_notify     pg_snapshots  pg_stat_tmp  pg_tblspc    PG_VERSION   postgresql.conf

Check whether the pgsql is running on your system or check with port number "netstat",
 
# ps aux | grep pgsql

postgres   657  0.0  0.7 161696 11116 ?        S    09:27   0:00 /usr/bin/postgres -D /var/lib/pgsql/data -p 5432
root      5686  0.0  0.0   4968   828 pts/1    S+   17:10   0:00 grep --color=auto pgsql

or
# netstat -anp | grep postgres

tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN      657/postgres
udp        0      0 127.0.0.1:35610         127.0.0.1:35610         ESTABLISHED 657/postgres
unix  2      [ ACC ]     STREAM     LISTENING     17568    657/postgres         /var/run/postgresql/.s.PGSQL.5432
unix  2      [ ACC ]     STREAM     LISTENING     17574    657/postgres         /tmp/.s.PGSQL.5432
unix  3      [ ]         STREAM     CONNECTED     16995    685/postgres: logge


give remote access

Open your configuration file and change the ident method to trust.
 
#  /var/lib/pgsql/data/pg_hba.conf

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     md5
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5


save and quit,
 
# sudo service postgresql restart
Redirecting to /bin/systemctl restart  postgresql.service


Enter Into PostgreSQL :
 
# psql -U postgres
psql: FATAL:  Peer authentication failed for user "postgres"

If you may getting an error execute below command to enter
 
# sudo -u postgres psql postgres

psql (9.3.5)
Type "help" for help.


To change postgres password,

postgres=# \password postgres
Enter new password:
Enter it again:

Create a Database and create user name password,

postgres=# CREATE USER linuxfaq WITH PASSWORD 'thelinux';
CREATE ROLE

postgres=# CREATE DATABASE fedora OWNER linuxfaq;
CREATE DATABASE

Quit from postgres,

postgres=# \q


Configure PostgreSQL with PHP


Open your PHP configuration file php.ini then add extension "pgsql.so"
 
# vim /etc/php.ini
extension = "pgsql.so"


if you are working with windows system,
extension = php_pgsql.dll


Finally restart your webserver, 

How to remove postgresql

To remove everything:
 
#  yum erase postgresql94*