Last active
January 25, 2016 08:04
-
-
Save yihyang/f90c725d82d3073eb88e to your computer and use it in GitHub Desktop.
Commonly used psql commands
This file contains 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
# Show all users | |
\du | |
# List all the databases | |
\l | |
\list | |
# Connect to database | |
\c <database_name> | |
\connect <database_name> | |
# List all tables within database | |
\dt | |
# Login database with another user, with prompt for password | |
psql -d <dbname> -U <username> -W | |
psql -h <hostname> -d <dbname> -U <username> -W | |
## Commands: | |
# Create User | |
CREATE USER <username> ENCRYPTED PASSWORD 'password'; | |
create user "username" with password 'password'; | |
# Create new database | |
CREATE DATABASE <database_name>; | |
# Change ownership of database | |
ALTER DATABASE <database_name> OWNER TO <username>; | |
# DROP DATABASE | |
DROP DATABASE IF EXISTS <table_name>; | |
# DROP TABLES | |
DROP TABLE IF EXISTS <table_name>; | |
References: | |
http://www.postgresql.org/docs/9.1/static/app-createuser.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment