How To Install PostgreSQL 11 / 10 on CentOS 7 / RHEL 7

12

PostgreSQL is an object-relational database management system (ORDBMS) available for many platforms including Linux, FreeBSD, Solaris, Microsoft Windows, and Mac OS X. It is released under the PostgreSQL License, which is an MIT-style license, a free and open source software.

PostgreSQL is developed by the PostgreSQL Global Development Group, consisting of a handful of community volunteers employed and supervised by companies such as Red Hat and EnterpriseDB.

The vast majority of Linux distributions have PostgreSQL available in supplied packages.

Here is the tutorial about installing PostgreSQL 11 / 10 on CentOS 7 / RHEL 7.

Open  a terminal ( Applications >> System Tools >> Terminal).

Switch to the root user.

$ su -

Setup PostgreSQL repository

PostgreSQL publishes rpm packages for all Linux platforms, and their packages are fresher than those available in the OS repositories.

So, you need to add the repository to your machine by installing PostgreSQL repo rpm.

### PostgreSQL 11 ###

# RHEL 7 #

yum install -y https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-redhat11-11-2.noarch.rpm

# CentOS 7 #

yum install -y https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-centos11-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

# CentOS 7 #

yum install -y https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm

Install PostgreSQL 11 / 10 on CentOS 7 / 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//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

Output (PostgreSQL 11):

 postgresql-11.service - PostgreSQL 11 database server
   Loaded: loaded (/usr/lib/systemd/system/postgresql-11.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2019-02-22 09:49:01 EST; 17s ago
     Docs: https://www.postgresql.org/docs/11/static/
 Main PID: 1408 (postmaster)
   CGroup: /system.slice/postgresql-11.service
           ├─1408 /usr/pgsql-11/bin/postmaster -D /var/lib/pgsql/11/data/
           ├─1410 postgres: logger
           ├─1412 postgres: checkpointer
           ├─1413 postgres: background writer
           ├─1414 postgres: walwriter
           ├─1415 postgres: autovacuum launcher
           ├─1416 postgres: stats collector
           └─1417 postgres: logical replication launcher

Feb 22 09:49:01 server.holhol24.local systemd[1]: Starting PostgreSQL 11 database server...
Feb 22 09:49:01 server.holhol24.local postmaster[1408]: 2019-02-22 09:49:01.202 EST [1408] LOG:  listening on...432
Feb 22 09:49:01 server.holhol24.local postmaster[1408]: 2019-02-22 09:49:01.202 EST [1408] LOG:  listening on...432
Feb 22 09:49:01 server.holhol24.local postmaster[1408]: 2019-02-22 09:49:01.207 EST [1408] LOG:  listening on...32"
Feb 22 09:49:01 server.holhol24.local postmaster[1408]: 2019-02-22 09:49:01.213 EST [1408] LOG:  listening on...32"
Feb 22 09:49:01 server.holhol24.local postmaster[1408]: 2019-02-22 09:49:01.226 EST [1408] LOG:  redirecting ...ess
Feb 22 09:49:01 server.holhol24.local postmaster[1408]: 2019-02-22 09:49:01.226 EST [1408] HINT:  Future log ...g".
Feb 22 09:49:01 server.holhol24.local systemd[1]: Started PostgreSQL 11 database server.

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      1969/postmaster
tcp6       0      0 :::5432                 :::*                    LISTEN      1969/postmaster

READ: netstat command not found on CentOS 7 / RHEL 7 – Quick Fix

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

You have successfully installed the PostgreSQL 11 / 10 on CentOS 7 / RHEL 7.

That’s All.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More