Skip to content

Instantly share code, notes, and snippets.

@jpfinlay
Last active March 28, 2019 12:00
Show Gist options
  • Save jpfinlay/4755284 to your computer and use it in GitHub Desktop.
Save jpfinlay/4755284 to your computer and use it in GitHub Desktop.
Adding users and databases to Postgresql 9.1.7
# Login as postgres user (superuser)
sudo -u postgres psql <db>
# Login to a db using a username
psql db_name -U username
# Create a new user and allow them to create databases
CREATE USER username WITH LOGIN;
ALTER ROLE username WITH CREATEDB;
# List all users
\du
# List all databases
\l
# Create new database from command line
createdb <db_name>
# Destroy a database from command line
dropdb <db_name>
# Create a new database and grant all privileges to the specified user
CREATE DATABASE database_name;
GRANT ALL PRIVILEGES ON DATABASE database_name TO username;
# List all databases
\list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment