Skip to content

Instantly share code, notes, and snippets.

@ryantbrown
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryantbrown/0d2833f1f4df3f1b51a2 to your computer and use it in GitHub Desktop.
Save ryantbrown/0d2833f1f4df3f1b51a2 to your computer and use it in GitHub Desktop.
Postgres Administration
# command line:
sudo -u postgres createuser --superuser username
sudo -u postgres createdb -O vagrant dbname
# enter shell
psql dbname username
# list users:
\du
#list databases:
\list
# exit shell:
\q
# manaing roles (users)
CREATE USER username WITH PASSWORD 'password'
ALTER ROLE username WITH PASSWORD 'vagrant';
DROP ROLE username;
# WITH options
SUPERUSER | NOSUPERUSER
CREATEDB | NOCREATEDB
CREATEROLE | NOCREATEROLE
CREATEUSER | NOCREATEUSER
PASSWORD 'password'
# managing databases
CREATE DATABASE dbname OWNER username;
DROP DATABASE IF EXISTS dbname;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment