# postgresql-common - man(7) - [phpMan]

[_PG_WRAPPER_(1)](https://www.chedong.com/phpMan.php/man/PGWRAPPER/1/markdown)                     Debian PostgreSQL infrastructure                     [_PG_WRAPPER_(1)](https://www.chedong.com/phpMan.php/man/PGWRAPPER/1/markdown)

## NAME
       pg_wrapper - wrapper for PostgreSQL client commands

## SYNOPSIS
       _client-program_ [**--cluster _**version_/_cluster_] [...]

       (_client-program_: **psql**, **createdb**, **dropuser**, and all other client programs installed in
       /usr/lib/postgresql/_version_/bin).

## DESCRIPTION
       This program is run only as a link to names which correspond to PostgreSQL programs in
       /usr/lib/postgresql/_version_/bin. It determines the configured cluster and database for the
       user and calls the appropriate version of the desired program to connect to that cluster and
       database, supplying any specified options to that command.

       The target cluster is selected by the following means, 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)](https://www.chedong.com/phpMan.php/man/postgresqlrc/5/markdown)), if that file exists

       •   matching  entry  in  /etc/postgresql-common/user_clusters (see [**user_clusters**(5)](https://www.chedong.com/phpMan.php/man/userclusters/5/markdown)), if that
           file exists

       •   If only one cluster exists on the local system, that one will be selected.

       •   If several clusters exist on the local system, the one listening on the default port 5432
           will be selected.

       If none of these rules match, **pg_wrapper **does not  set  any  environment  variables  and  the
       program  called  will  likely  error  out  with  a message like "could not connect to server:
       Connection refused".

       For **psql**, **pg_archivecleanup**, and **pg_isready**, **pg_wrapper **will always use the binary  from  the
       newest  PostgreSQL  version  installed,  as  these  are downwards compatible.  If the cluster
       version is older than 9.2, the newest considered binary version is 14.

       Note that **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 in a place that pg_wrapper cannot 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**.

## OPTIONS
       **--cluster _**version_**/_**cluster_
       **--cluster _**version_**/_**host_**:**[_port_]
           _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.

## 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.

       **PG_CLUSTER_CONF_ROOT**
           This  specifies an alternative base directory for cluster configurations. This is 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.

       **PGSYSCONFDIR**
           This  is the location of PostgreSQL's and postgresql-common's global configuration (e. g.
           pg_service.conf, [**user_clusters**(5)](https://www.chedong.com/phpMan.php/man/userclusters/5/markdown)). 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.

       $HOME/.postgresqlrc
           stores defaults set by the user himself.

## SEE ALSO
       [**user_clusters**(5)](https://www.chedong.com/phpMan.php/man/userclusters/5/markdown), [**postgresqlrc**(5)](https://www.chedong.com/phpMan.php/man/postgresqlrc/5/markdown)

## AUTHOR
       Martin Pitt <<mpitt@debian.org>>

Debian                                       2024-08-09                                [_PG_WRAPPER_(1)](https://www.chedong.com/phpMan.php/man/PGWRAPPER/1/markdown)
