liveBook · Manning

Psql meta-command

As explained in Just Use Postgres!

A psql meta-command is a backslash-prefixed instruction interpreted by the psql command-line client rather than by the SQL server.

A psql meta-command is a backslash-prefixed instruction interpreted by the psql command-line client rather than by the SQL server. It helps inspect the current connection and database objects, load scripts, and adjust result formatting. section 1.4

Common commands support connection checks, object discovery, script loading, and readable output:

  • \\? lists the available psql meta-commands, while \\q terminates the connection. section 1.4
  • \\conninfo displays the connected database, user, socket, and port; \\d lists tables, views, and sequences. section 1.4
  • \\i executes SQL scripts from a file, allowing prepared schemas and datasets to be loaded into Postgres. section 4.3 section 9.3
  • \\x on switches to expanded display for wide rows or large values; \\x off restores tabular output. section 8.3.2

Inspect and load a database

After connecting with psql, run \\conninfo to verify the session and \\d to inspect relations. To preload a schema or dataset, execute \\i /home/gaming_ddl.sql and \\i /home/gaming_data.sql, then verify the result with \\dt game.*. section 1.4 section 4.3

Listing 1.3 Connecting with psql
docker exec -it postgres psql -U postgres

Use the runnable psql connection command, then try the meta-commands at the interactive prompt. section 1.4

How Just Use Postgres! covers it

How deep it goes
Defines command roles and demonstrates execution, but stops short of comprehensive meta-command coverage and administration guidance.
Examples
Uses connection inspection, empty-relation checks, gaming, movie-embedding, time-series, and music-streaming dataset loads.
What it assumes
Assumes access to a running Postgres instance and basic psql connection skills while teaching command purposes through direct examples.
What you can do after
Operate/configure psql to inspect sessions, list relations, execute SQL files, and format large query results.
How it connects
Connects psql with SQL statements, database objects, Docker containers, schemas, and PostgreSQL datasets.

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.