Postgresql installation on redhat 7 and Postgresql 15

Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
  • User AvatarAshiwini
  • 09 Jul, 2024
  • 0 Comments
  • 2 Mins Read

Postgresql installation on redhat 7 and Postgresql 15

The Red Hat family of distributions includes:

  • Red Hat Enterprise Linux
  • Rocky Linux
  • AlmaLinux
  • CentOS (7 and 6 only)
  • Fedora
  • Oracle Linux

PostgreSQL is available on these platforms by default. However, each version of the platform normally “snapshots” a specific version of PostgreSQL that is then supported throughout the lifetime of this platform. Since this can often mean a different version than preferred, the PostgreSQL project provides a repository of packages of all supported versions for the most common distributions.

PostgreSQL Yum Repository

The PostgreSQL Yum Repository will integrate with your normal systems and patch management, and provide automatic updates for all supported versions of PostgreSQL throughout the support lifetime of PostgreSQL.

The PostgreSQL Yum Repository currently supports:

  • Red Hat Enterprise Linux
  • Rocky Linux
  • AlmaLinux
  • CentOS (7 and 6 only)
  • Oracle Linux
  • Fedora*

Note: due to the shorter support cycle on Fedora, all supported versions of PostgreSQL are not available on this platform. We do not recommend using Fedora for server deployments.

To use the PostgreSQL Yum Repository, follow these steps:

Postgresql installation on redhat 9 and Postgresql 15

Step 1: Update Your System

First, ensure that your system is up-to-date by running:

sudo dnf update -y
Step 2: Add the PostgreSQL Repository

PostgreSQL provides repositories for various versions. Add the PostgreSQL 15 repository to your system:

sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
Step 3: Install PostgreSQL 15

Now, install PostgreSQL 15:

sudo yum install -y postgresql15-server
Step 4: Create database directory and change ownerships

Initialize the PostgreSQL database with the following command:

sudo mkdir -p /home/postgres/data
sudo mkdir -p /home/postgres/wal
sudo chown -R postgres:postgres /home/postgres/data
sudo chown -R postgres:postgres /home/postgres/wal

sudo chmod 700 /home/postgres/data/
sudo chmod 700 /home/postgres/wal/
Step 5: Edit service file for custom DATA directory

Initialize the PostgreSQL database with the following command:

vi /usr/lib/systemd/system/postgresql-15.service

change the below line
Environment=PGDATA=/home/postgres/data/

Verify the changes
sudo systemctl cat postgresql-15.service
Restart the services
sudo systemctl daemon-reload
Step 6: Initialize the Database

Initialize the PostgreSQL database with the following command:

/usr/pgsql-15/bin/postgresql-15-setup initdb -D /home/postgres/data --waldir /home/postgres/wal
Step 7: Start and Enable PostgreSQL Service

Start the PostgreSQL service and enable it to start on boot:

sudo systemctl enable --now postgresql-15
sudo systemctl start postgresql-15
Step 8: Verify Installation

Verify that PostgreSQL is running:

sudo systemctl status postgresql-15

How to set bash profile

step 1:Open or Create the .bash_profile File

Open the .bash_profile file in your home directory using a text editor. If the file doesn’t exist, this command will create it:

nano ~/.bash_profile
step 2:Add Your Custom Configurations

You can add various configurations, such as environment variables, aliases, and function definitions. Here’s an example of what you might add:

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# User specific environment and startup programs

export PATH=/usr/pgsql-15/bin:$PATH
export PGDATA=/home/postgres/data

PATH=$PATH:$HOME/bin
export PS1="[\u@\h \W]\$ "
export PATH
step 3:Save and Close the File

If you are using nano, you can save the file by pressing Ctrl+O, then Enter, and exit by pressing Ctrl+X.

step 4:Apply the Changes

To apply the changes made to the .bash_profile, you need to source the file. This will load the new configurations into your current shell session:

source ~/.bash_profile
step 5:Verify the Changes

Verify that your changes have been applied. For instance, check the PATH variable or any aliases you set:

echo $PATH pgstatus