Install PostgreSQL 15 on Centos 7 with Easy Steps – OrcaCore
In this guide, we want to teach you How To Install PostgreSQL 15 on Centos 7. PostgreSQL 15 contains many new features and enhancements, including:
- Improved sorting performance
- Enhanced compression capabilities
- Support for SQL/JSON path expressions
You can now proceed to the guide steps below on the Orcacore website to set up Install PostgreSQL 15 on Centos 7.
Steps To Install and Configure PostgreSQL 15 on Centos 7
To complete this guide, you must log in to your server as a non-root user with sudo privileges. To do this, you can follow our guide on Initial Server Setup with Centos 7.
1. Set up PostgreSQL 15 on Centos 7
To install Install PostgreSQL 15 on Centos 7, you must add the PostgreSQL 15 repository on your server. First, install Epel Repository on Centos 7 by using the command below:
sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
Then, install the required packages:
sudo yum install libzstd-devel
Add PostgreSQL 15 Repository on Centos 7
At this point, you can use the command below to add the latest PostgreSQL repository on your server:
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
Then, update your local package index with the following command:
sudo yum update -y
Install PostgreSQL 15 on Centos 7
First, you need to install Epel Repo
At this point, you can use the following command to Install PostgreSQL 15 on Centos 7:
sudo yum install -y postgresql15-server
When your installation is completed, verify it by checking its version:
psql -V
In your output you will see:

Initialize PostgreSQL 15 Database
At this point, you need to initialize the initdb
database which is responsible for creating a new PostgreSQL cluster
. A cluster is a group or collection of several databases that are managed by a cluster.
To do this, run the following command:
sudo /usr/pgsql-15/bin/postgresql-15-setup initdb
When it is finished, you will get the following output:
**Output**
Initializing database ... OK
2. Manage PostgreSQL 15 Service
At this point, you can start and enable your Install PostgreSQL 15 on Centos 7. To do this, run the commands below:
# sudo systemctl enable postgresql-15
# sudo systemctl start postgresql-15
Verify your PostgreSQL 15 is active and running on your server with the command below:
sudo systemctl status postgresql-15
3. Connect To PostgreSQL 15 Shell on Centos 7
PostgreSQL uses a concept called roles to handle authentication and authorization. During the PostgreSQL installation, Postgres is set up to use ident
authentication, meaning that it associates Postgres roles with a matching Unix/Linux system account.
If a role exists within Postgres, a Unix/Linux username with the same name is able to sign in as that role.
One way is to switch over to the Postgres account on your server by running the following command:
sudo -i -u postgres
**Output**
-bash-4.2$
You can access the Postgres 15 shell on Centos 7 by running the following command:
-bash-4.2$ psql
With this command, you will see that your shell prompt changes to:
**Output**
psql (15.0)
Type "help" for help.
postgres=#
To exit from the PostgreSQL 15 shell on Centos 7, run the following command:
postgres=# q
With this command, you will be back to the Postgres Linux command prompt.
-bash-4.2$
You can type exit to return to the regular system user.
-bash-4.2$
exit
Also, you can connect to your Postgres shell on Centos 7 in another way by typing the following command:
sudo -u postgres psql
In this way, you will directly connect to your PostgreSQL 15 shell.
**Output**
psql (15.0)
Type "help" for help.
postgres=#
Create a new PostgreSQL 15 Role
At this point, you can create a new Postgres role in two ways.
First, if you are logged in as a Postgres account, you can use the following command:
-bash-4.2$ createuser --interactive
Second, you can use sudo for each command without switching from your normal account on Centos 7:
sudo -u postgres createuser --interactive
Both ways will be asked to enter your role name and whether the new role is a superuser or not.
**Output**
Enter name of role to add: orca
Shall the new role be a superuser? (y/n) y
Create a new PostgreSQL 15 Database
The Postgres authentication system for any role used to log in, the role should have a database with the same name that it can access.
If you logged in as the Postgres account, run the following command to create the database with the name of the role you have created in the previous step:
-bash-4.2$ createdb orca
Or you can use sudo to create the database on Centos 7:
sudo -u postgres createdb orca
Open the Postgres 15 Shell with the new Role
At this point, you need to create a Linux user with the same name as your Postgres role and database. To do this, run the following command:
sudo adduser orca
Now you can connect to the Postgres database with the following commands:
# sudo -i -u orca
# orca@reita:~$ psql
Or you can use the following command instead:
sudo -u orca psql
**Output**
psql (15.0)
Type "help" for help.
orca=#
When you have logged in to your PostgreSQL database on Centos 7, you can check your current connection information by running the following command:
orca=# conninfo
In your output you will see:
**Output**
You are connected to database "orca" as user "orca" via socket in "/var/run/postgres
For more information, you can visit the PostgreSQL Documentation page.
Conclusion
At this point, you have learned to Install PostgreSQL 15 on Centos 7. Using PostgreSQL 15 on CentOS 7 provides improved performance, security, and advanced database features. It ensures better SQL compliance, efficient query execution, and long-term stability for enterprise applications.
Hope you enjoy it. You may also like these articles:
How To Upgrade Linux Kernel on Centos 7
How To Install and Use Yarn on Centos 7
Set up and Configure an SVN Server on Centos 7
Alternative Solutions for Installing PostgreSQL 15 on CentOS 7
While the provided method effectively installs PostgreSQL 15 using the official PostgreSQL yum repository, there are alternative approaches, each with its own advantages and disadvantages.
1. Using Docker to Install PostgreSQL 15 on Centos 7
Docker provides a containerization solution, allowing you to run PostgreSQL 15 in an isolated environment. This approach simplifies dependency management and avoids potential conflicts with existing system libraries.
Explanation:
Docker containers package an application with all its dependencies, libraries, and configuration files. This ensures consistency across different environments (development, testing, production). Using a Docker image for PostgreSQL 15 eliminates the need to manually install and configure the database server and its dependencies on CentOS 7.
Steps:
-
Install Docker: If Docker is not already installed, install it using the following commands:
sudo yum install -y yum-utils sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo sudo yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin sudo systemctl start docker sudo systemctl enable docker
-
Pull the PostgreSQL 15 Docker Image: Download the official PostgreSQL 15 image from Docker Hub:
sudo docker pull postgres:15
-
Run the PostgreSQL 15 Container: Create and start a container based on the image. This command maps port 5432 (the default PostgreSQL port) to port 5432 on the host machine, sets the
POSTGRES_PASSWORD
environment variable for the initial database password, and names the container "mypostgres15":sudo docker run --name mypostgres15 -e POSTGRES_PASSWORD=your_strong_password -p 5432:5432 -d postgres:15
-
Connect to PostgreSQL: You can now connect to the PostgreSQL 15 server running within the Docker container using any PostgreSQL client, such as
psql
, from your CentOS 7 host. Uselocalhost
or the server’s IP address and port 5432.psql -h localhost -U postgres -p 5432 -d postgres
You will be prompted for the password you set in the
POSTGRES_PASSWORD
environment variable.
Advantages:
- Isolation: The PostgreSQL instance is isolated from the host system, preventing dependency conflicts.
- Portability: The Docker image can be easily deployed on other systems with Docker installed.
- Simplified Management: Docker provides tools for managing the container lifecycle (start, stop, restart, etc.).
Disadvantages:
- Overhead: Docker introduces some overhead due to containerization.
- Learning Curve: Requires familiarity with Docker concepts and commands.
2. Building PostgreSQL 15 from Source to Install PostgreSQL 15 on Centos 7
Another approach is to download the PostgreSQL 15 source code and compile it directly on the CentOS 7 system. This method provides the most control over the installation process and allows for custom optimization.
Explanation:
Building from source involves downloading the raw source code of PostgreSQL, configuring the build process using ./configure
, compiling the code using make
, and then installing the compiled binaries using make install
. This allows you to tailor the installation to your specific system requirements and potentially optimize performance.
Steps:
-
Install Build Dependencies: Before building from source, you need to install the necessary build tools and libraries:
sudo yum install -y gcc make zlib-devel readline-devel openssl-devel pam-devel libxml2-devel libxslt-devel python3-devel
-
Download the Source Code: Download the PostgreSQL 15 source code from the official PostgreSQL website or a mirror. You can use
wget
:wget https://ftp.postgresql.org/pub/source/v15.0/postgresql-15.0.tar.gz tar -xvzf postgresql-15.0.tar.gz cd postgresql-15.0
-
Configure the Build: Run the
./configure
script to prepare the build environment. You can specify installation directories and enable/disable features. For a basic installation, you can use the default settings:./configure --prefix=/usr/local/pgsql15
The
--prefix
option specifies the installation directory. You can customize this to your preference. -
Compile the Code: Run
make
to compile the source code:make
This step may take a while, depending on your system’s processing power.
-
Install the Binaries: Run
make install
as root to install the compiled binaries to the specified installation directory:sudo make install
-
Initialize the Database: After installation, you need to initialize the database cluster. Create a user for the database and set the appropriate environment variables:
sudo useradd postgres sudo chown postgres /usr/local/pgsql15 sudo chown -R postgres /usr/local/pgsql15/data export PGDATA=/usr/local/pgsql15/data export PATH=$PATH:/usr/local/pgsql15/bin su - postgres -c "/usr/local/pgsql15/bin/initdb -D '$PGDATA'"
-
Start the Server: Finally, start the PostgreSQL server:
su - postgres -c "/usr/local/pgsql15/bin/pg_ctl -D '$PGDATA' -l logfile start"
Advantages:
- Customization: Full control over the build process and installation options.
- Optimization: Potential for performance optimization by tuning compiler flags.
- Latest Features: Access to the very latest features and bug fixes, even before they are available in pre-built packages.
Disadvantages:
- Complexity: Requires more technical expertise and manual configuration.
- Time-Consuming: The build process can take a significant amount of time.
- Dependency Management: You are responsible for managing all build dependencies.
In conclusion, while the original method using yum
is the easiest and most common way to Install PostgreSQL 15 on Centos 7, Docker and building from source offer alternative approaches with different tradeoffs. Docker provides isolation and portability, while building from source provides the most control and customization. The best method depends on your specific requirements and technical expertise.