--- /dev/null
+diff -urpa postgresql-9.6.10.orig/src/bin/pg_upgrade/option.c postgresql-9.6.10/src/bin/pg_upgrade/option.c
+--- postgresql-9.6.10.orig/src/bin/pg_upgrade/option.c 2018-08-22 20:58:08.789332330 +0000
++++ postgresql-9.6.10/src/bin/pg_upgrade/option.c 2018-08-22 21:05:48.468327154 +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.6.10.orig/src/include/pg_config_manual.h postgresql-9.6.10/src/include/pg_config_manual.h
+--- postgresql-9.6.10.orig/src/include/pg_config_manual.h 2018-08-22 20:58:08.658332331 +0000
++++ postgresql-9.6.10/src/include/pg_config_manual.h 2018-08-22 20:58:43.807331936 +0000
+@@ -182,7 +182,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.