Skip to content

Instantly share code, notes, and snippets.

@mezbahalam
Created December 20, 2022 20:29
Show Gist options
  • Save mezbahalam/dacde594684dafabeafeebd92a92ae91 to your computer and use it in GitHub Desktop.
Save mezbahalam/dacde594684dafabeafeebd92a92ae91 to your computer and use it in GitHub Desktop.
install postgresql on ubuntu 22.04

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment