diff --git a/configs/res_pgsql.conf.sample b/configs/res_pgsql.conf.sample
index cfb8538bd857b49c9baf54ff8497a9a434d265c3..b889244a7e7214623fde1954742c451e43e8605d 100644
--- a/configs/res_pgsql.conf.sample
+++ b/configs/res_pgsql.conf.sample
@@ -13,6 +13,13 @@ dbname=asterisk
 dbuser=asterisk
 dbpass=password
 ;
+; dbsock is specified as the directory where the socket file may be found. The
+; actual socket is constructed as a combination of dbsock and dbport.  For
+; example, the values of '/tmp' and '5432', respectively, will specify a socket
+; file of '/tmp/.s.PGSQL.5432'.
+; 
+;dbsock=/tmp
+;
 ; requirements - At startup, each realtime family will make requirements
 ; on the backend.  There are several strategies for handling requirements:
 ; warn        - Warn if the required column does not exist.
diff --git a/res/res_config_pgsql.c b/res/res_config_pgsql.c
index e4bffd307dada921ed1825a2cbe7eebf7cec8cb5..9a6650fa42d86faae1bd5b1aedf954f5fc4e82fb 100644
--- a/res/res_config_pgsql.c
+++ b/res/res_config_pgsql.c
@@ -1391,8 +1391,8 @@ static int parse_config(int is_reload)
 		/* No socket needed */
 	} else if (!(s = ast_variable_retrieve(config, "general", "dbsock"))) {
 		ast_log(LOG_WARNING,
-				"PostgreSQL RealTime: No database socket found, using '/tmp/pgsql.sock' as default.\n");
-		strcpy(dbsock, "/tmp/pgsql.sock");
+				"PostgreSQL RealTime: No database socket found, using '/tmp/.s.PGSQL.%d' as default.\n", dbport);
+		strcpy(dbsock, "/tmp");
 	} else {
 		ast_copy_string(dbsock, s, sizeof(dbsock));
 	}
@@ -1453,7 +1453,7 @@ static int pgsql_reconnect(const char *database)
 		struct ast_str *connInfo = ast_str_create(32);
 
 		ast_str_set(&connInfo, 0, "host=%s port=%d dbname=%s user=%s",
-			dbhost, dbport, my_database, dbuser);
+			S_OR(dbhost, dbsock), dbport, my_database, dbuser);
 		if (!ast_strlen_zero(dbpass))
 			ast_str_append(&connInfo, 0, " password=%s", dbpass);