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
--hostoption - explicit specification with the
--clusteroption - if the
PGHOSTenvironment variable is set, no further cluster selection is performed. the default PostgreSQL version and port number (from the command line, the environment variablePGPORT, or default5432) will be used. - explicit specification with the
PGCLUSTERenvironment variable - if a port is given (either via
-p,--port, orPGPORT), and no host is given, the local cluster matching that port number is used - matching entry in
~/.postgresqlrc(seepostgresqlrc(5)), if that file exists - matching entry in
/etc/postgresql-common/user_clusters(seeuser_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
5432will 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 π
--clusterversion/cluster--clusterversion/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$PGCLUSTERis set, its value (of the form version/cluster) specifies the desired cluster, similar to the--clusteroption. however, if--clusteris 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
- ubuntu stonking: postgresql-client-common 293ubuntu1 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms