Skip to content

Instantly share code, notes, and snippets.

@vmwsree
Last active February 19, 2018 23:45
Show Gist options
  • Save vmwsree/4582424db5a3e385a1a31c0a7ef94595 to your computer and use it in GitHub Desktop.
Save vmwsree/4582424db5a3e385a1a31c0a7ef94595 to your computer and use it in GitHub Desktop.
sudo su - postgres
\password Change your password
\q Exit psql
\l List all databases accessible by the current account
\du List roles
\c <db name> Connect to a database
\dt List all tables in a connected database
\d <table> List columns in the selected table
\conninfo Show information about your currect connection
\q
createuser --interactive
createdb <database name>
psql
ALTER DATABASE <database name> OWNER TO <role name>;
ALTER USER <username> WITH PASSWORD '<new password>';
=======
> pg_dump -h <server> -p 5432 -U <username> <database> > <local file>
Restoring your database is also as simple with a single command:
> psql -h <server> -U <username> -d <database> < <local file>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment