psql: The PostgreSQL Client
Get fluent in psql — connect, create a database, run and save queries, format and export results, and make the client your own.
Most people meet PostgreSQL through a GUI and never learn the tool that ships with it. psql is faster, scriptable, and always there on the server you just SSH'd into. We start from an empty prompt and build up real fluency: creating a database, exploring it with meta-commands, keeping schema and queries in files you can replay, passing values in with variables, exporting results, and finally shaping the client to your taste with a startup file. Small steps, each one a thing you'll use the same day.
What you'll build
- Connect to PostgreSQL and move around with meta-commands
- Create a database and load schema and data from files
- Read, format and export query results
- Parameterise saved queries with psql variables
- Run psql non-interactively in scripts
- Customise the client with a .psqlrc
Contents
- Open a session
- Create a database
- Find your way around
- Keep your schema in a file
- Run a file from inside the session
- Give it some data
- Read a result
- Tame wide output
- Save a query you'll run again
- Pass values in
- Get results out
- Inspect what's there
- Use it from a script
- Compose a repeatable report
- Make the client yours