DEV Community

Shaikh Al Amin
Shaikh Al Amin

Posted on • Edited on

2

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'


// For AMD:

sudo sh -c 'echo "deb [arch=amd64 signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt noble-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

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more