How to Install POSTGRESQL ubuntu 23.04 and 23.10

thelinuxterminal

Author - Sanjay

Introduction

In this article , we will walk you through the process of installing and setting up a PostgreSQL database on Ubuntu 23.04 and Ubuntu 23.10. PostgreSQL, often referred to as Postgres, is a powerful, open-source object-relational database system known for its reliability, robustness, and extensibility .

By the end of this article, you'll have a fully functional PostgreSQL database running on your Ubuntu 23.04 system or Ubuntu 23.10 server, ready to store and manage your data efficiently.

Table of Contents

Pre-Requisistes

A Ubuntu 23.04 or an Ubuntu 23.10 production server or a fully managed DigitalOcean Instance .

  • Ubuntu 23.04 installed on your server or desktop.
  • A user account with sudo privileges.
Also Read
  1. Grep Command Example Linux
  2. Secure Your Apache Web Server on UNIX / Linux
  3. Install and Configure Nginx On Rocky Linux 8
  4. How to Setup an Amazon LightSail Instance
  5. How to install Kali Linux on a clean hard drive

Step-by-Step Installation Guide

Let's get started with the installation of PostgreSQL on your Ubuntu 23.04 system.

Step 1: Update Your System

Lets start and ensure our system is up to date by running the following command:

sudo apt update && sudo apt upgrade
Output :-

System Update Ubuntu 23.10

Step 2: Installing PostgreSQL

Now , lets go ahead and run the command from our terminal as shown below . This will install actuall postgresql in our ubuntu machine.

sudo apt install postgresql postgresql-contrib
Output :-

Installing Postgresql Ubuntu 23.10

Do You Want to Continue - > Y

Step 3: Starting and verifying PostgreSQL Service

Now once above step is compleetd lets verify if the postgres service is running or not .

Execute all the commands in sequence , you should see something below at the end of last command .

sudo systemctl start postgresql
sudo systemctl enable postgresql
sudo systemctl status postgresql
Output :-

Verify Postgresql Service

Few Additional Commands which would help you are as below :

sudo systemctl is-active postgresql
sudo systemctl is-enabled postgresql

You can execute these to get the status in the form of text .

Step 4: Connect to Postgres

Now that you have installed and started postgres successfully , lets login to server

sudo -i -u postgres

This takes you to postgres user account which gets created by default in postgres . Postgres user is created by default once you install postgres . Above command switches the user to postgres user account .

Postgress Account Access

If you want to access postgres database from postgres shell , you need to execute below command . Once you execute the below command you will gain access to postgres database shell to execute database related commands .

psql
Output :-

Postgress SHell Access

Now you can enter below command to exit from postgres ,

postgres=# \q

Step 5 - Create User Role

We need to change to default postgres role , then we can follow these step.

sudo -u postgres createuser --interactive

Execute this command by coming out of the postgres user account , you can enter exit , which will logout from the postgres user account.

Output

Postgress Role

Step 6 : Securing PostgreSQL

By default, PostgreSQL is configured to be secure. However, you should set a password for the database superuser 'postgres':

sudo -u postgres psql

postgres=# password postgres

Step 7: Creating a Database

You can create a new database using the following command for postgres role .

postgres=# CREATE DATABASE thelinuxterminal;

Postgress Create DB

Now , once you have coreated , if you want to connect to database .

Postgress Connect DB

Conclusion

In this article, we've guided you through the process of installing and setting up PostgreSQL on your Ubuntu 23.04 and Ubuntu 23.10 system. PostgreSQL's reliability, scalability, and robust features make it an excellent choice for a wide range of applications.

If you have any questions or encounter issues, feel free to refer to the PostgreSQL documentation or seek assistance from the active PostgreSQL community