DEV Community

Anthony Gilbert
Anthony Gilbert

Posted on

Install and config PostgreSQL on Ubuntu Linux

First we need to install PostgreSQL
sudo apt get install postgresql postgresql-contrib

Now we check the path for PostgreSQL(for me it is version 12, it might be different for you)
ls /etc/postgresql/12/main/

This allows us to check all of the commands available to us
service postgresql

This will allow us to check the status
service postgresql status

This will log us in as the default user
sudo su postgres

Now if we run psql we will enter the postgresql cli.

From here, you can run \l to see the default databases.

You can also run \du to list all of the users.

To change the password of the default user 'postgres', run ALTER USER postgres WITH PASSWORD 'test123';

To create a new user:
CREATE USER nova_glow WITH PASSWORD 'test123';

Now if we want to give our new user "super" access...
ALTER USER nova_glow WITH SUPERUSER;

If You want to remove a user, simply do the following:
DROP USER user_2;

If you want to see all of the available commands for psql, you can simply run man psql in a new shell.

Note: It is recommended to install pgadmin from the software center.

Top comments (0)