I use psql’s built-in commands to explore Postgres, inspect database objects, and adjust my command-line workflow. The notes below collect practical commands, customization tips, and questions I have shared about the client.
I noted that Postgres has an awesome amount of data collected in the catalog tables, though navigating them can be confusing and may require browsing documentation and PostgreSQL source code.
I noted that many built-in psql commands begin \d generally.
\di to list all your indexes
\dx to list installed extensions
\dp to show access privileges
\d tablename to describe a specific table
When exploring these commands, I recommend connecting to the database with the -E argument to psql, which echoes the command that runs so I can inspect how the \d commands work and which SQL they execute.
I described exploring the commands and their SQL as: A great exercise for learning more about Postgres and what is in the catalogs.
I expressed enthusiasm for a good psql post: “Love me a good psql post!”
I shared a psql post titled “Settings, Presets, Echo, and Saved Queries.”
I asked, “What various Postgres CLI clients do folks use?”
I asked, “Folks, how do you install postgres”.
I describe psql as a CLI editor that ships with Postgres, and say it is incredibly powerful for working with Postgres.
I find that psql doesn’t take too much of a learning curve to start to get comfortable.
\?
I use \? to get an idea of all utility commands available once connected in psql.
I use \d to describe tables within the database; the command is introduced by the line, “A handy thing I use all the time is \d.”
\d accounts
I use options you can set in your psqlrc (config) file to customize your CLI experience, and I can also toggle those options while working directly in psql.
\timing
I use \timing to show the time it took to run your query.
\x auto
I use \x auto to autoformat your text output.
\pset pager 0
\pset pager 1
I use \pset pager 0, which turns off your pager.
\e
For editing a query in your editor of choice, I use \e.
I described these as: Just a few things to get you started working with psql.
Related: psql exports and shell commands, using psql as an editor, customizing psql settings