Hamsa K
Editor
4 min read | 5 years ago

Install PostgreSQL 11 on centos 7

How to install Postgresql 11 on centos 7/8

PostgreSQL or Postgres is an open source general-purpose object-relational database management system with many advanced features which allows you to create complex web applications.

PostgreSQL (Postgres) allows users to create unique operators, complex data types, aggregate functions, data type conversion character, and other various database objects through the SQL function.

In this post, we will see how to install PostgreSql on Centos 7

step 1: Add postgresql yum repository

rpm -Uvh https://yum.postgresql.org/11/redhat/rhel-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

For more information visit PostgreSQL repositories url where you can get repository package rpm for diffrent operating systems.

step2: Install postgresql

# yum install postgresql11-server

This will also install some additional required packages on your system.

step 3: Initialize the database by running the following command

[root@lampblogs ~]# /usr/pgsql-11/bin/postgresql-11-setup initdb
Initializing database ... OK

PostgreSQL 11 default data directory location is /var/lib/pgsql/11/data

step 4: start and enable postgresql service 

[root@lampblogs ~]# systemctl start postgresql-11.service
[root@lampblogs ~]# systemctl enable postgresql-11.service

step 5: verify postgresql installtion

To verify the installation we will try to connect to the PostgreSQL database server using the psql tool 

The default database name and database user are 'postgres'. Switch to postgres user to perform postgresql related operations and login to postgresql

[root@lampblogs ~]# su - postgres
# To login to postgresql, enter the command psql
-bash-4.2$ psql
psql (11.3)
Type "help" for help.
postgres=#

You may create a password for user postgres for security purpose.

postgres-# \password postgres

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

step 6: Adjust Iptables/Firewall

firewall-cmd --permanent --add-port=5432/tcp
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --reload

If you have selinux enabled in your system run following command.

setsebool -P httpd_can_network_connect_db 1

Now you have successfully installed the PostgreSQL database server on CentOS 7/RHEL 7 server.

 



Warning! This site uses cookies
By continuing to browse the site, you are agreeing to our use of cookies. Read our terms and privacy policy