To install PostgreSQL on Ubuntu 22.04, follow these steps:
Update the package manager's package list by running the following command:
sudo apt update
Install the PostgreSQL package by running the following command:
sudo apt install postgresql
After the installation is complete, start the PostgreSQL service by running the following command:
sudo systemctl start postgresql
To make sure that the PostgreSQL service starts automatically when the system boots, run the following command:
sudo systemctl enable postgresql
To log in to the PostgreSQL database as the default "postgres" user, run the following command:
sudo -u postgres psql
postgres=# create database mydb_name;
postgres=# create database myuser;
postgres=# create user myuser with encrypted password 'mypass';
postgres=# grant all privileges on database mydb_name to myuser;
This will open the PostgreSQL interactive terminal. From here, you can create databases, users, and perform other tasks.
If you want to log in as a different user, you can use the following command:
psql -U username
Replace "username" with the name of the user you want to log in as.