Skip to main content

Postgres Installation (Ubuntu)

Install and initialize PostgreSQL on Ubuntu.

Install packages

sudo apt update
sudo apt install postgresql postgresql-contrib

Start the service (should be auto-started after install):

sudo systemctl start postgresql.service
sudo systemctl status postgresql.service

Create a database user (interactive)

Switch to the postgres admin account and create a user:

sudo -i -u postgres
createuser --interactive

Follow the prompts to set name/role flags.

Create a database

createdb <db_name>

If creating for a specific user:

createdb -O <db_user> <db_name>

Change user password

Open psql as the postgres superuser and change a user's password:

sudo -u postgres psql
\password <db_user>

Use strong, unique passwords.