Updated May 4, 2023
Introduction to Install PostgreSQL
The following article provides an outline for installing PostgreSQL. PostgreSQL is an object-relational database management system; it is an open-source database management system not owned or controlled by any company or individual person. Online community developers and other volunteers manage it; PostgreSQL database software was first released in mid 1990. PostgreSQL database software was written in C language. PostgreSQL’s primary competitors are databases like MySQL, MSSQL, and Oracle DB; PostgreSQL supports 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 superuser privileges on MAC, UNIX, or Linux systems. To install it on windows, we need to have administrator privileges.
2. To install this on Windows, we must enable or configure 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. Below is an example of setting SELinux permissive in different environments.
- Before installing PostgreSQL, we need to set SELinux on permissive please find below the command for the same.
Code:
$ setenforce permissive
- After installing PostgreSQL, we need to set SELinux on enforcing mode; please find the below command.
Code:
$ Setenforce enforcing
6. We must 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 occurs in the middle, we must exit and update the OS version to the latest operating system version.
8. We need the PostgreSQL database’s RPM (Red hat package manager) to install on Linux-like systems.
9. We need to download PostgreSQL RPM packages from PostgreSQL’s official website.
Steps to Install PostgreSQL on CentOS
Let us discuss the procedure to install PostgreSQL in detail.
Step 1
We have been using CentOS version 7.7 to install PostgreSQL.
Below is the command to check the CentOS version:
Code:
# cat /etc/Redhat-release
Output:
Step 2
Edit the CentOS base repo (Repository file) to install PostgreSQL DB.
- We have been 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 used 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”.
Code:
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 must install the repository configuration package using the official PostgreSQL repository for CentOS.
Code:
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 the 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 want a PostgreSQL 11 version.
Code:
yum list PostgreSQL*
Output:
Step 5
Install PostgreSQL on CentOS by using the following command.
- We must install the PostgreSQL client and PostgreSQL server to install the PostgreSQL database.
- Also, we need to install the PostgreSQL libs package to resolve dependency to install the PostgreSQL DB server.
- To install 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.
Code:
yum install postgresql11-server
Output:
Step 6
After installation, we need to initialize the steps to create a new database cluster of the PostgreSQL database.
- We need to create a PostgreSQL database cluster before using the database.
- A PostgreSQL cluster is nothing but a collection of databases that are managed by a single server instance.
- Creating of database cluster will create a new physical file of the 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 as follows.
- The below command will initialize the database, and database files also initialize the administrative database.
Code:
/usr/pgsql-11/bin/postgresql-11-setup initdb
Output:
Step 7
We need to enable and start the PostgreSQL service using the systemctl command.
Code:
systemctl start postgresql-11
systemctl enable PostgreSQL-11
Output:
Step 8
Log in to the PostgreSQL database by using the default authentication method.
- The default PostgreSQL database uses roles to handle 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 users 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
We hope that this EDUCBA information on “Install PostgreSQL” was beneficial to you. You can view EDUCBA’s recommended articles for more information.