DEV Community

Shaikh Al Amin
Shaikh Al Amin

Posted on

How to setup postgres on ubuntu 20.04

Ref Link: Installation Docs

sudo apt install curl ca-certificates

sudo install -d /usr/share/postgresql-common/pgdg
sudo curl -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc --fail https://www.postgresql.org/media/keys/ACCC4CF8.asc

sudo sh -c 'echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

sudo apt update

sudo apt install postgresql-13 postgresql-client-13
Enter fullscreen mode Exit fullscreen mode

Incase of i386 machine, we may need to update source list like below content:

Open the source list with gedit and add the content:

sudo gedit /etc/apt/sources.list.d/pgdg.list

deb [arch=amd64 signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt focal-pgdg main
Enter fullscreen mode Exit fullscreen mode

Login with postgres user and password:

sudo -i -u postgres
postgres@shaikh:~$ psql
postgres=# create database local_test;
CREATE DATABASE
postgres=# grant all privileges on database local_test to postgres;
GRANT
postgres=# ALTER USER postgres WITH PASSWORD 'postgres';
ALTER ROLE
postgres=# 
Enter fullscreen mode Exit fullscreen mode

Now login with postgres user:

psql -U postgres -h localhost

and password is postgres
Enter fullscreen mode Exit fullscreen mode

Top comments (0)