How To Install PostgreSQL 10 on CentOS 7

How To Install PostgreSQL 10 on CentOS 7

How To Install PostgreSQL 10 on CentOS 7 PostgreSQL is an open-source, object-relational database management system (ORDBMS). It is available for many platforms including Microsoft Windows, Linux, FreeBSD, Solaris, and Mac OS X.

PostgreSQL is developed by the PGDG (PostgreSQL Global Development Group), a group of corporates and individual contributors, released under PostgreSQL License.

Here is the post about installing PostgreSQL 10 on CentOS 7.

Add PostgreSQL Repository

PostgreSQL is available in the base repository, but it may be a bit older. So, you need to add the PostgreSQL repository on your machine by installing repo rpm.

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

Output:

Loaded plugins: fastestmirror
pgdg-centos10-10-2.noarch.rpm                                                            | 4.6 kB  00:00:00
Examining /var/tmp/yum-root-jPuuAN/pgdg-centos10-10-2.noarch.rpm: pgdg-centos10-10-2.noarch
Marking /var/tmp/yum-root-jPuuAN/pgdg-centos10-10-2.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package pgdg-centos10.noarch 0:10-2 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================================================
 Package                    Arch                Version           Repository                               Size
================================================================================================================
Installing:
 pgdg-centos10              noarch              10-2              /pgdg-centos10-10-2.noarch              2.7 k

Transaction Summary
================================================================================================================
Install  1 Package

Total size: 2.7 k
Installed size: 2.7 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : pgdg-centos10-10-2.noarch                                                                    1/1
  Verifying  : pgdg-centos10-10-2.noarch                                                                    1/1

Installed:
  pgdg-centos10.noarch 0:10-2

Complete!

Install PostgreSQL 10

Install PostgreSQL 10 using yum command.

yum install -y postgresql10-server postgresql10

Output:

Loaded plugins: fastestmirror
Determining fastest mirrors
 * base: mirror.nbrc.ac.in
 * extras: mirror.nbrc.ac.in
 * updates: mirror.nbrc.ac.in
base                                                                                     | 3.6 kB  00:00:00
extras                                                                                   | 3.4 kB  00:00:00
pgdg10                                                                                   | 4.1 kB  00:00:00
updates                                                                                  | 3.4 kB  00:00:00
(1/6): base/7/x86_64/group_gz                                                            | 166 kB  00:00:01
(2/6): extras/7/x86_64/primary_db                                                        | 187 kB  00:00:01
(3/6): pgdg10/7/x86_64/group_gz                                                          |  245 B  00:00:01
(4/6): pgdg10/7/x86_64/primary_db                                                        | 188 kB  00:00:03
(5/6): base/7/x86_64/primary_db                                                          | 6.0 MB  00:00:07
(6/6): updates/7/x86_64/primary_db                                                       | 3.4 MB  00:00:07
Resolving Dependencies
--> Running transaction check
---> Package postgresql10.x86_64 0:10.7-2PGDG.rhel7 will be installed
--> Processing Dependency: postgresql10-libs(x86-64) = 10.7-2PGDG.rhel7 for package: postgresql10-10.7-2PGDG.rhel7.x86_64
--> Processing Dependency: libicu for package: postgresql10-10.7-2PGDG.rhel7.x86_64
--> Processing Dependency: libpq.so.5()(64bit) for package: postgresql10-10.7-2PGDG.rhel7.x86_64
---> Package postgresql10-server.x86_64 0:10.7-2PGDG.rhel7 will be installed
--> Running transaction check
---> Package libicu.x86_64 0:50.1.2-17.el7 will be installed
---> Package postgresql10-libs.x86_64 0:10.7-2PGDG.rhel7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================================================
 Package                          Arch                Version                         Repository           Size
================================================================================================================
Installing:
 postgresql10                     x86_64              10.7-2PGDG.rhel7                pgdg10              1.6 M
 postgresql10-server              x86_64              10.7-2PGDG.rhel7                pgdg10              4.5 M
Installing for dependencies:
 libicu                           x86_64              50.1.2-17.el7                   base                6.9 M
 postgresql10-libs                x86_64              10.7-2PGDG.rhel7                pgdg10              355 k

Transaction Summary
================================================================================================================
Install  2 Packages (+2 Dependent packages)

Total download size: 13 M
Installed size: 52 M
Downloading packages:
(1/4): postgresql10-libs-10.7-2PGDG.rhel7.x86_64.rpm                                     | 355 kB  00:00:02
(2/4): postgresql10-10.7-2PGDG.rhel7.x86_64.rpm                                          | 1.6 MB  00:00:04
(3/4): postgresql10-server-10.7-2PGDG.rhel7.x86_64.rpm                                   | 4.5 MB  00:00:03
(4/4): libicu-50.1.2-17.el7.x86_64.rpm                                                   | 6.9 MB  00:00:08
----------------------------------------------------------------------------------------------------------------
Total                                                                           1.6 MB/s |  13 MB  00:00:08
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : libicu-50.1.2-17.el7.x86_64                                                                  1/4
  Installing : postgresql10-libs-10.7-2PGDG.rhel7.x86_64                                                    2/4
  Installing : postgresql10-10.7-2PGDG.rhel7.x86_64                                                         3/4
  Installing : postgresql10-server-10.7-2PGDG.rhel7.x86_64                                                  4/4
  Verifying  : postgresql10-server-10.7-2PGDG.rhel7.x86_64                                                  1/4
  Verifying  : postgresql10-10.7-2PGDG.rhel7.x86_64                                                         2/4
  Verifying  : postgresql10-libs-10.7-2PGDG.rhel7.x86_64                                                    3/4
  Verifying  : libicu-50.1.2-17.el7.x86_64                                                                  4/4

Installed:
  postgresql10.x86_64 0:10.7-2PGDG.rhel7              postgresql10-server.x86_64 0:10.7-2PGDG.rhel7

Dependency Installed:
  libicu.x86_64 0:50.1.2-17.el7                   postgresql10-libs.x86_64 0:10.7-2PGDG.rhel7

Complete!

Initialize PostgreSQL server

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

/usr/pgsql-10/bin/postgresql-10-setup initdb
Output
Initializing database ... OK

PostgreSQL data is can be found /var/lib/pgsql/10/data/ directory.

Start PostgreSQL server

To start PostgreSQL service, run:

systemctl start postgresql-10

To enable PostgreSQL on system startup, run:

systemctl enable postgresql-10

To check the status of PostgreSQL, run:

systemctl status postgresql-10
Output
● postgresql-10.service - PostgreSQL 10 database server Loaded: loaded (/usr/lib/systemd/system/postgresql-10.service; enabled; vendor preset: disabled) Active: active (running) since Mon 2019-04-15 02:48:04 EDT; 8s ago Docs: https://www.postgresql.org/docs/10/static/ Main PID: 1341 (postmaster) CGroup: /system.slice/postgresql-10.service ├─1341 /usr/pgsql-10/bin/postmaster -D /var/lib/pgsql/10/data/ ├─1343 postgres: logger process ├─1345 postgres: checkpointer process ├─1346 postgres: writer process ├─1347 postgres: wal writer process ├─1348 postgres: autovacuum launcher process ├─1349 postgres: stats collector process └─1350 postgres: bgworker: logical replication launcher

Apr 15 02:48:04 server.linuxbees.local systemd[1]: Starting PostgreSQL 10 database server… Apr 15 02:48:04 server.linuxbees.local postmaster[1341]: 2019-04-15 02:48:04.093 EDT [1341] LOG: listening …432 Apr 15 02:48:04 server.linuxbees.local postmaster[1341]: 2019-04-15 02:48:04.093 EDT [1341] LOG: listening …432 Apr 15 02:48:04 server.linuxbees.local postmaster[1341]: 2019-04-15 02:48:04.100 EDT [1341] LOG: listening …32” Apr 15 02:48:04 server.linuxbees.local postmaster[1341]: 2019-04-15 02:48:04.106 EDT [1341] LOG: listening …32” Apr 15 02:48:04 server.linuxbees.local postmaster[1341]: 2019-04-15 02:48:04.123 EDT [1341] LOG: redirectin…ess Apr 15 02:48:04 server.linuxbees.local postmaster[1341]: 2019-04-15 02:48:04.123 EDT [1341] HINT: Future lo…g”. Apr 15 02:48:04 server.linuxbees.local systemd[1]: Started PostgreSQL 10 database server. Hint: Some lines were ellipsized, use -l to show in full.

Access PostgreSQL server

Log in as postgres user (Linux user) in case you want to create a database. Login from the root user (doesn’t need postgres user’s password) or reset the password of postgres user for login.

# su -l postgres

Access a database using the psql command, an interactive front-end terminal for PostgreSQL database.

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

postgres=#

Set password for postgres (Database administrator) user.

postgres=# \password

Conclusion

You have learned how to install the PostgreSQL 10 on CentOS 7. You can visit PostgreSQL’s official documentation to get started with PostgreSQL database.

comments powered by Disqus