liveBook · Manning

Psql

As explained in Just Use Postgres!

psql is PostgreSQL's lightweight command-line client for connecting to databases and executing SQL and psql meta-commands.

psql is PostgreSQL’s lightweight command-line client. It runs inside the standard Postgres Docker container, letting you connect to a database and execute SQL without installing another SQL tool on the host. section 1.3 section 1.4

Connect from a Postgres container

Start a running container, then open an interactive psql session with `docker exec -it postgres psql -U postgres`. A successful connection displays a `postgres=#` prompt. Run `\conninfo` to inspect the database, user, socket, and port; run `\d` to list relations; enter `\q` to exit. section 1.4

Use psql for both SQL and backslash-prefixed meta-commands:

  • Execute ordinary SQL statements against the connected PostgreSQL database. section 1.4
  • Run `\?` to display the available meta-commands, which expose connection information, database objects, file-based data loading, and other operations. section 1.4
  • Connect locally without entering a password when `docker exec` places psql inside a container configured to trust local Unix-socket connections. section 1.4
Listing 1.3 Connecting with psql
docker exec -it postgres psql -U postgres

Inspect the runnable command for opening psql inside a Postgres container. section 1.4

How Just Use Postgres! covers it

How deep it goes
Explains invocation, prompts, socket authentication, SQL, and meta-commands, but stops short of administration or application integration.
Examples
Demonstrates docker exec, the postgres=# prompt, \conninfo, \d, \?, and TimescaleDB extension queries.
What it assumes
Assumes Docker is available and a Postgres container is running; teaches connection from inside the container without host-side SQL tools.
What you can do after
Operate PostgreSQL interactively from a container, inspect connection state and relations, execute SQL, and check installed extensions.
How it connects
Connects SQL with PostgreSQL, Docker containers, Unix sockets, database objects, and TimescaleDB extensions.

Also explained in

Compare how 3 books explain psql →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Just Use Postgres!. The section links point to the parts of the book it draws on.