specified, or is empty, is to connect to a Unix-domain
socket<indexterm><primary>Unix domain socket</primary></indexterm> in
<filename>/tmp</filename> (or whatever socket directory was specified
- when <productname>PostgreSQL</productname> was built). On Windows and
- on machines without Unix-domain sockets, the default is to connect to
- <literal>localhost</literal>.
+ when <productname>PostgreSQL</productname> was built). On Windows,
+ the default is to connect to <literal>localhost</literal>.
</para>
<para>
A comma-separated list of host names is also accepted, in which case
<para>
Without either a host name or host address,
<application>libpq</application> will connect using a local
- Unix-domain socket; or on Windows and on machines without Unix-domain
- sockets, it will attempt to connect to <literal>localhost</literal>.
+ Unix-domain socket; or on Windows, it will attempt to connect to
+ <literal>localhost</literal>.
</para>
</listitem>
</varlistentry>
of these options are required; there are useful defaults. If you omit the host
name, <application>psql</application> will connect via a Unix-domain socket
to a server on the local host, or via TCP/IP to <literal>localhost</literal> on
- machines that don't have Unix-domain sockets. The default port number is
+ Windows. The default port number is
determined at compile time.
Since the database server uses the same default, you will not have
to specify the port in most cases. The default user name is your
token = linitial(tokens);
if (strcmp(token->string, "local") == 0)
{
-#ifdef HAVE_UNIX_SOCKETS
parsedline->conntype = ctLocal;
-#else
- ereport(elevel,
- (errcode(ERRCODE_CONFIG_FILE_ERROR),
- errmsg("local connections are not supported by this build"),
- errcontext("line %d of configuration file \"%s\"",
- line_num, HbaFileName)));
- *err_msg = "local connections are not supported by this build";
- return NULL;
-#endif
}
else if (strcmp(token->string, "host") == 0 ||
strcmp(token->string, "hostssl") == 0 ||
static int internal_putbytes(const char *s, size_t len);
static int internal_flush(void);
-#ifdef HAVE_UNIX_SOCKETS
static int Lock_AF_UNIX(const char *unixSocketDir, const char *unixSocketPath);
static int Setup_AF_UNIX(const char *sock_path);
-#endif /* HAVE_UNIX_SOCKETS */
static const PQcommMethods PqCommSocketMethods = {
socket_comm_reset,
struct addrinfo hint;
int listen_index = 0;
int added = 0;
-
-#ifdef HAVE_UNIX_SOCKETS
char unixSocketPath[MAXPGPATH];
-#endif
#if !defined(WIN32) || defined(IPV6_V6ONLY)
int one = 1;
#endif
hint.ai_flags = AI_PASSIVE;
hint.ai_socktype = SOCK_STREAM;
-#ifdef HAVE_UNIX_SOCKETS
if (family == AF_UNIX)
{
/*
service = unixSocketPath;
}
else
-#endif /* HAVE_UNIX_SOCKETS */
{
snprintf(portNumberStr, sizeof(portNumberStr), "%d", portNumber);
service = portNumberStr;
familyDesc = _("IPv6");
break;
#endif
-#ifdef HAVE_UNIX_SOCKETS
case AF_UNIX:
familyDesc = _("Unix");
break;
-#endif
default:
snprintf(familyDescBuf, sizeof(familyDescBuf),
_("unrecognized address family %d"),
}
/* set up text form of address for log messages */
-#ifdef HAVE_UNIX_SOCKETS
if (addr->ai_family == AF_UNIX)
addrDesc = unixSocketPath;
else
-#endif
{
pg_getnameinfo_all((const struct sockaddr_storage *) addr->ai_addr,
addr->ai_addrlen,
continue;
}
-#ifdef HAVE_UNIX_SOCKETS
if (addr->ai_family == AF_UNIX)
{
if (Setup_AF_UNIX(service) != STATUS_OK)
break;
}
}
-#endif
/*
* Select appropriate accept-queue length limit. PG_SOMAXCONN is only
continue;
}
-#ifdef HAVE_UNIX_SOCKETS
if (addr->ai_family == AF_UNIX)
ereport(LOG,
(errmsg("listening on Unix socket \"%s\"",
addrDesc)));
else
-#endif
ereport(LOG,
/* translator: first %s is IPv4 or IPv6 */
(errmsg("listening on %s address \"%s\", port %d",
}
-#ifdef HAVE_UNIX_SOCKETS
-
/*
* Lock_AF_UNIX -- configure unix socket file path
*/
}
return STATUS_OK;
}
-#endif /* HAVE_UNIX_SOCKETS */
/*
}
#endif
-#ifdef HAVE_UNIX_SOCKETS
if (Unix_socket_directories)
{
char *rawstring;
list_free_deep(elemlist);
pfree(rawstring);
}
-#endif
/*
* check that we have some socket to listen on
GUC_LIST_INPUT | GUC_LIST_QUOTE | GUC_SUPERUSER_ONLY
},
&Unix_socket_directories,
-#ifdef HAVE_UNIX_SOCKETS
DEFAULT_PGSOCKET_DIR,
-#else
- "",
-#endif
NULL, NULL, NULL
},
static char **replace_token(char **lines,
const char *token, const char *replacement);
-#ifndef HAVE_UNIX_SOCKETS
-static char **filter_lines_with_token(char **lines, const char *token);
-#endif
static char **readfile(const char *path);
static void writefile(char *path, char **lines);
static FILE *popen_check(const char *command, const char *mode);
return result;
}
-/*
- * make a copy of lines without any that contain the token
- *
- * a sort of poor man's grep -v
- */
-#ifndef HAVE_UNIX_SOCKETS
-static char **
-filter_lines_with_token(char **lines, const char *token)
-{
- int numlines = 1;
- int i,
- src,
- dst;
- char **result;
-
- for (i = 0; lines[i]; i++)
- numlines++;
-
- result = (char **) pg_malloc(numlines * sizeof(char *));
-
- for (src = 0, dst = 0; src < numlines; src++)
- {
- if (lines[src] == NULL || strstr(lines[src], token) == NULL)
- result[dst++] = lines[src];
- }
-
- return result;
-}
-#endif
-
/*
* get the lines from a text file
*/
n_buffers * (BLCKSZ / 1024));
conflines = replace_token(conflines, "#shared_buffers = 128MB", repltok);
-#ifdef HAVE_UNIX_SOCKETS
snprintf(repltok, sizeof(repltok), "#unix_socket_directories = '%s'",
DEFAULT_PGSOCKET_DIR);
-#else
- snprintf(repltok, sizeof(repltok), "#unix_socket_directories = ''");
-#endif
conflines = replace_token(conflines, "#unix_socket_directories = '/tmp'",
repltok);
conflines = readfile(hba_file);
-#ifndef HAVE_UNIX_SOCKETS
- conflines = filter_lines_with_token(conflines, "@remove-line-for-nolocal@");
-#else
conflines = replace_token(conflines, "@remove-line-for-nolocal@", "");
-#endif
#ifdef HAVE_IPV6
void
get_sock_dir(ClusterInfo *cluster, bool live_check)
{
-#if defined(HAVE_UNIX_SOCKETS) && !defined(WIN32)
+#if !defined(WIN32)
if (!live_check)
cluster->sockdir = user_opts.socketdir;
else
pg_log(PG_WARNING, "user-supplied old port number %hu corrected to %hu",
orig_port, cluster->port);
}
-#else /* !HAVE_UNIX_SOCKETS || WIN32 */
+#else /* WIN32 */
cluster->sockdir = NULL;
#endif
}
socket_string[0] = '\0';
-#if defined(HAVE_UNIX_SOCKETS) && !defined(WIN32)
+#if !defined(WIN32)
/* prevent TCP/IP connections, restrict socket access */
strcat(socket_string,
" -c listen_addresses='' -c unix_socket_permissions=0700");
-#ifdef HAVE_UNIX_SOCKETS
static int getaddrinfo_unix(const char *path,
const struct addrinfo *hintsp,
struct addrinfo **result);
char *node, int nodelen,
char *service, int servicelen,
int flags);
-#endif
/*
/* not all versions of getaddrinfo() zero *result on failure */
*result = NULL;
-#ifdef HAVE_UNIX_SOCKETS
if (hintp->ai_family == AF_UNIX)
return getaddrinfo_unix(servname, hintp, result);
-#endif
/* NULL has special meaning to getaddrinfo(). */
rc = getaddrinfo((!hostname || hostname[0] == '\0') ? NULL : hostname,
void
pg_freeaddrinfo_all(int hint_ai_family, struct addrinfo *ai)
{
-#ifdef HAVE_UNIX_SOCKETS
if (hint_ai_family == AF_UNIX)
{
/* struct was built by getaddrinfo_unix (see pg_getaddrinfo_all) */
}
}
else
-#endif /* HAVE_UNIX_SOCKETS */
{
/* struct was built by getaddrinfo() */
if (ai != NULL)
{
int rc;
-#ifdef HAVE_UNIX_SOCKETS
if (addr && addr->ss_family == AF_UNIX)
rc = getnameinfo_unix((const struct sockaddr_un *) addr, salen,
node, nodelen,
service, servicelen,
flags);
else
-#endif
rc = getnameinfo((const struct sockaddr *) addr, salen,
node, nodelen,
service, servicelen,
}
-#if defined(HAVE_UNIX_SOCKETS)
-
/* -------
* getaddrinfo_unix - get unix socket info using IPv6-compatible API
*
return 0;
}
-#endif /* HAVE_UNIX_SOCKETS */
#define HAVE_SYMLINK 1
#endif
-/* Interfaces that we assume that all systems have. */
-#define HAVE_UNIX_SOCKETS 1
-
#endif /* PG_PORT_H */
else if (ch->host != NULL && ch->host[0] != '\0')
{
ch->type = CHT_HOST_NAME;
-#ifdef HAVE_UNIX_SOCKETS
if (is_unixsock_path(ch->host))
ch->type = CHT_UNIX_SOCKET;
-#endif
}
else
{
* This bit selects the default host location. If you change
* this, see also pg_regress.
*/
-#ifdef HAVE_UNIX_SOCKETS
if (DEFAULT_PGSOCKET_DIR[0])
{
ch->host = strdup(DEFAULT_PGSOCKET_DIR);
ch->type = CHT_UNIX_SOCKET;
}
else
-#endif
{
ch->host = strdup(DefaultHost);
ch->type = CHT_HOST_NAME;
static void
emitHostIdentityInfo(PGconn *conn, const char *host_addr)
{
-#ifdef HAVE_UNIX_SOCKETS
if (conn->raddr.addr.ss_family == AF_UNIX)
{
char service[NI_MAXHOST];
service);
}
else
-#endif /* HAVE_UNIX_SOCKETS */
{
const char *displayed_host;
const char *displayed_port;
"%s\n",
SOCK_STRERROR(errorno, sebuf, sizeof(sebuf)));
-#ifdef HAVE_UNIX_SOCKETS
if (conn->raddr.addr.ss_family == AF_UNIX)
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("\tIs the server running locally and accepting connections on that socket?\n"));
else
-#endif
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("\tIs the server running on that host and accepting TCP/IP connections?\n"));
}
break;
case CHT_UNIX_SOCKET:
-#ifdef HAVE_UNIX_SOCKETS
conn->addrlist_family = hint.ai_family = AF_UNIX;
UNIXSOCK_PATH(portstr, thisport, ch->host);
if (strlen(portstr) >= UNIXSOCK_PATH_BUFLEN)
portstr, gai_strerror(ret));
goto keep_going;
}
-#else
- Assert(false);
-#endif
break;
}
static FILE *logfile;
static char *difffilename;
static const char *sockdir;
-#ifdef HAVE_UNIX_SOCKETS
static const char *temp_sockdir;
static char sockself[MAXPGPATH];
static char socklock[MAXPGPATH];
-#endif
static _resultmap *resultmap = NULL;
}
}
-#ifdef HAVE_UNIX_SOCKETS
/*
* Remove the socket temporary directory. pg_regress never waits for a
* postmaster exit, so it is indeterminate whether the postmaster has yet to
return temp_sockdir;
}
-#endif /* HAVE_UNIX_SOCKETS */
/*
* Check whether string matches pattern
/* PGPORT, see below */
/* PGHOST, see below */
-#ifdef HAVE_UNIX_SOCKETS
if (hostname != NULL)
setenv("PGHOST", hostname, 1);
else
sockdir = make_temp_sockdir();
setenv("PGHOST", sockdir, 1);
}
-#else
- Assert(hostname != NULL);
- setenv("PGHOST", hostname, 1);
-#endif
unsetenv("PGHOSTADDR");
if (port != -1)
{
if (!pghost)
{
/* Keep this bit in sync with libpq's default host location: */
-#ifdef HAVE_UNIX_SOCKETS
if (DEFAULT_PGSOCKET_DIR[0])
/* do nothing, we'll print "Unix socket" below */ ;
else
-#endif
pghost = "localhost"; /* DefaultHost in fe-connect.c */
}
atexit(stop_postmaster);
-#if !defined(HAVE_UNIX_SOCKETS)
- use_unix_sockets = false;
-#elif defined(WIN32)
+#if defined(WIN32)
/*
- * We don't use Unix-domain sockets on Windows by default, even if the
- * build supports them. (See comment at remove_temp() for a reason.)
- * Override at your own risk.
+ * We don't use Unix-domain sockets on Windows by default (see comment at
+ * remove_temp() for a reason). Override at your own risk.
*/
use_unix_sockets = getenv("PG_TEST_USE_UNIX_SOCKETS") ? true : false;
#else
/*
* To reduce chances of interference with parallel installations, use
* a port number starting in the private range (49152-65535)
- * calculated from the version number. This aids !HAVE_UNIX_SOCKETS
+ * calculated from the version number. This aids non-Unix socket mode
* systems; elsewhere, the use of a private socket directory already
* prevents interference.
*/
snprintf(buf, sizeof(buf), "%s/data", temp_instance);
config_sspi_auth(buf, NULL);
}
-#elif !defined(HAVE_UNIX_SOCKETS)
-#error Platform has no means to secure the test installation.
#endif
/*