0% found this document useful (0 votes)
154 views4 pages

Postgresql Installation Steps

This document provides instructions for installing PostgreSQL 9.4 on CentOS 6 and 7 using Yum. It describes how to add the PostgreSQL repository, install the postgresql94-server package, initialize the database, start the service, and access the PostgreSQL prompt. It also covers creating users and databases, setting passwords, and configuring the server to accept TCP/IP and MD5 encrypted connections.

Uploaded by

Dinesh Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
154 views4 pages

Postgresql Installation Steps

This document provides instructions for installing PostgreSQL 9.4 on CentOS 6 and 7 using Yum. It describes how to add the PostgreSQL repository, install the postgresql94-server package, initialize the database, start the service, and access the PostgreSQL prompt. It also covers creating users and databases, setting passwords, and configuring the server to accept TCP/IP and MD5 encrypted connections.

Uploaded by

Dinesh Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 4

Install Postgresql Using Yum

Install PostgreSQL
Go to the PostgreSQL repository download page, and add the PostgreSQL 9.4 repository depending
upon your server architecture.
For CentOS 6.x 32bit:
rpm -Uvh http://yum.postgresql.org/9.4/redhat/rhel-6-i386/pgdg-centos94-9.41.noarch.rpm
For CentOS 6.x 64bit:
rpm -Uvh http://yum.postgresql.org/9.4/redhat/rhel-6-x86_64/pgdg-centos94-9.41.noarch.rpm
For CentOS 7 64bit:
rpm
-Uvh
http://yum.postgresql.org/9.4/redhat/rhel-7-x86_64/pgdg-centos94-9.41.noarch.rpm

Update the repository list using command:


yum update

Now, Install postgresql with the following command:


yum install postgresql94-server postgresql94-contrib
Initialize postgresql database using following command:
On CentOS 6.x systems:
service postgresql-9.4 initdb
On CentOS 7 systems:
/usr/pgsql-9.4/bin/postgresql94-setup initdb

Then, start postgresql service and make it to start automatically on every reboot.
On CentOS 6.x systems:
service postgresql-9.4 start
chkconfig postgresql-9.4 on
On CentOS 7 systems:
systemctl enable postgresql-9.4
systemctl start postgresql-9.4

Access PostgreSQL command prompt


The default database name and database user are postgres. Switch to postgres user to perform
postgresql related operations:
su - postgres

To login to postgresql, enter the command:


psql

Sample Output:
psql (9.4.0)
Type "help" for help.
postgres=#

To exit from posgresql prompt, type \q following by quit to return back to the Terminal.

Set postgres user password


Login to postgresql prompt,
su - postgres
psql

.. and set postgres password with following command:


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

To install PostgreSQL Adminpack, enter the command in postgresql prompt:


postgres=# CREATE EXTENSION adminpack;
CREATE EXTENSION

Create New User and Database


For example, let us create a new user called senthil with password centos, and database called
mydb.
Switch to postgres user:
su - postgres

Create user senthil.


$ createuser senthil

Create database:
$ createdb mydb

Now, login to the psql prompt, and set password and Grant access to the database mydb for senthil:
$ psql
psql (9.4.0)
Type "help" for help.
postgres=# alter user senthil with encrypted password 'centos';
ALTER ROLE
postgres=# grant all privileges on database mydb to senthil;
GRANT
postgres=#

Delete Users and Databases


To delete the database, switch to postgres user:
su - postgres

Enter command:
$ dropdb <database-name>

To delete a user, enter the following command:


$ dropuser <user-name>

Configure PostgreSQL-MD5 Authentication


MD5 authentication requires the client to supply an MD5-encrypted password for authentication. To
do that, edit /opt/PostgreSQL/9.4/data/pg_hba.conf file:
vi /opt/PostgreSQL/9.4/data/pg_hba.conf

Add or Modify the lines as shown below


[...]
# 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
host all all 192.168.1.0/24 md5
# IPv6 local connections:
host all all ::1/128 md5
[...]

Restart postgresql service to apply the changes:

On CentOS 6.x systems:


service postgresql-9.4 restart
On CentOS 7 systems:
systemctl restart postgresql-9.4

Configure PostgreSQL-Configure TCP/IP


By default, TCP/IP connection is disabled, so that the users from another computers cant access
postgresql.
To
allow
to
connect
users
from
another
computers,
Edit
file
/opt/PostgreSQL/9.4/data/postgresql.conf:
vi /opt/PostgreSQL/9.4/data/postgresql.conf

Find the lines:


[...]
#listen_addresses = 'localhost'
[...]
#port = 5432
[...]

Uncomment both lines, and set the IP address of your postgresql server or set * to listen from all
clients as shown below:
listen_addresses = '*'
port = 5432

Restart postgresql service to save changes:


On CentOS 6.x systems:
/etc/init.d/postgresql-9.4 restart
On CentOS 7 systems:
systemctl restart postgresql-9.4

You might also like