Created
May 5, 2017 19:12
-
-
Save fabiotatsuo/738d53774f3780071f8f7f62da322643 to your computer and use it in GitHub Desktop.
Basic PostgreSQL commands
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
Create superuser | |
$ createuser -P -s -e username | |
psswd: | |
$ psql -U username | |
List databases | |
postgres=# \l | |
\q: Quit/Exit | |
\du: List users | |
Remove database | |
postgres=# REVOKE CONNECT ON DATABASE database_name FROM public; | |
postgres=# SELECT pg_terminate_backend(pg_stat_activity.pid) | |
FROM pg_stat_activity | |
WHERE pg_stat_activity.datname = 'database_name'; | |
postgres=# drop database database_name; | |
Use db | |
postgres=# \c database_name | |
list tables in connected database | |
postgres=# \dt | |
list columns on table | |
postgres=# \d <tablename> | |
backup database | |
$ pg_dump <databasename> > <outfile> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment