PostgreSQL - Create user & grant permission on a database

Create user & grant permission on a PostgreSQL database

Snippets

CREATE USER your_username;
ALTER USER your_username WITH ENCRYPTED PASSWORD 'your_password';

CREATE DATABASE your_database_name;

// Grant all PRIVILEGES
GRANT ALL PRIVILEGES ON DATABASE your_database_name TO your_username;

// Grant Readonly
GRANT SELECT, SHOW VIEW ON `your_database_name`.* TO 'your_username' @ '%';

Referrence

Last updated