Skip to content

RootDBA

DBA expertise: PostgreSQL, SQL Server & MySQL

Menu
  • Home
  • blog
  • PostgreSql
  • MySql
  • Sql Server
  • About AHMED – Root DBA
Menu

Installing PostgreSQL on linux

Posted on August 31, 2025September 1, 2025 by AHMED

 

Downloading package

In the realm of Red Hat, we employ RPMs (Red Hat Package Manager) as a fundamental tool. RPM files serve as the architects of software repositories, facilitating the seamless installation of software packages. The process unfolds as follows:

  1. Selecting the Operating System (OS) Version: This step is akin to choosing the foundation upon which our digital infrastructure will be built.

  2. Utilizing the Yum Repository Method: We opt for the Yum repository method, a robust approach akin to gaining access to a comprehensive software library.

  3. PostgreSQL Version Selection: A pivotal decision arises as we must specify the PostgreSQL version. For our purposes, let’s opt for PostgreSQL version 12.
    7970a78fbc57bc37665e1a6bab887e3f.png
    490270343ca731794e5a442c8ea24f11.png
    use the below command wget to download file directory from website
    wget [link to download ]
    wget [https://yum.postgresql.org/packages/#pg12]
    or use the below script which you can get from website its self

sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm sudo dnf -qy module disable postgresql sudo dnf install -y postgresql12-server sudo /usr/pgsql-12/bin/postgresql-12-setup initdb sudo systemctl enable postgresql-12 sudo systemctl start postgresql-12

  • on the script you will download rpm repo package

  • disable the PostgreSQL module available on redhat (only redhat)

  • sudo dnf -qy module disable postgresql This command ensures that the PostgreSQL module will not be active or installed on the system. It can be useful when you want to prevent the installation or use of a specific PostgreSQL module or version

  • /usr/pgsql-12/bin/postgresql-12-setup: This part of the command specifies the path to the PostgreSQL version 12 setup utility. It’s a script or program responsible for configuring and managing various aspects of PostgreSQL, including initializing the database cluster.

  • initdb: The "initdb" command is short for “initialize database.” When executed, it creates a new PostgreSQL database cluster, which is the core directory structure and configuration files required to run a PostgreSQL instance. It sets up the essential components and directory structure for a fresh database installation.
    In summary, the provided command, “sudo /usr/pgsql-12/bin/postgresql

  • setup initdb,” is used to initialize a PostgreSQL version 12 database cluster on the system with elevated privileges, creating the necessary infrastructure for PostgreSQL to operate effectively.
    21cc8b2efda798542920f28fa6302a55.png

additional package we need to install postgree-contrib , this will include all additional features

to locate this the syntax for package use yum list postgresql12*
9f1a6c51a8d86259e011687b6e098483.png
b46dbd3d758efca270571f1e1b396888.png
ccf2b47349a922989672ce20af6faaef.png

configuring PostgreSQL post installation

During the installation of PostgreSQL on a Linux system, you may have noticed that the installation process lacks certain user interactions that are typically associated with software installations. Unlike some other software, PostgreSQL installation on Linux doesn’t ask you for important details such as the data directory, installation directory, port number, or even the PostgreSQL password.

installation and data directory in Linux

the installation directory will be in usr/pgsql-12/bin/
bd2f21f13af962e89a5d0f44e115d04f.png
the data directory will be locating in /var/lib/pgsql/

create superuser for PostgreSQL

to check the superuser for PostgreSQL is configured
type su - postgres
if it dint ask you for password means the password was not setup for PostgreSQL
6a1483245d80d914816e645d8929dec4.png

 

you cannot login to PostgreSQL using normal only root can access
then once you login just Chang the password using passwd command using the root user

make sure the services are running

make sure the below command is installed

sudo systemctl enable postgresql-12 sudo systemctl start postgresql-12

setup environment variables

first login using postgres user

the use VIM to edit the

2b9d24ce9c8f9338270f0dcd49aa1802.png
the installer has already specify the pgdata path for the user

e4df893752a4b16f3c43d3488995ab75.png
you just need to specify the path for binary to be used by user
PATH=$PATH:HOME/BIN export PATH export PATH=/usr/pgsql-12/bin:$PATH
584e43fda930e0fbf9e383173285aa56.png
when you want to use deterrent user then you will have to edit environment path for that user to .

 

0
Visited 27 times, 1 visit(s) today
Category: PostgreSql

Post navigation

database cluster in PostgreSql →
© 2025 RootDBA | Powered by Minimalist Blog WordPress Theme