File postgresql-var-run-socket.patch of Package postgresql12.14323

Change the built-in default socket directory to be /var/run/postgresql.
For backwards compatibility with (probably non-libpq-based) clients that
might still expect to find the socket in /tmp, also create a socket in
/tmp.  This is to resolve communication problems with clients operating
under systemd's PrivateTmp environment, which won't be using the same
global /tmp directory as the server; see bug #825448.

Note that we apply the socket directory change at the level of the
hard-wired defaults in the C code, not by just twiddling the setting in
postgresql.conf.sample; this is so that the change will take effect on
server package update, without requiring any existing postgresql.conf
to be updated.  (Of course, a user who dislikes this behavior can still
override it via postgresql.conf.)

Index: src/bin/pg_upgrade/
--- src/bin/pg_upgrade/
+++ src/bin/pg_upgrade/
@@ -64,7 +64,9 @@ case $testhost in
-POSTMASTER_OPTS="-F -c listen_addresses=\"$LISTEN_ADDRESSES\" -k \"$PGHOST\""
+# we want the Unix sockets in $temp_root
+POSTMASTER_OPTS="-F -c listen_addresses=\"$LISTEN_ADDRESSES\" -k \"$PGHOST\" -c unix_socket_directories='$PGHOST'"
 export PGHOST
 # don't rely on $PWD here, as old shells don't set it
Index: src/backend/utils/misc/guc.c
--- src/backend/utils/misc/guc.c.orig
+++ src/backend/utils/misc/guc.c
@@ -3954,7 +3954,7 @@ static struct config_string ConfigureNam
Index: src/bin/initdb/initdb.c
--- src/bin/initdb/initdb.c.orig
+++ src/bin/initdb/initdb.c
@@ -1103,7 +1103,7 @@ setup_config(void)
 	snprintf(repltok, sizeof(repltok), "#unix_socket_directories = '%s'",
+			 DEFAULT_PGSOCKET_DIR ", /tmp");
 	snprintf(repltok, sizeof(repltok), "#unix_socket_directories = ''");
Index: src/include/pg_config_manual.h
--- src/include/pg_config_manual.h.orig
+++ src/include/pg_config_manual.h
@@ -179,7 +179,7 @@
  * here's where to twiddle it.  You can also override this at runtime
  * with the postmaster's -k switch.
-#define DEFAULT_PGSOCKET_DIR  "/tmp"
+#define DEFAULT_PGSOCKET_DIR  "/var/run/postgresql"
  * This is the default event source for Windows event log.