Skip to content

Instantly share code, notes, and snippets.

@surjikal
Last active December 9, 2015 21:58
Show Gist options
  • Save surjikal/4333828 to your computer and use it in GitHub Desktop.
Save surjikal/4333828 to your computer and use it in GitHub Desktop.
Postgres cheat sheet.

Default port: 5432

To log in (as root)...
psql -d template1 -U postgres

Commands

The prompt should be: template1=#

Description Command
Create a user CREATE USER <user> WITH PASSWORD '<password>';
Create a database CREATE DATABASE <database>;
Assign db to user ALTER DATABASE <database> OWNER TO <user>;
List roles SELECT rolname FROM pg_roles;
Drop user privileges DROP OWNED BY <old_user>;
Reassign roles REASSIGN OWNED BY <old_user> TO <user>;
Drop user DROP USER <user>;
List databases \l
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment