Instiq
Chapter 2 · Operations management·v1.0.0·Updated 7/12/2026·~14 min

What's changed: Initial version (topic S2)

2.2Standard Bundled Tools

Key points

Learn the commands bundled standard with PostgreSQL: pg_ctl for starting, stopping, and reloading the server; createuser/dropuser for role management; createdb/dropdb for database management; the psql interactive terminal; pg_config for build information; pg_controldata for cluster control information; pg_isready for checking server liveness; pg_resetwal for resetting the WAL; and psql's meta-commands (\d, \l, \dt, \du, \c, \?, \h, \timing).

PostgreSQL ships with a standard set of bundled commands covering everything from starting the server to day-to-day interactive work and status checks. There are many to remember, but each has a clearly separated role, so mapping "which command for which task" turns this into reliable exam points.

2.2.1pg_ctl and user/database management commands

  • pg_ctl is the central command for controlling the PostgreSQL server process. Its subcommands are start (start), stop (stop; -m selects the shutdown mode), reload (reload the configuration file only, keeping connections alive), restart (stop then start again), and status (check running status).
  • createuser/dropuser are command-line tools for creating and dropping database roles (users). Internally they are wrappers that execute the SQL CREATE ROLE/DROP ROLE, with options such as -s (grant superuser privileges).
  • createdb/dropdb are command-line tools for creating and dropping databases. Internally they wrap the SQL CREATE DATABASE/DROP DATABASE. By default they create the database by copying template1.

2.2.2psql and diagnostic commands

  • psql is PostgreSQL's standard interactive terminal. Besides executing SQL statements, it supports meta-commands starting with \: \l (list databases), \c (switch database), \dt (list tables), \d (show the structure of a table etc.; \d tablename for detail), \du (list roles), \timing (toggle showing each query's execution time), \? (help for meta-commands), and \h (help for SQL commands).
  • pg_config reports the installed PostgreSQL's build-time settings, version, and various directory paths (include directory, etc.). pg_controldata is a read-only tool that displays the control-file information for a data directory (cluster state, the latest checkpoint location, WAL timeline ID, and so on).
  • pg_isready is a tool that quickly checks whether the server is ready to accept connections (used by monitoring scripts for liveness checks; judged via its exit code). pg_resetwal is a last-resort tool that resets a corrupted WAL (write-ahead log), forcibly returning an unstartable cluster to a startable state (it carries a risk of data inconsistency, so it is used only when no other option remains).
Exam point

The staples: pg_ctl reload reloads only the configuration file while keeping connections alive, whereas restart drops connections and restarts; createuser/createdb wrap CREATE ROLE/CREATE DATABASE; \l lists databases, \dt lists tables, \du lists roles, \d shows structure; pg_isready = liveness check, pg_resetwal = forced WAL reset (last resort). Confusing meta-command letters (e.g. \l vs \dt) is a recurring trap.

Picture a day of operations and the roles of these commands become clear. In the morning, a request comes in to change max_connections in postgresql.conf. Because this is a parameter that requires a restart, you safely stop and start again with pg_ctl restart -D $PGDATA. For a parameter that does not require a restart, such as changing only the log destination, you apply it without dropping connections using pg_ctl reload (or the SQL equivalent SELECT pg_reload_conf()), minimizing business impact. Next, a request arrives to provision a role and database for a new app: you create them in order with createuser app_user then createdb -O app_user app_db, and confirm the connection works with psql -U app_user -d app_db. Inside psql, the standard check is \l to confirm the new database appears in the list, and \du to visually confirm the app_user role exists with the intended privileges. In a monitoring context, a load balancer or orchestration tool periodically runs pg_isready -h dbhost, and if it detects anything other than exit code 0 (ready), it removes the node from rotation—wired into automation this way. Finally, in the serious scenario where a power outage or similar corrupts the cluster so badly it cannot even start, once every other recovery avenue is exhausted, pg_resetwal becomes the last-resort option—but you must understand its nature: it is a forced measure that prioritizes getting the server running again even at the cost of transactional consistency.

CommandRoleNote
pg_ctl reloadReload config file onlyKeeps connections
pg_ctl restartStop then start againConnections are dropped
pg_isreadyQuick check of readinessUsed for liveness monitoring
pg_resetwalForce-reset the WALLast resort; risks inconsistency
Warning

Trap: "any config change takes effect immediately with just pg_ctl reload" is wrong—some parameters, like max_connections, require a restart, and reload alone will not apply them. Also, "\dt lists databases" is wrong—\dt lists tables; \l lists databases. Furthermore, treating pg_resetwal as "a safe command for routine maintenance" is wrong—it is a last resort carrying a risk of data inconsistency and is not used in normal operations.

Diagram of the roles of pg_ctl, createuser/createdb, psql, and info tools.
Four groups: control, admin, interactive, info

2.2.3Section summary

  • pg_ctl = start/stop/reload/restart/status. reload keeps connections and only reloads config; restart drops connections and restarts
  • createuser/dropuser, createdb/dropdb wrap CREATE/DROP ROLE and DATABASE. Distinguish psql meta-commands (\l, \dt, \du, \d, \c, \?, \h, \timing)
  • pg_config = build info, pg_controldata = control-file info, pg_isready = liveness check, pg_resetwal = forced WAL reset (last resort)

Sign in to track progress — Log in.

Quick check

(just a quick review)

Q1. You changed only the log destination in postgresql.conf. What is the best way to apply this change to the running server without dropping active connections?

Q2. While connected via psql, you want to see the list of databases that exist on the server. Which meta-command should you use?

Q3. A power outage corrupted the PostgreSQL server so badly it will not start via normal procedures. As a last resort, once every other recovery avenue is exhausted, which command is considered?

Check your understandingPractice questions for Chapter 2: Operations management