Skip to main content

Postgres

	•	psql -U <username> -d <database>
Opens the interactive PostgreSQL terminal for the specified database and user.
• \q
Exits the psql terminal.
• \l
Lists all databases in the PostgreSQL instance.
• \c <database>
Connects to a specified database.
• \dt
Lists all tables in the current database.
• \d <table>
Describes the structure of a table (columns, types, etc.).
• createdb <database>
Creates a new PostgreSQL database.
• dropdb <database>
Drops (deletes) a PostgreSQL database.
• createuser <username>
Creates a new PostgreSQL user.
• dropuser <username>
Deletes a PostgreSQL user.
• pg_dump <database> > backup.sql
Backs up a PostgreSQL database to a SQL file.
• pg_restore -d <database> backup.sql
Restores a PostgreSQL database from a backup file.
• pg_isready -U <username>
Checks if the PostgreSQL server is ready to accept connections.
• sudo -u postgres psql
Opens the PostgreSQL terminal as the default postgres user.