Skip to content

Instantly share code, notes, and snippets.

@gnzsnz
Last active March 9, 2024 17:40
Show Gist options
  • Save gnzsnz/97db4be8deb42db049e4c63e1b1757fb to your computer and use it in GitHub Desktop.
Save gnzsnz/97db4be8deb42db049e4c63e1b1757fb to your computer and use it in GitHub Desktop.

Create postgres user and database

How to create a user, a database and grant all privileges on the new database?

sudo -u postgres psql
postgres=# CREATE DATABASE mydb;
postgres=# CREATE USER myuser WITH ENCRYPTED PASSWORD 'mypass';
postgres=# GRANT ALL PRIVILEGES ON DATABASE mydb TO myuser;
postgres=# GRANT ALL ON SCHEMA public TO myuser;

Further Reading on:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment