How to Install PostgreSQL on Ubuntu 20.04  Server

How to Install PostgreSQL on Ubuntu 20.04 Server

·

1 min read

Install software certificates for a secure SSL connection

$ sudo apt install wget ca-certificates

pgsql_1.png

Add it to apt-key management utility and create a new configuration file with an official PostgreSQL repository address

$ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

$ sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'

pgsql_2.png

pgsql_3.png

Install PostgreSQL

$ sudo apt update

pgsql_4.png

$ apt install postgresql postgresql-contrib

pgsql_5.png

Check PostgreSQL status

$ service postgresql status

pgsql_6.png

Command Line Tool

A default admin user “postgres” is created by the default. A “psql” command-line client tool is used to interact with the database engine.

$ sudo -u postgres psql

pgsql_7.png

PostgreSQL installation also creates a default database named “postgres” and connects you to it automatically when you first launch psql.

Check the connection

$ \conninfo

pgsql_8.png

If you want to see a list of all the databases that are available on a server, use \l command.

$ \l

pgsql_9.png

list of all the users with their privileges use

$ \du

pgsql_10.png

Since the default “postgres” user does not have a password, you should set it yourself.

$ \password postgres

pgsql_11.png