For the PostgreSQL source code, the default is /tmp
.
However, this path is not nailed, it is a constant in the DEFAULT_PGSOCKET_DIR
code and some accompanying packages prefer to change the path to the preferred one for the distributor. In particular, packages for Ubuntu
and Debian
are usually built with this path changed to /var/run/postgresql/
.
And this change does not pose any problems, but only as long as your applications using the database are compiled with the same DEFAULT_PGSOCKET_DIR
. If the libpq
library used on the system was compiled with one DEFAULT_PGSOCKET_DIR
, and a DBMS with another, then you will receive such errors. Therefore, it is best to check which particular packages you use for the DBMS itself, and which applications and libpq
. Obviously they are compiled with different settings, possibly derived from different repositories. As a postgresql DBA, I recommend using the PostgreSQL Global Development Group repositories.
Another possibility, as already noted, is to configure the DBMS to listen to the socket not at the address with which it was compiled, but with the specified one manually. The configuration option unix_socket_directories
is responsible for unix_socket_directories
( here you can see that the default value is the constant DEFAULT_PGSOCKET_DIR
)
Where is the postgresql.conf
configuration file itself - the question is separate and specific again for the preferences of the person who collected the DBMS. Although this is not an assembly option (the name postgresql.conf
hard-coded in the paths), it is located in a directory called $PGDATA
. That is, anywhere, if only this directory was specified during initialization and then at each start of the DBMS. As well as the configuration file can be located anywhere if the launch option config_file to specify the path to it when you start the database.
In ubuntu
and debian
usually laid out like this: - configuration files in /etc/postgresql/(номер major версии postgresql)/main
- $PGDATA
is located along the path /var/lib/postgresql/(номер major версии postgresql)/main
In CentOS, for example, $PGDATA
is located in /var/lib/pgsql/(номер major версии postgresql)/data
, the same configuration file.
But if, as in your case, there is an inconsistent state of installed packages, then there may be surprises. It's guaranteed to find out from which configuration file PostgreSQL started working by request.
show config_file;
In response, there will be a path to the configuration file. It remains only to bring the unix_socket_directories
option to the unix_socket_directories = '/var/run/postgresql/'
and restart the DBMS: unix_socket_directories
can be changed only when restarting the entire DBMS.
PS: it is worth commenting that before release 9.3 the option was called unix_socket_directory
. Modern unix_socket_directories
allows listing of several directories separated by commas.