Skip to content

Instantly share code, notes, and snippets.

@mauriballes
Last active September 7, 2018 17:55
Show Gist options
  • Save mauriballes/01bef81b363dcb545442ba017c8391cc to your computer and use it in GitHub Desktop.
Save mauriballes/01bef81b363dcb545442ba017c8391cc to your computer and use it in GitHub Desktop.
Postgres Create Users

Postgres Users

Create User

CREATE USER mynewuser PASSWORD 'mynewpassword';

Drop User

DROP USER mynewuser;

Alter Role Super User

  • SUPERUSER/NOSUPERUSER
  • CREATEDB/NOCREATEDB
  • CREATEROLE/NOCREATEROLE
  • CREATEUSER/NOCREATEUSER
  • LOGIN/NOLOGIN
  • PASSWORD
  • VALID UNTIL
ALTER ROLE <rol name> WITH <options>;
-- Example
ALTER ROLE mynewuser WITH SUPERUSER;

Change Password

ALTER ROLE mynewuser WITH PASSWORD 'mynewpassword';

Create Database

CREATE DATABASE mydatabase WITH OWNER mynewuser;

Grant Privileges

GRANT ALL PRIVILEGES ON DATABASE mydatabase TO mynewuser;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment