Last active
March 28, 2019 12:00
-
-
Save jpfinlay/4755284 to your computer and use it in GitHub Desktop.
Adding users and databases to Postgresql 9.1.7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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