PostgreSQL – Create databas and user

Ubuntu 16.04
PostgreSQL 9.5

As the default installation of Postgres a super admin (postgres) is made and has full access to the entire PostgresSQL instance.

Change to postgres user

sudo -u postgres psql
postgres=# create database MY_DATABASE;

Create a new user

postgres=# create user MY_USER with encrypted password 'USER_PASSWORD';

Grant access on the database MY_DATABASE to the new user MY_USER

postgres=# grant all privileges on database MY_DATABASE to MY_USER;

Or using pure psql

CREATE DATABASE MY_DATABASE;
CREATE USER MY_USER WITH ENCRYPTED PASSWORD 'USER_PASSWORD';
GRANT ALL PRIVILEGES ON DATABASE MY_DATABASE TO MY_USER;