You are on page 1of 4

Setup PostgreSQL repository

# RHEL 7 #

yum install -y https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86


_64/pgdg-redhat11-11-2.noarch.rpm

### PostgreSQL 10 ###

# RHEL 7 #

yum install -y https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86


_64/pgdg-redhat10-10-2.noarch.rpm

Install PostgreSQL 11 / 10 RHEL 7


Install PostgreSQL 11 / 10 using yum command.

### PostgreSQL 11 ###

yum install -y postgresql11-server postgresql11

### PostgreSQL 10 ###

yum install -y postgresql10-server postgresql10

Initialize PostgreSQL Server


After installing PostgreSQL, you need to initialize it before using for the first time.

### PostgreSQL 11 ###

/usr/pgsql-11/bin/postgresql-11-setup initdb

### PostgreSQL 10 ###

/usr/pgsql-10/bin/postgresql-10-setup initdb
PostgreSQL data is typically found /var/lib/pgsql/<version>/data/ directory.

Control PostgreSQL Service


To start PostgreSQL service, run:

### PostgreSQL 11 ###

systemctl start postgresql-11

### PostgreSQL 10 ###

systemctl start postgresql-10


To enable PostgreSQL on system startup, run:

### PostgreSQL 11 ###

systemctl enable postgresql-11

### PostgreSQL 10 ###

systemctl enable postgresql-10

To check the status of PostgreSQL service, run:

### PostgreSQL 11 ###

systemctl status postgresql-11

### PostgreSQL 10 ###

systemctl status postgresql-10

Configure PostgreSQL Server


By default, PostgreSQL listens on localhost which means you can access the database from
the server itself and won’t be able to connect to the database from outside network.

To enable the database service access for external machines, edit the configuration file.

### PostgreSQL 11 ###

vi /var/lib/pgsql/11/data/postgresql.conf
### PostgreSQL 10 ###

vi /var/lib/pgsql/10/data/postgresql.conf
Set the listen_addresses to *.

listen_addresses = '*'
Restart PostgreSQL service.

### PostgreSQL 11 ###

systemctl restart postgresql-11

### PostgreSQL 10 ###

systemctl restart postgresql-10


Confirm the PostgreSQL listening on port 5432 using netstat command.

netstat -antup | grep 5432


Output:

tcp 0 0 0.0.0.0:5432 0.0.0.0:* LISTEN 1


969/postmaster
tcp6 0 0 :::5432 :::* LISTEN 1
969/postmaster

Access PostgreSQL server

To create a database, log in as postgres (Linux user). Login from the root user or reset
the password of postgres user for login.

# su -l postgres
Access the database using the psql command. It is an interactive front-end terminal for
PostgreSQL database.

$ psql
Output:

-bash-4.2$ psql
psql (11.2)
Type "help" for help.

postgres=#
Set password for postgres (Database administrator) user.
postgres=# \password

The PostgreSQL community runs a blog-aggregation service called


Planet
PostgreSQL (planet.postgresql.org). Several PostgreSQL developers and
companies use this service to share their experience and knowledge.

You might also like