Skip to content

Instantly share code, notes, and snippets.

@jahe
Last active April 1, 2024 18:52
Show Gist options
  • Save jahe/23a8b3378e8695493612654c2ab65ecc to your computer and use it in GitHub Desktop.
Save jahe/23a8b3378e8695493612654c2ab65ecc to your computer and use it in GitHub Desktop.
psql Cheatsheet
# Start psql
> psql
<current-database>=#
# Exit psql
\q
# Show all tables
\dt
# Show all roles
\du
# Show all databases
\l
# Create new database using createdb (not within psql shell)
> createdb <database>
# Switch to a different database
\c <database>
# Execute SQL statements
<current-database>=# SELECT * FROM product;
# Login with role and connect to specific database
> psql -U <role> -d <database>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment