PostgreSQL is an open source object-relational, highly scalable, SQL compliant database management system. PostgreSQL, often simply Postgres, is an object-relational database management system (ORDBMS) with an emphasis on extensibility and standards compliance. As a database server, its primary functions are to store data securely and return that data in response to requests from other software applications. It can handle workloads ranging from small single-machine applications to large Internet-facing applications (or for data warehousing) with many concurrent users; on macOS Server, PostgreSQL is the default database; and it is also available for Microsoft Windows and Linux (supplied in most distributions).
. This article will help you to install PostgreSQL on CentOS, RHEL and Fedora Systems.
Add PostgreSQL Yum Repository
The first step is to install PostgreSQL repository in your system, Use one of below commands as per your system architecture and operating system.
CentOS/ 7 ###
rpm -Uvh https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm
CentOS/ 6 ###
rpm -Uvh https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-6-x86_64/pgdg-centos10-10-2.noarch.rpm
Fedora 27 ###
rpm -Uvh https://download.postgresql.org/pub/repos/yum/10/fedora/fedora-27-x86_64/pgdg-fedora10-10-4.noarch.rpm
Fedora 28 ###
rpm -Uvh https://download.postgresql.org/pub/repos/yum/10/fedora/fedora-28-x86_64/pgdg-fedora10-10-4.noarch.rpm
Installing PostgreSQL Server
After enabling PostgreSQL yum repository in your system use following command to install PostgreSQL 10 on your system with yum package manager.
yum install postgresql10-server postgresql10
Initializing PGDATA
After installing PostgreSQL server, It’s required to initialize it before using the first time. To initialize database use below command. /usr/pgsql-10/bin/postgresql-10-setup initdb
[root@iptables-server ~]# /usr/pgsql-10/bin/postgresql-10-setup initdb Initializing database ... OK
Above command will initialize PostgreSQL first time. PGDATA environment variable contains the path of the data directory.
PostgreSQL data directory Path is : /var/lib/pgsql/10/data/
[root@iptables-server ~]# ls /var/lib/pgsql/10/data/ -altr total 52 drwx------. 4 postgres postgres 51 Jul 15 17:33 .. -rw-------. 1 postgres postgres 3 Jul 15 17:33 PG_VERSION drwx------. 2 postgres postgres 6 Jul 15 17:33 pg_twophase drwx------. 2 postgres postgres 6 Jul 15 17:33 pg_tblspc drwx------. 2 postgres postgres 6 Jul 15 17:33 pg_stat_tmp drwx------. 2 postgres postgres 6 Jul 15 17:33 pg_stat drwx------. 2 postgres postgres 6 Jul 15 17:33 pg_snapshots drwx------. 2 postgres postgres 6 Jul 15 17:33 pg_serial drwx------. 2 postgres postgres 6 Jul 15 17:33 pg_replslot drwx------. 4 postgres postgres 36 Jul 15 17:33 pg_multixact drwx------. 2 postgres postgres 6 Jul 15 17:33 pg_dynshmem drwx------. 2 postgres postgres 6 Jul 15 17:33 pg_commit_ts -rw-------. 1 postgres postgres 22775 Jul 15 17:33 postgresql.conf -rw-------. 1 postgres postgres 88 Jul 15 17:33 postgresql.auto.conf -rw-------. 1 postgres postgres 1636 Jul 15 17:33 pg_ident.conf -rw-------. 1 postgres postgres 4269 Jul 15 17:33 pg_hba.conf drwx------. 2 postgres postgres 18 Jul 15 17:33 pg_xact drwx------. 3 postgres postgres 60 Jul 15 17:33 pg_wal drwx------. 2 postgres postgres 18 Jul 15 17:33 pg_subtrans drwx------. 2 postgres postgres 18 Jul 15 17:33 pg_notify drwx------. 2 postgres postgres 4096 Jul 15 17:33 global drwx------. 5 postgres postgres 41 Jul 15 17:33 base drwx------. 4 postgres postgres 68 Jul 15 17:33 pg_logical drwx------. 2 postgres postgres 6 Jul 15 17:33 log
Start / Enable PostgreSQL Server
To start PostgreSQL service using the following command as per your operating systems. Also, enable PostgreSQL service to autostart on system boot.
For CentOS/RHEL 7 and Fedora
systemctl start postgresql-10 systemctl enable postgresql-10
For CentOS/RHEL 6
service postgresql-10 start chkconfig postgresql-10 on
Check and Verify PostgreSQL Installation
After the above steps, your setup of Postgresql 10 server is ready , Let’s log in to verify that installation completed successfully.
su - postgres
Use psql command to access PostgreSQL prompt with admin privileges.
[root@iptables-server ~]# su - postgres -bash-4.2$ psql psql (10.4) Type "help" for help. postgres=#
You may create password for user postgres
postgres=#\ password postgres
Congratulation you PostgreSQL installation Server is completed
Please share .