2018-01-17 16:13:38 +00:00
|
|
|
-- Connect to a specific database
|
2018-01-07 11:42:08 +00:00
|
|
|
\c database_name
|
|
|
|
|
2018-01-17 16:13:38 +00:00
|
|
|
-- To quite the psql
|
2018-01-07 11:42:08 +00:00
|
|
|
\q
|
|
|
|
|
2018-01-17 16:13:38 +00:00
|
|
|
-- List all databases in the PostgreSQL database server
|
2018-01-07 11:42:08 +00:00
|
|
|
\l
|
|
|
|
|
2018-01-17 16:13:38 +00:00
|
|
|
-- List all schemas
|
2018-01-07 11:42:08 +00:00
|
|
|
\dn
|
|
|
|
|
2018-01-17 16:13:38 +00:00
|
|
|
-- List all stored procedures and functions
|
2018-01-07 11:42:08 +00:00
|
|
|
\df
|
|
|
|
|
2018-01-17 16:13:38 +00:00
|
|
|
-- List all views
|
2018-01-07 11:42:08 +00:00
|
|
|
\dv
|
|
|
|
|
2018-01-17 16:13:38 +00:00
|
|
|
-- Lists all tables in a current database
|
2018-01-07 11:42:08 +00:00
|
|
|
\dt
|
|
|
|
|
2018-01-17 16:13:38 +00:00
|
|
|
-- Get more information on tables in the current database
|
2018-01-07 11:42:08 +00:00
|
|
|
\dt+
|
|
|
|
|
2018-01-17 16:13:38 +00:00
|
|
|
-- Get detailed information on a table
|
2018-01-07 11:42:08 +00:00
|
|
|
\d+ table_name
|
|
|
|
|
2018-01-17 16:13:38 +00:00
|
|
|
-- Show a stored procedure or function code
|
2018-01-07 11:42:08 +00:00
|
|
|
\df+ function_name
|
|
|
|
|
2018-01-17 16:13:38 +00:00
|
|
|
-- Show query output in the pretty-format
|
2018-01-07 11:42:08 +00:00
|
|
|
\x
|
|
|
|
|
2018-01-17 16:13:38 +00:00
|
|
|
-- List all users
|
2018-01-07 11:42:08 +00:00
|
|
|
\du
|
|
|
|
|
2018-01-17 16:13:38 +00:00
|
|
|
-- Export table into CSV file
|
2018-01-07 11:42:08 +00:00
|
|
|
\copy <table_name> TO '<file_path>' CSV
|
|
|
|
|
2018-01-17 16:13:38 +00:00
|
|
|
-- Export table, only specific columns, to CSV file
|
2018-01-07 11:42:08 +00:00
|
|
|
\copy <table_name>(<column_1>,<column_1>,<column_1>) TO '<file_path>' CSV
|
|
|
|
|
2018-01-17 16:13:38 +00:00
|
|
|
-- Import CSV file into table
|
2018-01-07 11:42:08 +00:00
|
|
|
\copy <table_name> FROM '<file_path>' CSV
|
|
|
|
|
2018-01-17 16:13:38 +00:00
|
|
|
-- Import CSV file into table, only specific columns
|
2018-01-07 11:42:08 +00:00
|
|
|
\copy <table_name>(<column_1>,<column_1>,<column_1>) FROM '<file_path>' CSV
|
|
|
|
|