Skip to content

Instantly share code, notes, and snippets.

@hansrajdas
Last active September 23, 2023 14:29
Show Gist options
  • Save hansrajdas/43a73a9fbafdc23cbd78539c37255e1a to your computer and use it in GitHub Desktop.
Save hansrajdas/43a73a9fbafdc23cbd78539c37255e1a to your computer and use it in GitHub Desktop.
Postgres commands

Connect to postgres DB

Install psql and use below command from shell

psql postgres://username:password@hostname:5432/db_name

# With some params
psql postgres://username:password@hostname:5432/db_name?application_name=root_connection

Postgres commands

List all databases

\l

Change to given DB_NAME

\c <DB_NAME>

List all tables within current DB

\d

Describe table - view table schema

\d <TABLE_NAME>

\d+ <TABLE_NAME>

select column_name, data_type from information_schema.columns where table_name = '<table_name>'

Toggle extended display

\x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment