How to create database & user in PostgreSQL

This is a quick reminder to myself about how to quickly create PostgreSQL database (along with the user & password). Since it’s quite usual for me that db name and user name are the same, I’m putting them the same in a script to make search&replace easier.

sudo -u postgres psql
postgres=# CREATE USER user_db_name WITH ENCRYPTED PASSWORD 'mypass';
postgres=# CREATE DATABASE user_db_name WITH OWNER user_db_name ENCODING='UTF-8' LC_COLLATE='en_US.utf8' LC_CTYPE='en_US.utf8' TEMPLATE template0;