--- /dev/null
+diff -urpa postgresql-9.5.14.orig/src/bin/pg_config/pg_config.c postgresql-9.5.14/src/bin/pg_config/pg_config.c
+--- postgresql-9.5.14.orig/src/bin/pg_config/pg_config.c 2018-08-23 13:41:50.944654284 +0000
++++ postgresql-9.5.14/src/bin/pg_config/pg_config.c 2018-08-23 13:42:31.233653830 +0000
+@@ -26,6 +26,8 @@
+
+ #include "port.h"
+
++#include "../port/pg_config_paths.h"
++
+ static const char *progname;
+ static char mypath[MAXPGPATH];
+
+@@ -481,7 +483,6 @@ main(int argc, char **argv)
+ {
+ int i;
+ int j;
+- int ret;
+
+ set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_config"));
+
+@@ -497,13 +498,7 @@ main(int argc, char **argv)
+ }
+ }
+
+- ret = find_my_exec(argv[0], mypath);
+-
+- if (ret)
+- {
+- fprintf(stderr, _("%s: could not find own program executable\n"), progname);
+- exit(1);
+- }
++ snprintf(mypath, sizeof(mypath), "%s/%s", PGBINDIR, progname);
+
+ /* no arguments -> print everything */
+ if (argc < 2)
+diff -urpa postgresql-9.5.14.orig/src/Makefile.global.in postgresql-9.5.14/src/Makefile.global.in
+--- postgresql-9.5.14.orig/src/Makefile.global.in 2018-08-23 13:41:50.825654285 +0000
++++ postgresql-9.5.14/src/Makefile.global.in 2018-08-23 13:42:31.233653830 +0000
+@@ -120,7 +120,7 @@ libdir := @libdir@
+ pkglibdir = $(libdir)
+ ifeq "$(findstring pgsql, $(pkglibdir))" ""
+ ifeq "$(findstring postgres, $(pkglibdir))" ""
+-override pkglibdir := $(pkglibdir)/postgresql
++override pkglibdir := $(pkglibdir)/postgresql/@PG_MAJORVERSION@/lib
+ endif
+ endif
+
+@@ -168,7 +168,7 @@ endif # PGXS
+
+ # These derived path variables aren't separately configurable.
+
+-includedir_server = $(pkgincludedir)/server
++includedir_server = $(pkgincludedir)/@PG_MAJORVERSION@/server
+ includedir_internal = $(pkgincludedir)/internal
+ pgxsdir = $(pkglibdir)/pgxs
+
--- /dev/null
+diff -urpa postgresql-9.5.14.orig/src/bin/pg_upgrade/option.c postgresql-9.5.14/src/bin/pg_upgrade/option.c
+--- postgresql-9.5.14.orig/src/bin/pg_upgrade/option.c 2018-08-23 13:18:56.785669756 +0000
++++ postgresql-9.5.14/src/bin/pg_upgrade/option.c 2018-08-23 13:32:12.040660802 +0000
+@@ -462,6 +462,11 @@ get_sock_dir(ClusterInfo *cluster, bool
+ cluster->sockdir = pg_malloc(MAXPGPATH);
+ if (!getcwd(cluster->sockdir, MAXPGPATH))
+ pg_fatal("cannot find current directory\n");
++#ifndef UNIX_PATH_MAX
++#define UNIX_PATH_MAX 108
++#endif
++ if (strlen(cluster->sockdir) >= UNIX_PATH_MAX - sizeof(".s.PGSQL.50432"))
++ strcpy(cluster->sockdir, "/tmp"); /* fall back to tmp */
+ }
+ else
+ {
+@@ -487,7 +492,6 @@ get_sock_dir(ClusterInfo *cluster, bool
+ {
+ if (fgets(line, sizeof(line), fp) == NULL)
+ pg_fatal("Cannot read line %d from %s: %m\n", lineno, filename);
+-
+ /* potentially overwrite user-supplied value */
+ if (lineno == LOCK_FILE_LINE_PORT)
+ sscanf(line, "%hu", &old_cluster.port);
+diff -urpa postgresql-9.5.14.orig/src/include/pg_config_manual.h postgresql-9.5.14/src/include/pg_config_manual.h
+--- postgresql-9.5.14.orig/src/include/pg_config_manual.h 2018-08-23 13:18:56.652669757 +0000
++++ postgresql-9.5.14/src/include/pg_config_manual.h 2018-08-23 13:32:12.040660802 +0000
+@@ -169,7 +169,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.