Frequently used commands with PostgreSQL
psql |
open PostgreSQL interactive terminal
|
psql -c {command} |
execute a single command and exit
|
psql -d {dbatabase} |
connect to a particular database
|
psql -U {role} |
connect as a particular user
|
psql -l |
list all databases
|
psql commands
\du |
list all roles with their permissions
|
\l |
list all databases with their owners
|
\c |
show the current user and the database that you are connected to
|
\c {database} |
connect to a particular database
|
\dt |
list all tables in a connected database
|
\d {table} |
list all columns and indexes for a specific table in a connected database
|
psql interactive terminal
createuser {user} |
create a new PostgreSQL role
|
dropuser {user} |
drop an existing PostgreSQL role
|
createdb {database} |
create a new database
|
dropdb {database} |
drop an existing database
|
pg_dump {database} \ |
dump a database to a text file
|
psql {database} \ |
restore a database from a text file
|
pg_dump -Ft \ |
dump a database to an archive file
|
pg_restore -d \ |
restore a database from an archive file
|
pg_dumpall > dump.sql |
dump all databases to a text file
|
pg_dump -Ft is the same as --format=tarpg_restore-c will drop database before restoring if already exists-C will also create a database unless already exists
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.