PG_WRAPPER(1)

πŸ’… pg_wrapper β€” the little genius matchmaker of PostgreSQL client commands ✨

okay so bestie, welcome to pg_wrapper(1) from the Debian PostgreSQL infrastructure crew. she's small, she's sneaky, and she knows exactly which cluster you meant. let's get into it 🫢


🌸 NAME 🌸

pg_wrapper β€” a wrapper for PostgreSQL client commands. basically the backstage manager nobody sees but everybody needs πŸ’–


✨ SYNOPSIS ✨

client-program [--cluster version/cluster] [...]

and who is client-program? it's psql, createdb, dropuser, and literally every other client program installed in /usr/lib/postgresql/version/bin. the whole squad πŸ‘‘


πŸ¦‹ DESCRIPTION πŸ¦‹

so this program only runs as a link to names that match PostgreSQL programs in /usr/lib/postgresql/version/bin. sneaky, right? πŸ™ˆ

what she does: she figures out the configured cluster and database for you, the user, then calls the right version of the program you asked for to connect to that cluster and database β€” passing along any options you specified. no cap. πŸŽ€

here's how she picks the target cluster, in descending order of precedence:

  • explicit specification with the --host option
  • explicit specification with the --cluster option
  • if the PGHOST environment variable is set, no further cluster selection is performed. the default PostgreSQL version and port number (from the command line, the environment variable PGPORT, or default 5432) will be used.
  • explicit specification with the PGCLUSTER environment variable
  • if a port is given (either via -p, --port, or PGPORT), and no host is given, the local cluster matching that port number is used
  • matching entry in ~/.postgresqlrc (see postgresqlrc(5)), if that file exists
  • matching entry in /etc/postgresql-common/user_clusters (see user_clusters(5)), if that file exists
  • if only one cluster exists on the local system, that one gets selected. periodt. πŸ’…
  • if several clusters exist on the local system, the one listening on the default port 5432 will be selected
and if none of these rules match? pg_wrapper doesn't set any environment variables at all, and the program you called will likely error out with a message like could not connect to server: Connection refused. sad girl hours 😭

now for the plot twist 🫢: for psql, pg_archivecleanup, and pg_isready, pg_wrapper will always use the binary from the newest PostgreSQL version installed β€” because these are downwards compatible, bestie. icon behavior. but if the cluster version is older than 9.2, the newest considered binary version is 14. noted. πŸ“Œ

and one more thing β€” pg_wrapper needs to be able to read the server config to get the port number to connect to. if a non-standard port is configured somewhere pg_wrapper can't read, connecting will fail. this particularly holds if the port was configured via ALTER SYSTEM in postgresql.auto.conf and pg_wrapper is invoked as any user other than postgres and root. πŸ’€ consider yourself warned, angel.


πŸ’œ OPTIONS πŸ’œ

  • --cluster version/cluster
  • --cluster version/host:[port]

where cluster is either the name of a cluster on the local system, or takes the form host:port for a remote cluster. if port is left empty (i.e. you just specify host:), it defaults to 5432. easy as that ✨


🌈 ENVIRONMENT 🌈

  • PGCLUSTER β€” if $PGCLUSTER is set, its value (of the form version/cluster) specifies the desired cluster, similar to the --cluster option. however, if --cluster is specified, it overrides the value of $PGCLUSTER. the explicit one wins, always πŸ‘‘
  • PG_CLUSTER_CONF_ROOT β€” this specifies an alternative base directory for cluster configurations. it's usually /etc/postgresql/, but for testing/development purposes you can change this to point to, e.g., your home directory β€” so that you can use the postgresql-common tools without root privileges. main character energy, no sudo required 🧚
  • PGSYSCONFDIR β€” this is the location of PostgreSQL's and postgresql-common's global configuration (e.g. pg_service.conf, user_clusters(5)). the default is /etc/postgresql-common/. πŸ“

πŸŽ€ FILES πŸŽ€

  • /etc/postgresql-common/user_clusters β€” stores the default cluster and database for users and groups, as set by the administrators. the adult-in-the-room file πŸ’Ό
  • $HOME/.postgresqlrc β€” stores defaults set by the user himself. your personal little vibe file πŸ’–

⭐ SEE ALSO ⭐

user_clusters(5), postgresqlrc(5) β€” go read your other faves too, they're all connected iykyk 🌸


πŸ‘‘ AUTHOR πŸ‘‘

Martin Pitt <mpitt@debian.org> β€” thank you for your service legend πŸ«‘πŸ’–


and that's a wrap bestie!! this page came to you straight from Debian, dated 2026-07-28, filed under PG_WRAPPER(1). now go connect to something and slay πŸ’…βœ¨πŸ”₯

πŸ“¦ where this page comes from