segunda-feira, 17 de novembro de 2014

Install PostgreSQL 9.3 on CentOS 7



Open Terminal ( Applications —> System Tools —> Terminal).
Switch to root user.
[raj@itzgeek~/]$ su -

Dependency:

rpm -Uvh ftp://ftp.muug.mb.ca/mirror/centos/7.0.1406/os/x86_64/Packages/uuid-1.6.2-26.el7.x86_64.rpm

Install PosgreSQL 9.1.3:

PostgreSQL publishes rpm packages for all Linux platforms, their packages are generally fresher than those in the other repository. We need to add the repository on our machine by installing repo rpm.
[root@itzgeek~/]# rpm -Uvh http://yum.postgresql.org/9.3/redhat/rhel-7-x86_64/pgdg-centos93-9.3-1.noarch.rpm
Install PostgreSQL 9.3.1 , enable only PostgreSQL repository to install.
[root@itzgeek~/]#  yum install postgresql93 postgresql93-server postgresql93-libs postgresql93-contrib postgresql93-devel --disablerepo=* --enablerepo=pgdg93

Configuring PostgreSQL 9.3.1 server:

Initialize the PostgreSQL.
[root@itzgeek~/]# /usr/pgsql-9.3/bin/postgresql93-setup initdb
PostgreSQL normally listens on the localhosts only, if would you like to enable the PostgreSQL to listen on all ip addresses; edit the /var/lib/pgsql/9.1/data/postgresql.conf .
[root@itzgeek~/]# vi /var/lib/pgsql/9.3/data/postgresql.conf
Go to Connections and Communications section, find the "listen_address" variable. Uncomment the "listen_addresses" and place "*" instead of "localhost"
Before editing:
#listen_addresses = "localhost"
After editing:
listen_addresses = "*"
Add your network to access database remotely; Edit  /var/lib/pgsql/9.3/data/pg_hba.conf.
[root@itzgeek~/]#  vi /var/lib/pgsql/9.3/data/pg_hba.conf
Add the following line according to your network configuration with md5 password authentication (Enable remote access of database).
# IPv4 local connections: host    all             all             127.0.0.1/32            md5 host    all             all             107.155.94.0/24         md5 # IPv6 local connections: host    all             all             ::1/128                 md5
Restart the PostgreSQL server.
[root@itzgeek~/]# systemctl start postgresql-9.3.service
Confirm the PostgreSQL listening.
[root@itzgeek ~/]# netstat -antup | grep 5432 tcp        0      0 0.0.0.0:5432            0.0.0.0:*               LISTEN      39620/postgres tcp6       0      0 :::5432                 :::*                    LISTEN      39620/postgres
Auto start the service on startup.
[root@itzgeek~/]# systemctl enable postgresql-9.3.service

Creating Database:

Login as postgres user.
[root@geeksite~/]$ su -l postgres
create the database called "test"
-bash-4.2$ createdb test
Login into the database.
-bash-4.2$ psql test
Create a new user called "raj" to manage the databases.
test=# CREATE USER raj WITH SUPERUSER LOGIN PASSWORD 'raj';
Login with the superuser.
sam@geeksite~/$ psql -h localhost -d test -U raj
That's all!. You have successfully installed the PostgreSQL 9.3 on CentOS 7 / RHEL 7.