Skip to content

Instantly share code, notes, and snippets.

@mraza007
Last active September 26, 2018 19:05
Show Gist options
  • Save mraza007/07c28ea6a4d8ae339a60c7e06f5acb4a to your computer and use it in GitHub Desktop.
Save mraza007/07c28ea6a4d8ae339a60c7e06f5acb4a to your computer and use it in GitHub Desktop.
Postgres Useful Commands

Postgres useful commands

  • psql db_name Connecting to Database
  • \df+ View tables
  • \du View users
  • \q: Quit/Exit
  • \c __database__: Connect to a database
  • \d __table__: Show table definition including triggers
  • \l: List databases
  • \dy: List events
  • \df: List functions
  • \di: List indexes
  • \dn: List schemas
  • \dt *.*: List tables from all schemas (if *.* is omitted will only show SEARCH_PATH ones)
  • \dv: List views
  • \df+ __function__ : Show function SQL code.
  • \x: Pretty-format query results instead of the not-so-useful ASCII tables
  • \copy (SELECT * FROM __table_name__) TO 'file_path_and_name.csv' WITH CSV: Export a table as CSV
  • \d+ table_name This will allow you to see table information

Database Specific

  • SELECT * FROM table_name to view the rows of the table
  • DELETE FROM table_name This will allow you to delete table rows
  • ALTER USER user_name WITH PASSWORD 'new_password' This will allow you to change password.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment