Installing PostgreSQL on Oracle Linux 7

Published May 14, 2024, 6:11 a.m. by cloudblog

Installing postgresql on Oracle Linux 7.9

Step 1: Update the System Start by ensuring your Oracle Linux 7 system is up to date. 
Open a terminal and run the following commands: 
sudo yum update This command will update the package list and upgrade existing packages on your system. 

Step 2: Install PostgreSQL To install PostgreSQL on Oracle Linux 7, use the following command: 
sudo yum install postgresql-server postgresql15-contrib This command will 
install both the PostgreSQL server and additional contrib packages that 
provide useful extensions and utilities. Step 3: Initialize the PostgreSQL 
Database After the installation, initialize the PostgreSQL database cluster by running: 

sudo postgresql-setup initdb 
This command will create the necessary directory structure and configuration files for PostgreSQL. 

Step 4: Start and Enable PostgreSQL To start the PostgreSQL service and 

enable it to start automatically at boot, use these commands: sudo systemctl start postgresql 

sudo systemctl enablepostgresql Creating a PostgreSQL User and Database Let’s create a new 

PostgreSQL user and database. Replace your_user and your_password with your preferred values: 

sudo -u postgres createuser psqlblog 

sudo -u postgres createdb -O psqlblog psqlblog 

To illustrate PostgreSQL’s capabilities, let’s create a simple table in the newly created database.

 Access the PostgreSQL command-line tool, psql, using the following command: 
 
 sudo -u postgres psql -d your_database Once in the psql prompt, 
 
 execute the following SQL commands to create a basic table: 
 
 CREATE TABLE example ( id serial PRIMARY KEY, name VARCHAR (100), age INT ); 
 Managing the PostgreSQL Service To manage the PostgreSQL service on Oracle Linux 7, 
 you can use the following commands: • Start PostgreSQL service: sudo systemctl start postgresql •


sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
 Stop PostgreSQL service: sudo systemctl stop postgresql • Restart PostgreSQL service: sudo systemctl restart postgresql • 
Check PostgreSQL service status: sudo systemctl status postgresql

CREATE TABLESPACE psqlblog OWNER psqlblog LOCATION '/psql/dbs';
ALTER USER postgres WITH PASSWORD '******';

Share this post

Similar posts

There are no similar posts yet.

2 comments

Comment 1 by Cloudblog July 27, 2024, 12:46 p.m.

To update the postgresql version.

First, remove all the existing psql from the Linux machine.

$sudo yum remove postgresql\*
sudo rm /var/lib/pgsql.

Now, start the installation again with the latest release of PostgreSQL.

sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sudo yum install postgresql15-server postgresql15-contrib

Check the status of psql

systemctl list-units|grep PostgreSQL
cd /usr/lib/systemd/system/
service postgresql-15.service start
sudo status postgresql-15.service
sudo service status postgresql-15.service
sudo systemctl enable postgresql-15.service
psql --version

Comment 2 by Cloudblog July 27, 2024, 12:56 p.m.

To create a postgresql database follow the below steps:

1. service postgresql-15.service start
2. sudo systemctl enable postgresql-15.service
3. sudo -u postgres createuser psqlblog
4. sudo -u postgres createdb -O psqlblog psqlblog
5. sudo -u postgres psql -d psqlblog
CREATE TABLESPACE psqlblog OWNER psqlblog LOCATION '/psql/dbs';
ALTER USER postgres WITH PASSWORD '******';
In case when to start django and giving access issue please check the

[root@cloudblog data]# ls -ltr
total 72
drwx------. 2 postgres postgres 6 Feb 5 12:59 pg_twophase
drwx------. 2 postgres postgres 6 Feb 5 12:59 pg_stat_tmp
drwx------. 2 postgres postgres 6 Feb 5 12:59 pg_snapshots
drwx------. 2 postgres postgres 6 Feb 5 12:59 pg_serial
drwx------. 2 postgres postgres 6 Feb 5 12:59 pg_replslot
drwx------. 2 postgres postgres 6 Feb 5 12:59 pg_notify
drwx------. 4 postgres postgres 36 Feb 5 12:59 pg_multixact
drwx------. 2 postgres postgres 6 Feb 5 12:59 pg_dynshmem
drwx------. 2 postgres postgres 6 Feb 5 12:59 pg_commit_ts
-rw-------. 1 postgres postgres 3 Feb 5 12:59 PG_VERSION
-rw-------. 1 postgres postgres 88 Feb 5 12:59 postgresql.auto.conf
-rw-------. 1 postgres postgres 1636 Feb 5 12:59 pg_ident.conf
drwx------. 2 postgres postgres 18 Feb 5 12:59 pg_xact
drwx------. 2 postgres postgres 18 Feb 5 12:59 pg_subtrans
drwx------. 5 postgres postgres 33 Feb 5 12:59 base
drwx------. 2 postgres postgres 19 Feb 5 13:31 pg_tblspc
-rw-------. 1 postgres postgres 4566 Feb 5 13:37 pg_hba.conf
-rw-------. 1 postgres postgres 29455 Feb 5 13:38 postgresql.conf
drwx------. 2 postgres postgres 4096 Feb 11 00:00 log
drwx------. 3 postgres postgres 92 Mar 26 08:00 pg_wal
drwx------. 2 postgres postgres 4096 Jun 30 07:09 global
drwx------. 2 postgres postgres 6 Jul 18 05:33 pg_stat
-rw------- 1 postgres postgres 30 Jul 26 09:10 current_logfiles
-rw-------. 1 postgres postgres 58 Jul 26 09:10 postmaster.opts
drwx------. 4 postgres postgres 68 Jul 26 09:10 pg_logical
-rw------- 1 postgres postgres 95 Jul 26 09:10 postmaster.pid
[root@cloudblog data]#
[root@cloudblog data]# cat pg_hba.conf

# TYPE DATABASE USER ADDRESS METHOD

# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 0.0.0.0/0 md5

After changing the file will be able to start Django services.

Add a new comment