Getting comfortable with psql
psql is a CLI editor that ships with Postgres. It’s incredibly powerful for working with Postgres, and doesn’t take too much of a learning curve to start to get comfortable so you can really feel like an expert working with your database.
Just a rundown of a few things to get you started:
Once connected in psql you can get an idea of all utility commands available with:
\?
A handy thing I use all the time is \d
.
\d
will describe the tables within database. You can also add a table/index/etc. onto it to describe that specific table such as:
\d accounts
There are a number of options you can set in your psqlrc (config) file to customize your CLI experience. But you can also toggle those when directly working in psql.
\timing
will give you the time it took to run your query\x auto
will autoformat your text output\pset pager 0
turns off your pager or 1 to turn it back on
Oh and for editing a query in your editor of choice. Make sure you set your $EDITOR enviroment variable to the editor of your choice, though the only right choice is vim:
\e
Just a few things to get you started working with psql.