Support Online
Skip to main content

PostgreSQL installation

What will you learn in this guide?

This guide explains how to install PostgreSQL on Rocky Linux 9.
You see role management and ident verification in practice.
You create a table, add, update and delete data.

Technical Summary

Main topic: Installing and using basic PostgreSQL on Rocky Linux 9.
Solved problem: Quickly establishing a standard SQL environment suitable for production.
Steps: Installation → initdb → service → role → database → table → CRUD.


1. PostgreSQL installation

PostgreSQL is installed from the default repositories.
An additional package is recommended for language support.

sudo dnf install postgresql-server glibc-all-langpacks
  • This command installs the PostgreSQL server and language packs.

Note: Rocky Linux 9 mostly ships with PostgreSQL 13.


2. Starting a database cluster

  1. The cluster must be created before PostgreSQL starts.
  • This process prepares the data directory and system tables.

sudo postgresql-setup --initdb
  • This command initializes the database cluster.

Start the service:


sudo systemctl start postgresql

  • Start automatically at server startup:

sudo systemctl enable postgresql
  • This command starts the services and makes them persistent.

3. Roles and ident verification logic

  1. PostgreSQL manages the user with the concept of "role".
  2. Identity verification is common in the default installation.
  3. This maps the Linux username to the Postgres role.

4. Login to PostgreSQL shell

  1. There are two fast ways.

Path A: switching to postgres user


sudo -i -u postgres
psql
  • This command opens the psql console.

Path B: single command login


sudo -u postgres psql
  • This command opens psql without opening an intermediate shell.

For exit:


\q

Alternative output:


Ctrl+D

5. Create a new role

  1. You can create the new role interactively.

sudo -u postgres createuser --interactive
  • This command asks for the role name and permissions.

Example:

Role: sammy

Authority: superuser (available for testing)


6. Creating a new database

  1. Generally, a database with the same name as the role is created.

sudo -u postgres createdb sammy
  • This command creates the sammy database.

7. Connect with new role

  1. If you use Ident, Linux user is also required.

sudo adduser sammy
  • This command opens the sammy user in the system.

Link:


sudo -u sammy psql

  • Check connection information:

\conninfo
  • This command shows the active user and database.

8. Creating and listing tables

Let's create an example table.


CREATE TABLE park_ekipman (
id serial PRIMARY KEY,
tur varchar(50) NOT NULL,
renk varchar(25) NOT NULL,
konum varchar(25)
);
  • This command creates the table that tracks parking equipment.

Listing tables and objects:


\d

Listing only tables:


\dt

9. Add, read, update, delete data

  1. Add data:

INSERT INTO park_ekipman (tur, renk, konum)
VALUES ('kaydirak', 'mavi', 'guney');
  • This command adds a record to the table.

Take all records:


SELECT * FROM park_ekipman;
  • This command lists all lines.

Update:


UPDATE park_ekipman
SET renk = 'kirmizi'
WHERE tur = 'kaydirak';
  • This command changes the color of the matching record.

Delete:


DELETE FROM park_ekipman
WHERE tur = 'kaydirak';
  • This command deletes the matching line.

Frequently Asked Questions (FAQ)

1. What is identity validation? Maps the Linux username to the Postgres role.

2. How do I exit psql? Type \q or use Ctrl+D.

3. How do I list tables? \dt lists tables, \d makes them larger.

4. What is the PostgreSQL port? The default port is 5432.

5. Should I use the Superuser role in production? No, grant limited permissions in production.


Result

Now,

  • Running PostgreSQL on Rocky Linux 9.
  • You have established the role and database logic at a basic level.

The next step might be access and security settings.

You can try it now on the GenixNode platform to run PostgreSQL on high-performance servers.