Monday, September 29, 2025

Install ProgreSQL Ubuntu 22.04

Ref

  • https://g.co/gemini/share/d10d3ed58283

The easiest way to install the PostgreSQL database on Ubuntu 22.04 is by using the default Ubuntu repository, which is an extremely straightforward process.1

Here are the step-by-step instructions:

1. Update Package Index

First, update your local package list to ensure you have access to the latest versions:

Bash
sudo apt update

2. Install PostgreSQL2

Install the main PostgreSQL server package and the postgresql-contrib package, which adds useful extra utilities and extensions:3

Bash
sudo apt install postgresql postgresql-contrib -y

This command will install the latest version of PostgreSQL available in the Ubuntu 22.04 repository (typically version 14 or a later update). The installation process automatically starts the PostgreSQL service and sets it to start on boot.


3. Verify Installation and Service Status

You can check if the service is running correctly:

Bash
sudo systemctl status postgresql

The output should show Active: active (exited) or Active: active (running), confirming the service is active.


4. Connect to PostgreSQL4

By default, the installation creates a Unix user named postgres which is associated with the default PostgreSQL administrative role (also called postgres). You can log in as this user to manage the database.

To access the PostgreSQL prompt (psql):

  1. Switch to the postgres system user:

    Bash
    sudo -i -u postgres
    
  2. Access the PostgreSQL prompt:

    Bash
    psql
    

You will now be at the PostgreSQL prompt, indicated by postgres=#.

SQL
postgres=#

To exit the PostgreSQL prompt, type:

SQL
\q

Then, type exit to return to your regular Ubuntu user prompt.


5. Basic Post-Installation Setup (Optional but Recommended)

For better security and usability, you should set a password for the default postgres database user.5

  1. Connect to the PostgreSQL prompt as the postgres user:

    Bash
    sudo -u postgres psql
    
  2. Set a new password:

    Replace 'your_strong_password' with a secure password.

    SQL
    ALTER USER postgres WITH PASSWORD 'your_strong_password';
    
  3. Exit the prompt:

    SQL
    \q
    

You can now use this password for remote connections or when configuring client applications.

No comments:

Post a Comment

Popular Posts