Introduction to Install PostgreSQL
PostgreSQL is an object-relational database management system; it is an open-source database management system that is not owned or controlled by any one company or individual person, it is managed by online community developers also by other volunteers; PostgreSQL database software first released in the mid of 1990, PostgreSQL database software was written in C language, PostgreSQL primary competitors database like MySQL, MSSQL and Oracle DB, PostgreSQL was supporting all database feature and also support MVCC (Multi-version concurrency control) architecture.
Prerequisites for PostgreSQL installation
The following are the prerequisites for PostgreSQL.
1. PostgreSQL on windows; we need to have superuser privileges on MAC, UNIX or Linux system. To install it on windows, we need to have administrator privileges.
2. To install this on windows, we need to enabled or configured user account control (UAC).
3. We need to have superuser privileges to install it on Linux.
4. Before installing PostgreSQL on the system that we have run an SELinux, We must set it to SELinux on permissive mode.
5. Please find below the example to set SELinux permissive in different environments.
- Before installing PostgreSQL, we need to set SELinux on permissive please find below command for the same.
$ setenforce permissive
- After installing PostgreSQL, we need to set SELinux on enforcing mode; please find the below command.
$ Setenforce enforcing
6. We need to install xterm, Konsole or genome terminal before executing a console-based program by the PostgreSQL enterprise DB installer.
7. For the Windows operating system, we need to update the OS before installing PostgreSQL software. If an error occurred in the middle, we need to exit and update the OS version to the latest operating system version.
8. We need to have RPM (Red hat package manager) of the PostgreSQL database to install it on Linux like systems.
9. We need to have download PostgreSQL RPM packages from PostgreSQL official website.
Steps to Install PostgreSQL on CentOS
Let us discuss the procedure to install PostgreSQL in detail.
Step 1
We have using CentOS version 7.7 to install PostgreSQL.
Below is the command to check the CentOS version:
# cat /etc/Redhat-release
Output:
Step 2
Edit CentOS base repo (Repository file) to install PostgreSQL DB
- We have using the CentOS base repository to install PostgreSQL on CentOS. We need to exclude the search of PostgreSQL from the repository for installing it from the base repository.
- Then open the repository file using vi or vim; we have using vi to edit the below file.
- The file finds the base and updates section in the repository and inserts it by pressing “i” after opening and repository file.
- Then we need to insert “Exclude = PostgreSQL* in both sections after saving the file using ESC + “wq”.
vi /etc/yum.repos.d/CentOS-Base.repo
[base]
name = CentOS-$releasever - Base
mirrorlist =http://mirrorlist.centos.org/?release=$releasever&arch
=$basearch&repo=os&infra=$infra
baseurl = http://mirror.centos.org/centos/$releasever/os/$basearch/
Gpgcheck = 1
Gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Exclude = postgresql*
released updates
[updates]
Name = CentOS-$releasever - Updates
Mirrorlist = http://mirrorlist.centos.org/?release=$releasever&arch
=$basearch&repo=updates&infra=$infra
baseurl = http://mirror.centos.org/centos/$releasever/updates/$basearch/
Gpgcheck = 1
Gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Exclude = postgresql*
Output:
Step 3
Then we need to install the repository configuration package by using the official PostgreSQL repository for CentOS.
yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
After executing the above command, the process will prompt, then we confirm the installation by pressing key “Y”.
Output:
Step 4
Then we list all packages and versions by using the following command. It will show all the PostgreSQL desired versions. We desire a PostgreSQL 11 version.
yum list PostgreSQL*
Output:
Step 5
Install PostgreSQL on CentOS by using the following command.
- We need to install the PostgreSQL client and PostgreSQL server to install the PostgreSQL database.
- Also, we need to install the PostgreSQL libs package for resolving dependency to install the PostgreSQL DB server.
- For installing this, we need to install the below package as follows.
- Postgresql 11 server
- Postgresql 11
- Postgresql 11 libs
- PostgreSQL 11 and Postgresql 11 libs are dependency packages to install the PostgreSQL DB server.
yum install postgresql11-server
Output:
Step 6
After installation, we need to initialize steps to create a new database cluster of the PostgreSQL database.
- We need to create a PostgreSQL database cluster before using the database.
- PostgreSQL cluster is nothing but the collection of databases that was managed by a single server instance.
- Creating of database cluster will create a new physical file of data directory and database files.
- It will also create catalog tables and creates template 0, template 1 and Postgres database.
- Template 0 and template 1 database is used to create a new database for the user.
- Postgres database is a default database for connections of administrative users and application users.
- Below is the command to initialize the PostgreSQL database cluster are as follows.
- The below command will initialize the database, and database files also initialize the administrative database.
/usr/pgsql-11/bin/postgresql-11-setup initdb
Output:
Step 7
Now we need to enable and start the PostgreSQL service by using systemctl command.
systemctl start postgresql-11
systemctl enable PostgreSQL-11
Output:
Step 8
Log in to the PostgreSQL database by using the default authentication method.
- Default PostgreSQL database uses roles to handle the authentication and authorization.
- It default uses an ident authentication method to authenticate the database with users.
- It will manage OS authentication with database users.
- The procedure creates OS level and DB level user by default; it will access the database the first time with the ident authentication method.
- Below is the authentication method available in PostgreSQL.
- MD5
- Ident
- Peer
- LDAP
- Trust
- Kerberos
- Below is the process to access the PostgreSQL database for the first time.
Conclusion
It is an open-source database management system. It is also an object-relational database management system. A single company or person does not manage the PostgreSQL database; it has managed by community developers or other volunteers. It is most popular in the relational database management system.
Recommended Articles
This is a guide to Install PostgreSQL. Here we discuss Prerequisites and Steps to Install PostgreSQL on CentOS along with appropriate examples. You can also go through our other suggested articles to learn more –