Nerd For Tech
Published in

Nerd For Tech

How to install PostgreSQL on Ubuntu 20.04

First steps first

We are going to the PostgreSQL using plain old Ubuntu repositories. This is the easiest and the most convenient way of installation on Ubuntu and its flavors. Step1: Don’t forget to update your repositories:

sudo apt-get update

After that, you are good to go with the installation.
Step2: Install PostgreSQL

sudo apt install postgresql postgresql-contrib

If everything went smooth you should check the status of the installed service, just to be sure it is running:

sudo service postgresql status

If it is not running you can start with the following command:

sudo service postgresql start

Step3: Create a new user

You will probably want to create a new user, the easiest way is to use interactive mode:

sudo -u postgres createuser --interactive

You will be prompted to enter the name of a new role and whether it should be a superuser or not:

Enter name of role to add: test_user Shall the new role be a superuser? (y/n) y

Step4: Assign a password to a newly created user ( or default postgres account)

Probably it is a good idea to assign a password to a newly created role. The easiest way of doing this is by using the PostgreSQL prompt:

sudo -u postgres psql

After you are welcomed with a prompt you can type \password previously_picked_user_name

postgres=# \password test_user

Following the same strategy you can alter your default postgres user password:

postgres=# \password postgres

Step5: Create your first database

When you are finished with setting up your users you can create a new database( testDb in my case):

sudo -u postgres createdb testDb

Step6: Assign database created in Step5 to user-created in Step4

After you’ve created a new database all you left to do is to set your previously created user as a new owner of your database:


That is everything you need to do in order to start using PostgreSQL. Enjoy!


  1. Set up WSL2, PostgresQL and Phoenix LiveView on Windows
  2. How To Install PostgreSQL on Ubuntu 20.04 [Quickstart]
  3. How to change owner of PostgreSql database?

Originally published at on November 23, 2020.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Mike Vas

Mike Vas


Software Engineer interested in web and mobile development and ML. IG: TW: @mikevastech, GitHub: mikevatech