If this begins with a slash, it specifies Unix-domain
communication rather than TCP/IP communication; the value is the
name of the directory in which the socket file is stored. The
- default is to connect to a Unix-domain socket in
- socket>>
+ default behavior when host is not specified
+ is to connect to a Unix-domain
+ socket
Unix domain socket>> in
+ /tmp (or whatever socket directory was specified
+ when
PostgreSQL> was built). On machines without
+ Unix-domain sockets, the default is to connect to localhost>.
Without either a host name or host address,
libpq will connect using a
- local Unix domain socket.
+ local Unix-domain socket; or on machines without Unix-domain
+ sockets, it will attempt to connect to localhost>.
these parameters, under PQconnectdb above, for details
on their interaction.
+When neither PGHOST nor PGHOSTADDR is set,
+the default behavior is to connect using a local Unix-domain socket; or on
+machines without Unix-domain sockets,
libpq will
+attempt to connect to localhost>.
+
- Specifies the TCP port or the local Unix domain
+ Specifies the TCP port or the local Unix-domain
socket file extension on which the server is listening for
connections. Defaults to the value of the PGPORT
environment variable or, if not set, to the port specified at
, , , and
respectively. If an argument is found that does
not belong to any option it will be interpreted as the database name
- (or the user name, if the database name is also given). Not all
- these options are required, defaults do apply. If you omit the host
- name,
psql> will connect via a Unix domain socket
- to a server on the local host, or via TCP/IP to localhost> on machines
- that don't have Unix domain sockets. The default port number is compile-time determined.
+ (or the user name, if the database name is already given). Not all
+ these options are required; there are useful defaults. If you omit the host
+ name,
psql> will connect via a Unix-domain socket
+ to a server on the local host, or via TCP/IP to localhost> on
+ machines that don't have Unix-domain sockets. 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
Unix user name, as is the default database name. Note that you can't
just connect to any database under any user name. Your database
- administrator should have informed you about your access rights. To
- save you some typing you can also set the environment variables
+ administrator should have informed you about your access rights.
+
+
+ When the defaults aren't quite right, you can save yourself
+ some typing by setting the environment variables
PGDATABASE, PGHOST,
- PGPORT and PGUSER to appropriate
+ PGPORT and/or PGUSER to appropriate
values.
*
* Copyright (c) 2000-2004, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.106 2004/11/27 18:51:07 tgl Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.107 2004/12/28 23:17:41 tgl Exp $
*/
#include "postgres_fe.h"
pset.getPassword = false;
#endif
-#ifndef HAVE_UNIX_SOCKETS
- /* default to localhost on platforms without unix sockets */
- options.host = "localhost";
-#endif
-
parse_psql_options(argc, argv, &options);
if (!pset.popt.topt.fieldSep)
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.292 2004/12/02 23:20:19 tgl Exp $
+ * $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.293 2004/12/28 23:17:54 tgl Exp $
*
*-------------------------------------------------------------------------
*/
char portstr[128];
struct addrinfo *addrs = NULL;
struct addrinfo hint;
- const char *node = NULL;
+ const char *node;
int ret;
if (!conn)
node = conn->pghost;
hint.ai_family = AF_UNSPEC;
}
-#ifdef HAVE_UNIX_SOCKETS
else
{
+#ifdef HAVE_UNIX_SOCKETS
/* pghostaddr and pghost are NULL, so use Unix domain socket */
node = NULL;
hint.ai_family = AF_UNIX;
UNIXSOCK_PATH(portstr, portnum, conn->pgunixsocket);
- }
+#else
+ /* Without Unix sockets, default to localhost instead */
+ node = "localhost";
+ hint.ai_family = AF_UNSPEC;
#endif /* HAVE_UNIX_SOCKETS */
+ }
/* Use getaddrinfo_all() to resolve the address */
ret = getaddrinfo_all(node, portstr, &hint, &addrs);