Support Online
Skip to main content

Installing PostgreSQL: Step-by-Step Guide on Ubuntu 18.04

Meta Description: Learn step by step how to install PostgreSQL on Ubuntu 18.04, role management and basic SQL operations.

What will you learn in this guide?

In this content, you will install PostgreSQL on Ubuntu 18.04 server.
You will learn how to create roles, open a database and table management.
You will practice basic SQL commands with real examples.

🧠 Technical Summary

This guide describes the installation of PostgreSQL relational database server on Ubuntu 18.04 system.
The aim is to teach basic database management commands.
Additionally, ident authentication logic is explained.


1️⃣ PostgreSQL Installation

Update package list:

sudo apt update

This command refreshes the package list on the system.

Install PostgreSQL and additional tools:

sudo apt install postgresql postgresql-contrib

This command installs the PostgreSQL server and utilities.

Start the service:

sudo systemctl start postgresql.service

This command enables the database service to run.

To check service status:

sudo systemctl status postgresql

This command shows PostgreSQL service status.


2️⃣ Understanding PostgreSQL Role Logic

PostgreSQL uses the concept of role instead of user.
Default admin role: postgres

Switch to Postgres account:

sudo -i -u postgres

This command switches to the postgres system user.

Open the database shell:

psql

This command starts the PostgreSQL command line.

To log out:

\q

Alternative quick entry:

sudo -u postgres psql

This command directly opens the PostgreSQL interface.


3️⃣ Creating a New Role

Create interactive role:

sudo -u postgres createuser --interactive

This command creates a new PostgreSQL role.


4️⃣ Creating a New Database

Open new database:

sudo -u postgres createdb proje_db

This command creates a database with the specified name.


5️⃣ What is Ident Authentication?

PostgreSQL uses ident verification by default.
This system matches the Linux username and role name.

To create a new system user:

sudo adduser proje_kullanici

This command creates a new Linux user.


6️⃣ Creating a Table

CREATE TABLE ekipman (
id serial PRIMARY KEY,
ad varchar (50) NOT NULL,
renk varchar (25) NOT NULL,
konum varchar(25),
kurulum_tarihi date
);

This command creates the table named equipment.

To list tables:

\dt

This command shows the available tables.


7️⃣ Adding Data

INSERT INTO ekipman (ad, renk, konum, kurulum_tarihi)
VALUES ('salincak', 'kirmizi', 'kuzey', '2026-02-22');

This command adds a new record to the table.

View data:

SELECT * FROM ekipman;

This command lists all records.


8️⃣ Data Update

UPDATE ekipman SET renk = 'mavi' WHERE ad = 'salincak';

This command updates the existing record.


9️⃣ Delete Data

DELETE FROM ekipman WHERE ad = 'salincak';

This command deletes the relevant record.


Frequently Asked Questions (FAQ)

What is the PostgreSQL default port?

The default port is 5432.

How to restart PostgreSQL service?

sudo systemctl restart postgresql

This command restarts the service.

I'm getting Ident error, why?

The Linux username and role name may not match.

What does superuser do?

He has all the powers. Misuse is risky.

How do I list existing tables?

You can use the \dt command.


Result

With this guide, you have completed the PostgreSQL installation and basic management steps on Ubuntu 18.04.
You learned how to create roles, open a database and SQL operations.

If you want to run your PostgreSQL infrastructure in a scalable environment, you can create a server on the GenixNode platform in minutes.