PostgreSQL 18 cheatsheet
PostgreSQL 18: Connecting
6 common PostgreSQL 18 tasks.
Connect to a database
Open psql against a specific host, port, user and database.
psql -h localhost -p 5432 -U postgres -d mydb
Connect with a connection URI
Open psql using a single connection string.
psql "postgresql://postgres@localhost:5432/mydb"
Check the server version
Run inside psql to see which server version you are connected to.
SELECT version();
Run a SQL file
Execute the statements in a file and stop at the first error.
psql -U postgres -d mydb -v ON_ERROR_STOP=1 -f script.sql