Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

Install PostgreSQL on Ubuntu 18.04

This guide shows you how to install PostgreSQL on Ubuntu 18.04, then make a user and a database. It needs root access, so it is for VPS and dedicated server users.

VPS and Cloud Servers1 min read11 steps
Tip: Ubuntu 18.04 is old. Newer Ubuntu versions use almost the same steps.

What is PostgreSQL?

A database is a place where programs store information, like a big filing cabinet. PostgreSQL, often called Postgres, is a free and popular database. Websites and apps use it to keep users, orders and posts.

Steps

  1. Log in to your server with SSH. SSH lets you type commands on a remote computer.
  2. Update the package list.
    apt update
  3. Install PostgreSQL and its extra tools.
    apt install -y postgresql postgresql-contrib
  4. Check that it is running.
    systemctl status postgresql
  5. Switch to the special postgres user. The install creates this user to manage the database.
    su - postgres
  6. Open the Postgres command window.
    psql
    The prompt changes to postgres=#.
  7. Create a new database user. Change the name and password.
    CREATE USER myuser WITH PASSWORD 'choose-a-strong-password';
  8. Create a database owned by that user.
    CREATE DATABASE mydb OWNER myuser;
  9. Leave the command window.
    \q
  10. Go back to the root user.
    exit
  11. Test the new login.
    psql -h 127.0.0.1 -U myuser -d mydb
    Type the password when asked. If you see the mydb=> prompt, it works.

Useful facts

  • Postgres uses port 5432. A port is like a numbered door into your server.
  • By default it only listens on the server itself. This is the safe choice.
  • On Ubuntu 18.04, the version installed is 10.
  • Settings live in /etc/postgresql/10/main/.

Warning: Do not open port 5432 to the whole internet. If a remote app needs access, allow only its IP address and take a backup first.

Quick recap

  • PostgreSQL is a free database.
  • Install it with apt install postgresql postgresql-contrib.
  • Use the postgres user and psql to create a user and a database.
  • Keep port 5432 private.