-If your site administrator has not set things up in the
-default way, you may have some more work to do. For example, if the database
- server machine is a remote machine, you
-will need to set the
PGHOST environment variable to the name
-of the database server machine. The environment variable
-
PGPORT may also have to be set. The bottom line is this: if
-you try to start an application program and it complains
-that it cannot connect to the
postmaster,
- you should immediately consult your site administrator to make sure that your
-environment is properly set up.
-
+
+If your site administrator has not set things up in the default way,
+you may have some more work to do. For example, if the database server
+machine is a remote machine, you will need to set the
+
PGHOST environment variable to the name of the
+database server machine. The environment variable
+
PGPORT or
PGUNIXSOCKET may also have
+to be set. The bottom line is this: if you try to start an application
+program and it complains that it cannot connect to the
+
postmaster, you should immediately consult
+your site administrator to make sure that your environment is properly
+set up.
backend.
+
+ PGUNIXSOCKET sets the full Unix domain socket
+ file name for communicating with the
Postgres
+ backend.
+
+
PGDATABASE sets the default
+
+ unixsocket
+
+ Full path to Unix-domain socket file to connect to at the server host.
+
+
+
+
dbname
+
+PQunixsocket
+ Returns the name of the Unix-domain socket of the connection.
+
+char *PQunixsocket(const PGconn *conn)
+
+
+
+
PQtty
+PGPORT sets the default port or local Unix domain socket
+file extension for communicating with the
Postgres
+backend.
+
+
+
PGDATABASE sets the default
+
+ -k, --unixsocket path
+
+ Specifies the Unix-domain socket on which the
+ Without this option, the socket is created in /tmp
+ based on the port number.
+
+
+
+
-U, --username username
+
+ -k, --unixsocket path
+
+ Specifies the Unix-domain socket on which the
+ Without this option, the socket is created in /tmp
+ based on the port number.
+
+
+
+
-U, --username username
+
+ -k, --unixsocket path
+
+ Specifies the Unix-domain socket on which the
+ Without this option, the socket is created in /tmp
+ based on the port number.
+
+
+
+
-e, --echo
+
+ -k, --unixsocket path
+
+ Specifies the Unix-domain socket on which the
+ Without this option, the socket is created in /tmp
+ based on the port number.
+
+
+
+
-U, --username username
+
+ -k, --unixsocket path
+
+ Specifies the Unix-domain socket on which the
+ Without this option, the socket is created in /tmp
+ based on the port number.
+
+
+
+
-U, --username username
+
+ -k, --unixsocket path
+
+ Specifies the Unix-domain socket on which the
+ Without this option, the socket is created in /tmp
+ based on the port number.
+
+
+
+
-e, --echo
pg_dump [ dbname ]
-pg_dump [ -h host ] [ -p port ]
+pg_dump [ -h host ]
+ [ -k path ]
+ [ -p port ]
[ -t table ]
[ -a ] [ -c ] [ -d ] [ -D ] [ -i ] [ -n ] [ -N ]
[ -o ] [ -s ] [ -u ] [ -v ] [ -x ]
+
+ -k path
+
+ Specifies the local Unix domain socket file path
+ on which the
postmaster
+ is listening for connections.
+ Without this option, the socket path name defaults to
+ the value of the PGUNIXSOCKET environment
+ variable (if set), otherwise it is constructed
+ from the port number.
+
+
+
+
-p port
1999-07-20
-pg_dumpall [ -h host ] [ -p port ] [ -a ] [ -d ] [ -D ] [ -O ] [ -s ] [ -u ] [ -v ] [ -x ] [ --accounts-only ]
+pg_dumpall [ -h host ] [ -k path ] [ -p port ] [ -a ] [ -d ] [ -D ] [ -O ] [ -s ] [ -u ] [ -v ] [ -x ] [ --accounts-only ]
+
+ -k path
+
+ Specifies the local Unix domain socket file path
+ on which the
postmaster
+ is listening for connections.
+ Without this option, the socket path name defaults to
+ the value of the PGUNIXSOCKET environment
+ variable (if set), otherwise it is constructed
+ from the port number.
+
+
+
+
-p port
postmaster [ -B nBuffers ] [ -D DataDir ] [ -N maxBackends ] [ -S ]
- [ -d DebugLevel ] [ -i ] [ -l ]
+ [ -d DebugLevel ]
+ [ -h hostname ] [ -i ]
+ [ -k path ] [ -l ]
[ -o BackendOptions ] [ -p port ] [ -n | -s ]
+
+ -h hostName
+
+ Specifies the TCP/IP hostname or address
+ on which the
postmaster
+ is to listen for connections from frontend applications. Defaults to
+ the value of the
+ PGHOST
+ environment variable, or if PGHOST
+ is not set, then defaults to "all", meaning listen on all configured addresses
+ (including localhost).
+
+ If you use a hostname or address other than "all", do not try to run
+ multiple instances of
postmaster on the
+ same IP address but different ports. Doing so will result in them
+ attempting (incorrectly) to use the same shared memory segments.
+ Also, if you use a hostname other than "all", all of the host's IP addresses
+ on which
postmaster instances are
+ listening must be distinct in the two last octets.
+
+ If you do use "all" (the default), then each instance must listen on a
+ different port (via -p or PGPORT). And, of course, do
+ not try to use both approaches on one host.
+
+
+
+
-i
+
+ -k path
+
+ Specifies the local Unix domain socket path name
+ on which the
postmaster
+ is to listen for connections from frontend applications. Defaults to
+ the value of the
+ PGUNIXSOCKET
+ environment variable, or if PGUNIXSOCKET
+ is not set, then defaults to a file in /tmp
+ constructed from the port number.
+
+ You can use this option to put the Unix-domain socket in a
+ directory that is private to one or more users using Unix
+ directory permissions. This is necessary for securely
+ creating databases automatically on shared machines.
+ In that situation, also disallow all TCP/IP connections
+ initially in pg_hba.conf.
+ If you specify a socket path other than the
+ default then all frontend applications (including
+
psql) must specify the same
+ socket path using either command-line options or
+ PGUNIXSOCKET.
+
+
+
+
-l
+
+ -k, --unixsocket path
+
+ Specifies the Unix-domain socket on which the
+ Without this option, the socket is created in /tmp
+ based on the port number.
+
+
+
+
+
-H, --html
+
+ -k, --unixsocket path
+
+ Specifies the Unix-domain socket on which the
+ Without this option, the socket is created in /tmp
+ based on the port number.
+
+
+
+
-U username
--username username
will need to set the
PGHOST environment
variable to the name
of the database server machine. The environment variable
-
PGPORT may also have to be set. The bottom
- line is this: if
+
PGPORT or PGUNIXSOCKET may also have to be set.
+ The bottom line is this: if
you try to start an application program and it complains
that it cannot connect to the
postmaster,
you should immediately consult your site administrator to make
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: pqcomm.c,v 1.109 2000/11/01 21:14:01 petere Exp $
+ * $Id: pqcomm.c,v 1.110 2000/11/13 15:18:09 momjian Exp $
*
*-------------------------------------------------------------------------
*/
/*
* StreamServerPort -- open a sock stream "listening" port.
*
- * This initializes the Postmaster's connection-accepting port.
+ * This initializes the Postmaster's connection-accepting port fdP.
*
* RETURNS: STATUS_OK or STATUS_ERROR
*/
int
-StreamServerPort(int family, unsigned short portName, int *fdP)
+StreamServerPort(int family, char *hostName, unsigned short portName,
+ char *unixSocketName, int *fdP)
{
SockAddr saddr;
int fd,
#ifdef HAVE_UNIX_SOCKETS
if (family == AF_UNIX)
{
- len = UNIXSOCK_PATH(saddr.un, portName);
+ UNIXSOCK_PATH(saddr.un, portName, unixSocketName);
+ len = UNIXSOCK_LEN(saddr.un);
strcpy(sock_path, saddr.un.sun_path);
/*
* If the socket exists but nobody has an advisory lock on it we
if (family == AF_INET)
{
- saddr.in.sin_addr.s_addr = htonl(INADDR_ANY);
+ /* TCP/IP socket */
+ if (hostName[0] == '\0')
+ saddr.in.sin_addr.s_addr = htonl(INADDR_ANY);
+ else
+ {
+ struct hostent *hp;
+
+ hp = gethostbyname(hostName);
+ if ((hp == NULL) || (hp->h_addrtype != AF_INET))
+ {
+ snprintf(PQerrormsg, PQERRORMSG_LENGTH,
+ "FATAL: StreamServerPort: gethostbyname(%s) failed: %s\n",
+ hostName, hstrerror(h_errno));
+ fputs(PQerrormsg, stderr);
+ pqdebug("%s", PQerrormsg);
+ return STATUS_ERROR;
+ }
+ memmove((char *) &(saddr.in.sin_addr), (char *) hp->h_addr,
+ hp->h_length);
+ }
+
saddr.in.sin_port = htons(portName);
len = sizeof(struct sockaddr_in);
}
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.182 2000/11/12 20:51:51 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.183 2000/11/13 15:18:11 momjian Exp $
*
* NOTES
*
/* The socket number we are listening for connections on */
int PostPortName;
+char * UnixSocketName;
+char * HostName;
/*
* This is a sequence number that indicates how many times we've had to
static void pmdaemonize(int argc, char *argv[]);
static Port *ConnCreate(int serverFd);
static void ConnFree(Port *port);
-static void reset_shared(int port);
+static void reset_shared(unsigned short port);
static void SIGHUP_handler(SIGNAL_ARGS);
static void pmdie(SIGNAL_ARGS);
static void reaper(SIGNAL_ARGS);
* will occur.
*/
opterr = 1;
- while ((opt = getopt(argc, argv, "A:a:B:b:c:D:d:Film:MN:no:p:SsV-:?")) != EOF)
+ while ((opt = getopt(argc, argv, "A:a:B:b:c:D:d:Fh:ik:lm:MN:no:p:SsV-:?")) != EOF)
{
switch(opt)
{
#ifdef HAVE_INT_OPTRESET
optreset = 1;
#endif
- while ((opt = getopt(argc, argv, "A:a:B:b:c:D:d:Film:MN:no:p:SsV-:?")) != EOF)
+ while ((opt = getopt(argc, argv, "A:a:B:b:c:D:d:Fh:ik:lm:MN:no:p:SsV-:?")) != EOF)
{
switch (opt)
{
case 'F':
enableFsync = false;
break;
+ case 'h':
+ HostName = optarg;
+ break;
case 'i':
NetServer = true;
break;
+ case 'k':
+ /* Set PGUNIXSOCKET by hand. */
+ UnixSocketName = optarg;
+ break;
#ifdef USE_SSL
case 'l':
EnableSSL = true;
if (NetServer)
{
- status = StreamServerPort(AF_INET, (unsigned short) PostPortName,
- &ServerSock_INET);
+ status = StreamServerPort(AF_INET, HostName,
+ (unsigned short) PostPortName, UnixSocketName,
+ &ServerSock_INET);
if (status != STATUS_OK)
{
fprintf(stderr, "%s: cannot create INET stream port\n",
}
#ifdef HAVE_UNIX_SOCKETS
- status = StreamServerPort(AF_UNIX, (unsigned short) PostPortName,
- &ServerSock_UNIX);
+ status = StreamServerPort(AF_UNIX, HostName,
+ (unsigned short) PostPortName, UnixSocketName,
+ &ServerSock_UNIX);
if (status != STATUS_OK)
{
fprintf(stderr, "%s: cannot create UNIX stream port\n",
printf(" -d 1-5 debugging level\n");
printf(" -D database directory\n");
printf(" -F turn fsync off\n");
+ printf(" -h hostname specify hostname or IP address\n");
printf(" -i enable TCP/IP connections\n");
+ printf(" -k path specify Unix-domain socket name\n");
#ifdef USE_SSL
printf(" -l enable SSL connections\n");
#endif
free(conn);
}
+/*
+ * get_host_port -- return a pseudo port number (16 bits)
+ * derived from the primary IP address of HostName.
+ */
+static unsigned short
+get_host_port(void)
+{
+ static unsigned short hostPort = 0;
+
+ if (hostPort == 0)
+ {
+ SockAddr saddr;
+ struct hostent *hp;
+
+ hp = gethostbyname(HostName);
+ if ((hp == NULL) || (hp->h_addrtype != AF_INET))
+ {
+ char msg[1024];
+ snprintf(msg, sizeof(msg),
+ "FATAL: get_host_port: gethostbyname(%s) failed: %s\n",
+ HostName, hstrerror(h_errno));
+ fputs(msg, stderr);
+ pqdebug("%s", msg);
+ exit(1);
+ }
+ memmove((char *) &(saddr.in.sin_addr),
+ (char *) hp->h_addr,
+ hp->h_length);
+ hostPort = ntohl(saddr.in.sin_addr.s_addr) & 0xFFFF;
+ }
+
+ return hostPort;
+}
+
/*
* reset_shared -- reset shared memory and semaphores
*/
static void
-reset_shared(int port)
+reset_shared(unsigned short port)
{
+ /*
+ * A typical ipc_key is 5432001, which is port 5432, sequence
+ * number 0, and 01 as the index in IPCKeyGetBufferMemoryKey().
+ * The 32-bit INT_MAX is 2147483 6 47.
+ *
+ * The default algorithm for calculating the IPC keys assumes that all
+ * instances of postmaster on a given host are listening on different
+ * ports. In order to work (prevent shared memory collisions) if you
+ * run multiple PostgreSQL instances on the same port and different IP
+ * addresses on a host, we change the algorithm if you give postmaster
+ * the -h option, or set PGHOST, to a value other than the internal
+ * default.
+ *
+ * If HostName is set, then we generate the IPC keys using the
+ * last two octets of the IP address instead of the port number.
+ * This algorithm assumes that no one will run multiple PostgreSQL
+ * instances on one host using two IP addresses that have the same two
+ * last octets in different class C networks. If anyone does, it
+ * would be rare.
+ *
+ * So, if you use -h or PGHOST, don't try to run two instances of
+ * PostgreSQL on the same IP address but different ports. If you
+ * don't use them, then you must use different ports (via -p or
+ * PGPORT). And, of course, don't try to use both approaches on one
+ * host.
+ */
+
+ if (HostName[0] != '\0')
+ port = get_host_port();
+
ipc_key = port * 1000 + shmem_seq * 100;
CreateSharedMemoryAndSemaphores(ipc_key, MaxBackends);
shmem_seq += 1;
* Support for grand unified configuration scheme, including SET
* command, configuration file, and command line options.
*
- * $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.16 2000/11/09 11:25:59 vadim Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.17 2000/11/13 15:18:12 momjian Exp $
*
* Copyright 2000 by PostgreSQL Global Development Group
* Written by Peter Eisentraut
.
{"unix_socket_group", PGC_POSTMASTER, &Unix_socket_group,
"", NULL},
+ {"unixsocket", PGC_POSTMASTER, &UnixSocketName,
+ "", NULL},
+
+ {"hostname", PGC_POSTMASTER, &HostName,
+ "", NULL},
+
{NULL, 0, NULL, NULL, NULL}
};
int useDB;
char *dbname;
- char *pgport;
char *pghost;
+ char *pgport;
+ char *pgunixsocket;
int ignoreVersion;
int requirePassword;
const char* dbname,
const char* pghost,
const char* pgport,
+ const char* pgunixsocket,
const int reqPwd,
const int ignoreVersion);
if (AH->version < K_VERS_1_3)
die_horribly(AH, "Direct database connections are not supported in pre-1.3 archives");
- ConnectDatabase(AHX, ropt->dbname, ropt->pghost, ropt->pgport,
- ropt->requirePassword, ropt->ignoreVersion);
+ ConnectDatabase(AHX, ropt->dbname, ropt->pghost, ropt->pgport,
+ ropt->pgunixsocket, ropt->requirePassword,
+ ropt->ignoreVersion);
/*
* If no superuser was specified then see if the current user will do...
char *archdbname; /* DB name *read* from archive */
char *pghost;
char *pgport;
+ char *pgunixsocket;
PGconn *connection;
PGconn *blobConnection; /* Connection for BLOB xref */
int txActive; /* Flag set if TX active on connection */
/*-------------------------------------------------------------------------
*
*
-*-------------------------------------------------------------------------
+ *-------------------------------------------------------------------------
*/
#include /* for getopt() */
const char* dbname,
const char* pghost,
const char* pgport,
+ const char* pgunixsocket,
const int reqPwd,
const int ignoreVersion)
{
else
AH->pgport = NULL;
+ if (pgunixsocket != NULL)
+ {
+ AH->pgport = strdup(pgunixsocket);
+ sprintf(tmp_string, "unixsocket=%s ", AH->pgunixsocket);
+ strcat(connect_string, tmp_string);
+ }
+ else
+ AH->pgunixsocket = NULL;
+
sprintf(tmp_string, "dbname=%s ", AH->dbname);
strcat(connect_string, tmp_string);
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.177 2000/10/31 14:20:30 pjw Exp $
+ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.178 2000/11/13 15:18:13 momjian Exp $
*
*
" -F, --format {c|f|p} output file format (custom, files, plain text)\n"
" -h, --host server host name\n"
" -i, --ignore-version proceed when database version != pg_dump version\n"
+ " -k, --unixsocket
server Unix-domain socket name\n"
" -n, --no-quotes suppress most quotes around identifiers\n"
" -N, --quotes enable most quotes around identifiers\n"
" -o, --oids dump object ids (oids)\n"
" -F {c|f|p} output file format (custom, files, plain text)\n"
" -h server host name\n"
" -i proceed when database version != pg_dump version\n"
+ " -k
server Unix-domain socket name\n"
" -n suppress most quotes around identifiers\n"
" -N enable most quotes around identifiers\n"
" -o dump object ids (oids)\n"
const char *dbname = NULL;
const char *pghost = NULL;
const char *pgport = NULL;
+ const char *pgunixsocket = NULL;
char *tablename = NULL;
bool oids = false;
TableInfo *tblinfo;
{"attribute-inserts", no_argument, NULL, 'D'},
{"host", required_argument, NULL, 'h'},
{"ignore-version", no_argument, NULL, 'i'},
+ {"unixsocket", required_argument, NULL, 'k'},
{"no-reconnect", no_argument, NULL, 'R'},
{"no-quotes", no_argument, NULL, 'n'},
{"quotes", no_argument, NULL, 'N'},
ignore_version = true;
break;
+ case 'k': /* server Unix-domain socket */
+ pgunixsocket = optarg;
+ break;
+
case 'n': /* Do not force double-quotes on
* identifiers */
force_quotes = false;
dbname = argv[optind];
/* Open the database using the Archiver, so it knows about it. Errors mean death */
- g_conn = ConnectDatabase(g_fout, dbname, pghost, pgport, use_password, ignore_version);
+ g_conn = ConnectDatabase(g_fout, dbname, pghost, pgport, pgunixsocket,
+ use_password, ignore_version);
/*
* Start serializable transaction to dump consistent data
{ "ignore-version", 0, NULL, 'i'},
{ "index", 2, NULL, 'I'},
{ "list", 0, NULL, 'l'},
+ { "unixsocket", 1, NULL, 'k' },
{ "no-acl", 0, NULL, 'x' },
{ "no-owner", 0, NULL, 'O'},
{ "no-reconnect", 0, NULL, 'R' },
progname = *argv;
#ifdef HAVE_GETOPT_LONG
- while ((c = getopt_long(argc, argv, "acCd:f:F:h:i:lNoOp:P:rRsS:t:T:uU:vx", cmdopts, NULL)) != EOF)
+ while ((c = getopt_long(argc, argv, "acCd:f:F:h:i:k:lNoOp:P:rRsS:t:T:uU:vx", cmdopts, NULL)) != EOF)
#else
- while ((c = getopt(argc, argv, "acCd:f:F:h:i:lNoOp:P:rRsS:t:T:uU:vx")) != -1)
+ while ((c = getopt(argc, argv, "acCd:f:F:h:i:k:lNoOp:P:rRsS:t:T:uU:vx")) != -1)
#endif
{
switch (c)
case 'i':
opts->ignoreVersion = 1;
break;
+ case 'k':
+ if (strlen(optarg) != 0)
+ opts->pgunixsocket = strdup(optarg);
+ break;
case 'N':
opts->origOrder = 1;
break;
*
* Copyright 2000 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.36 2000/09/17 20:33:45 petere Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.37 2000/11/13 15:18:14 momjian Exp $
*/
#include "postgres.h"
#include "command.h"
SetVariable(pset.vars, "USER", NULL);
SetVariable(pset.vars, "HOST", NULL);
SetVariable(pset.vars, "PORT", NULL);
+ SetVariable(pset.vars, "UNIXSOCKET", NULL);
SetVariable(pset.vars, "ENCODING", NULL);
/* If dbname is "" then use old name, else new one (even if NULL) */
do
{
need_pass = false;
+ /* FIXME use PQconnectdb to support passing the Unix socket */
pset.db = PQsetdbLogin(PQhost(oldconn), PQport(oldconn),
NULL, NULL, dbparam, userparam, pwparam);
SetVariable(pset.vars, "USER", PQuser(pset.db));
SetVariable(pset.vars, "HOST", PQhost(pset.db));
SetVariable(pset.vars, "PORT", PQport(pset.db));
+ SetVariable(pset.vars, "UNIXSOCKET", PQunixsocket(pset.db));
SetVariable(pset.vars, "ENCODING", pg_encoding_to_char(pset.encoding));
pset.issuper = test_superuser(PQuser(pset.db));
*
* Copyright 2000 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.23 2000/08/29 09:36:48 petere Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.24 2000/11/13 15:18:14 momjian Exp $
*/
#include "postgres.h"
#include "common.h"
SetVariable(pset.vars, "DBNAME", NULL);
SetVariable(pset.vars, "HOST", NULL);
SetVariable(pset.vars, "PORT", NULL);
+ SetVariable(pset.vars, "UNIXSOCKET", NULL);
SetVariable(pset.vars, "USER", NULL);
SetVariable(pset.vars, "ENCODING", NULL);
return NULL;
SetVariable(pset.vars, "DBNAME", NULL);
SetVariable(pset.vars, "HOST", NULL);
SetVariable(pset.vars, "PORT", NULL);
+ SetVariable(pset.vars, "UNIXSOCKET", NULL);
SetVariable(pset.vars, "USER", NULL);
SetVariable(pset.vars, "ENCODING", NULL);
return false;
*
* Copyright 2000 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/help.c,v 1.32 2000/09/22 23:02:00 petere Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/help.c,v 1.33 2000/11/13 15:18:14 momjian Exp $
*/
#include "postgres.h"
#include "help.h"
puts(")");
puts(" -H HTML table output mode (-P format=html)");
+
+ /* Display default Unix-domain socket */
+ env = getenv("PGUNIXSOCKET");
+ printf(" -k
Specify Unix domain socket name (default: ");
+ if (env)
+ fputs(env, stdout);
+ else
+ fputs("computed from the port", stdout);
+ puts(")");
+
puts(" -l List available databases, then exit");
puts(" -n Disable readline");
puts(" -o Send query output to filename (or |pipe)");
*
* Copyright 2000 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/prompt.c,v 1.13 2000/08/20 10:55:34 petere Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/prompt.c,v 1.14 2000/11/13 15:18:14 momjian Exp $
*/
#include "postgres.h"
#include "prompt.h"
if (pset.db && PQport(pset.db))
strncpy(buf, PQport(pset.db), MAX_PROMPT_SIZE);
break;
+ /* DB server Unix-domain socket */
+ case '<':
+ if (pset.db && PQunixsocket(pset.db))
+ strncpy(buf, PQunixsocket(pset.db), MAX_PROMPT_SIZE);
+ break;
/* DB server user name */
case 'n':
if (pset.db)
*
* Copyright 2000 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/startup.c,v 1.37 2000/09/17 20:33:45 petere Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/startup.c,v 1.38 2000/11/13 15:18:14 momjian Exp $
*/
#include "postgres.h"
char *dbname;
char *host;
char *port;
+ char *unixsocket;
char *username;
enum _actions action;
char *action_string;
do
{
need_pass = false;
+ /* FIXME use PQconnectdb to allow setting the unix socket */
pset.db = PQsetdbLogin(options.host, options.port, NULL, NULL,
options.action == ACT_LIST_DB ? "template1" : options.dbname,
username, password);
SetVariable(pset.vars, "USER", PQuser(pset.db));
SetVariable(pset.vars, "HOST", PQhost(pset.db));
SetVariable(pset.vars, "PORT", PQport(pset.db));
+ SetVariable(pset.vars, "UNIXSOCKET", PQunixsocket(pset.db));
SetVariable(pset.vars, "ENCODING", pg_encoding_to_char(pset.encoding));
#ifndef WIN32
{"field-separator", required_argument, NULL, 'F'},
{"host", required_argument, NULL, 'h'},
{"html", no_argument, NULL, 'H'},
+ {"unixsocket", required_argument, NULL, 'k'},
{"list", no_argument, NULL, 'l'},
{"no-readline", no_argument, NULL, 'n'},
{"output", required_argument, NULL, 'o'},
memset(options, 0, sizeof *options);
#ifdef HAVE_GETOPT_LONG
- while ((c = getopt_long(argc, argv, "aAc:d:eEf:F:lh:Hno:p:P:qRsStT:uU:v:VWxX?", long_options, &optindex)) != -1)
+ while ((c = getopt_long(argc, argv, "aAc:d:eEf:F:lh:Hk:no:p:P:qRsStT:uU:v:VWxX?", long_options, &optindex)) != -1)
#else /* not HAVE_GETOPT_LONG */
/*
* Be sure to leave the '-' in here, so we can catch accidental long
* options.
*/
- while ((c = getopt(argc, argv, "aAc:d:eEf:F:lh:Hno:p:P:qRsStT:uU:v:VWxX?-")) != -1)
+ while ((c = getopt(argc, argv, "aAc:d:eEf:F:lh:Hk:no:p:P:qRsStT:uU:v:VWxX?-")) != -1)
#endif /* not HAVE_GETOPT_LONG */
{
switch (c)
case 'l':
options->action = ACT_LIST_DB;
break;
+ case 'k':
+ options->unixsocket = optarg;
+ break;
case 'n':
options->no_readline = true;
break;
#
#
# IDENTIFICATION
-# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createdb,v 1.9 2000/11/11 22:59:48 petere Exp $
+# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createdb,v 1.10 2000/11/13 15:18:14 momjian Exp $
#
#-------------------------------------------------------------------------
--port=*)
PSQLOPT="$PSQLOPT -p "`echo $1 | sed 's/^--port=//'`
;;
+ --unixsocket|-k)
+ PSQLOPT="$PSQLOPT -k $2"
+ shift;;
+ -k*)
+ PSQLOPT="$PSQLOPT $1"
+ ;;
+ --unixsocket=*)
+ PSQLOPT="$PSQLOPT -k "`echo $1 | sed 's/^--unixsocket=//'`
+ ;;
--username|-U)
PSQLOPT="$PSQLOPT -U $2"
shift;;
echo " -E, --encoding=ENCODING Multibyte encoding for the database"
echo " -h, --host=HOSTNAME Database server host"
echo " -p, --port=PORT Database server port"
+ echo " -k, --unixsocket=PATH Database server Unix-domain socket name"
echo " -U, --username=USERNAME Username to connect as"
echo " -W, --password Prompt for password"
echo " -e, --echo Show the query being sent to the backend"
#
#
# IDENTIFICATION
-# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createlang.sh,v 1.17 2000/11/11 22:59:48 petere Exp $
+# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createlang.sh,v 1.18 2000/11/13 15:18:14 momjian Exp $
#
#-------------------------------------------------------------------------
--port=*)
PSQLOPT="$PSQLOPT -p "`echo $1 | sed 's/^--port=//'`
;;
+ --unixsocket|-k)
+ PSQLOPT="$PSQLOPT -k $2"
+ shift;;
+ -k*)
+ PSQLOPT="$PSQLOPT $1"
+ ;;
+ --unixsocket=*)
+ PSQLOPT="$PSQLOPT -k "`echo $1 | sed 's/^--unixsocket=//'`
+ ;;
--username|-U)
PSQLOPT="$PSQLOPT -U $2"
shift;;
echo "Options:"
echo " -h, --host=HOSTNAME Database server host"
echo " -p, --port=PORT Database server port"
+ echo " -k, --unixsocket=PATH Database server Unix-domain socket name"
echo " -U, --username=USERNAME Username to connect as"
echo " -W, --password Prompt for password"
echo " -d, --dbname=DBNAME Database to install language in"
#
#
# IDENTIFICATION
-# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createuser,v 1.12 2000/11/11 22:59:48 petere Exp $
+# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createuser,v 1.13 2000/11/13 15:18:14 momjian Exp $
#
# Note - this should NOT be setuid.
#
--port=*)
PSQLOPT="$PSQLOPT -p "`echo $1 | sed 's/^--port=//'`
;;
+ --unixsocket|-k)
+ PSQLOPT="$PSQLOPT -k $2"
+ shift;;
+ -k*)
+ PSQLOPT="$PSQLOPT $1"
+ ;;
+ --unixsocket=*)
+ PSQLOPT="$PSQLOPT -k "`echo $1 | sed 's/^--unixsocket=//'`
+ ;;
# Note: These two specify the user to connect as (like in psql),
# not the user you're creating.
--username|-U)
echo " -P, --pwprompt Assign a password to new user"
echo " -h, --host=HOSTNAME Database server host"
echo " -p, --port=PORT Database server port"
+ echo " -k, --unixsocket=PATH Database server Unix-domain socket name"
echo " -U, --username=USERNAME Username to connect as (not the one to create)"
echo " -W, --password Prompt for password to connect"
echo " -e, --echo Show the query being sent to the backend"
#
#
# IDENTIFICATION
-# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/dropdb,v 1.7 2000/11/11 22:59:48 petere Exp $
+# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/dropdb,v 1.8 2000/11/13 15:18:14 momjian Exp $
#
#-------------------------------------------------------------------------
--port=*)
PSQLOPT="$PSQLOPT -p "`echo $1 | sed 's/^--port=//'`
;;
+ --unixsocket|-k)
+ PSQLOPT="$PSQLOPT -k $2"
+ shift;;
+ -k*)
+ PSQLOPT="$PSQLOPT $1"
+ ;;
+ --unixsocket=*)
+ PSQLOPT="$PSQLOPT -k "`echo $1 | sed 's/^--unixsocket=//'`
+ ;;
--username|-U)
PSQLOPT="$PSQLOPT -U $2"
shift;;
echo "Options:"
echo " -h, --host=HOSTNAME Database server host"
echo " -p, --port=PORT Database server port"
+ echo " -k, --unixsocket=PATH Database server Unix-domain socket name"
echo " -U, --username=USERNAME Username to connect as"
echo " -W, --password Prompt for password"
echo " -i, --interactive Prompt before deleting anything"
#
#
# IDENTIFICATION
-# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/droplang,v 1.8 2000/11/11 22:59:48 petere Exp $
+# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/droplang,v 1.9 2000/11/13 15:18:14 momjian Exp $
#
#-------------------------------------------------------------------------
--port=*)
PSQLOPT="$PSQLOPT -p "`echo $1 | sed 's/^--port=//'`
;;
+ --unixsocket|-k)
+ PSQLOPT="$PSQLOPT -k $2"
+ shift;;
+ -k*)
+ PSQLOPT="$PSQLOPT $1"
+ ;;
+ --unixsocket=*)
+ PSQLOPT="$PSQLOPT -k "`echo $1 | sed 's/^--unixsocket=//'`
+ ;;
--username|-U)
PSQLOPT="$PSQLOPT -U $2"
shift;;
echo "Options:"
echo " -h, --host=HOSTNAME Database server host"
echo " -p, --port=PORT Database server port"
+ echo " -k, --unixsocket=PATH Database server Unix-domain socket name"
echo " -U, --username=USERNAME Username to connect as"
echo " -W, --password Prompt for password"
echo " -d, --dbname=DBNAME Database to remove language from"
#
#
# IDENTIFICATION
-# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/dropuser,v 1.7 2000/11/11 22:59:48 petere Exp $
+# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/dropuser,v 1.8 2000/11/13 15:18:14 momjian Exp $
#
# Note - this should NOT be setuid.
#
--port=*)
PSQLOPT="$PSQLOPT -p "`echo $1 | sed 's/^--port=//'`
;;
+ --unixsocket|-k)
+ PSQLOPT="$PSQLOPT -k $2"
+ shift;;
+ -k*)
+ PSQLOPT="$PSQLOPT $1"
+ ;;
+ --unixsocket=*)
+ PSQLOPT="$PSQLOPT -k "`echo $1 | sed 's/^--unixsocket=//'`
+ ;;
# Note: These two specify the user to connect as (like in psql),
# not the user you're dropping.
--username|-U)
echo "Options:"
echo " -h, --host=HOSTNAME Database server host"
echo " -p, --port=PORT Database server port"
+ echo " -k, --unixsocket=PATH Database server Unix-domain socket name"
echo " -U, --username=USERNAME Username to connect as (not the one to drop)"
echo " -W, --password Prompt for password to connect"
echo " -i, --interactive Prompt before deleting anything"
#
#
# IDENTIFICATION
-# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/vacuumdb,v 1.10 2000/11/11 22:59:48 petere Exp $
+# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/vacuumdb,v 1.11 2000/11/13 15:18:14 momjian Exp $
#
#-------------------------------------------------------------------------
--port=*)
PSQLOPT="$PSQLOPT -p "`echo $1 | sed 's/^--port=//'`
;;
+ --unixsocket|-k)
+ PSQLOPT="$PSQLOPT -k $2"
+ shift;;
+ -k*)
+ PSQLOPT="$PSQLOPT $1"
+ ;;
+ --unixsocket=*)
+ PSQLOPT="$PSQLOPT -k "`echo $1 | sed 's/^--unixsocket=//'`
+ ;;
--username|-U)
PSQLOPT="$PSQLOPT -U $2"
shift;;
echo "Options:"
echo " -h, --host=HOSTNAME Database server host"
echo " -p, --port=PORT Database server port"
+ echo " -k, --unixsocket=PATH Database server Unix-domain socket name"
echo " -U, --username=USERNAME Username to connect as"
echo " -W, --password Prompt for password"
echo " -d, --dbname=DBNAME Database to vacuum"
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: libpq.h,v 1.39 2000/07/08 03:04:30 tgl Exp $
+ * $Id: libpq.h,v 1.40 2000/11/13 15:18:14 momjian Exp $
*
*-------------------------------------------------------------------------
*/
/*
* prototypes for functions in pqcomm.c
*/
-extern int StreamServerPort(int family, unsigned short portName, int *fdP);
+extern int StreamServerPort(int family, char *hostName,
+ unsigned short portName, char *unixSocketName, int *fdP);
extern int StreamConnection(int server_fd, Port *port);
extern void StreamClose(int sock);
extern void pq_init(void);
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: pqcomm.h,v 1.43 2000/11/01 21:14:03 petere Exp $
+ * $Id: pqcomm.h,v 1.44 2000/11/13 15:18:14 momjian Exp $
*
*-------------------------------------------------------------------------
*/
/* Configure the UNIX socket address for the well known port. */
#if defined(SUN_LEN)
-#define UNIXSOCK_PATH(sun,port) \
- (sprintf((sun).sun_path, "/tmp/.s.PGSQL.%d", (port)), SUN_LEN(&(sun)))
+#define UNIXSOCK_PATH(sun,port,defpath) \
+ ((defpath && defpath[0] != '\0') ? (strncpy((sun).sun_path, defpath, sizeof((sun).sun_path)), (sun).sun_path[sizeof((sun).sun_path)-1] = '\0') : sprintf((sun).sun_path, "/tmp/.s.PGSQL.%d", (port)))
+#define UNIXSOCK_LEN(sun) \
+ (SUN_LEN(&(sun)))
#else
-#define UNIXSOCK_PATH(sun,port) \
- (sprintf((sun).sun_path, "/tmp/.s.PGSQL.%d", (port)), \
- strlen((sun).sun_path)+ offsetof(struct sockaddr_un, sun_path))
+#define UNIXSOCK_PATH(sun,port,defpath) \
+ ((defpath && defpath[0] != '\0') ? (strncpy((sun).sun_path, defpath, sizeof((sun).sun_path)), (sun).sun_path[sizeof((sun).sun_path)-1] = '\0') : sprintf((sun).sun_path, "/tmp/.s.PGSQL.%d", (port)))
+#define UNIXSOCK_LEN(sun) \
+ (strlen((sun).sun_path)+ offsetof(struct sockaddr_un, sun_path))
#endif
/*
extern int Unix_socket_permissions;
extern char * Unix_socket_group;
+extern char * UnixSocketName;
+extern char * HostName;
#endif /* PQCOMM_H */
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.144 2000/11/04 02:27:56 ishii Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.145 2000/11/13 15:18:15 momjian Exp $
*
*-------------------------------------------------------------------------
*/
{"port", "PGPORT", DEF_PGPORT_STR, NULL,
"Database-Port", "", 6},
+ {"unixsocket", "PGUNIXSOCKET", NULL, NULL,
+ "Unix-Socket", "", 80},
+
{"tty", "PGTTY", DefaultTty, NULL,
"Backend-Debug-TTY", "D", 40},
conn->pghost = tmp ? strdup(tmp) : NULL;
tmp = conninfo_getval(connOptions, "port");
conn->pgport = tmp ? strdup(tmp) : NULL;
+ tmp = conninfo_getval(connOptions, "unixsocket");
+ conn->pgunixsocket = tmp ? strdup(tmp) : NULL;
tmp = conninfo_getval(connOptions, "tty");
conn->pgtty = tmp ? strdup(tmp) : NULL;
tmp = conninfo_getval(connOptions, "options");
* PGPORT identifies TCP port to which to connect if
argument
* is NULL or a null string.
*
+ * PGUNIXSOCKET identifies Unix-domain socket to which to connect; default
+ * is computed from the TCP port.
+ *
* PGTTY identifies tty to which to send messages if
argument
* is NULL or a null string.
*
else
conn->pgport = strdup(pgport);
+#if FIX_ME
+ /* we need to modify the function to accept a unix socket path */
+ if (pgunixsocket)
+ conn->pgunixsocket = strdup(pgunixsocket);
+ else if ((tmp = getenv("PGUNIXSOCKET")) != NULL)
+ conn->pgunixsocket = strdup(tmp);
+#endif
+
if (pgtty == NULL)
{
if ((tmp = getenv("PGTTY")) == NULL)
/*
* update_db_info -
- * get all additional infos out of dbName
+ * get all additional info out of dbName
*
*/
static int
update_db_info(PGconn *conn)
{
- char *tmp,
+ char *tmp, *tmp2,
*old = conn->dbName;
if (strchr(conn->dbName, '@') != NULL)
tmp = strrchr(conn->dbName, ':');
if (tmp != NULL) /* port number given */
{
+ if (conn->pgport)
+ free(conn->pgport);
conn->pgport = strdup(tmp + 1);
*tmp = '\0';
}
tmp = strrchr(conn->dbName, '@');
if (tmp != NULL) /* host name given */
{
+ if (conn->pghost)
+ free(conn->pghost);
conn->pghost = strdup(tmp + 1);
*tmp = '\0';
}
/*
* new style:
- * :postgresql://server[:port][/dbname][?options]
+ * :postgresql://server[:port|:/unixsocket/path:][/dbname][?options]
*/
offset += strlen("postgresql://");
tmp = strrchr(conn->dbName + offset, '?');
if (tmp != NULL) /* options given */
{
+ if (conn->pgoptions)
+ free(conn->pgoptions);
conn->pgoptions = strdup(tmp + 1);
*tmp = '\0';
}
tmp = strrchr(conn->dbName + offset, '/');
if (tmp != NULL) /* database name given */
{
+ if (conn->dbName)
+ free(conn->dbName);
conn->dbName = strdup(tmp + 1);
*tmp = '\0';
}
else
{
+ /* Why do we default only this value from the environment again? */
if ((tmp = getenv("PGDATABASE")) != NULL)
+ {
+ if (conn->dbName)
+ free(conn->dbName);
conn->dbName = strdup(tmp);
+ }
else if (conn->pguser)
+ {
+ if (conn->dbName)
+ free(conn->dbName);
conn->dbName = strdup(conn->pguser);
+ }
}
tmp = strrchr(old + offset, ':');
- if (tmp != NULL) /* port number given */
+ if (tmp != NULL) /* port number or Unix socket path given */
{
- conn->pgport = strdup(tmp + 1);
*tmp = '\0';
+ if ((tmp2 = strchr(tmp + 1, ':')) != NULL)
+ {
+ if (strncmp(old, "unix:", 5) != 0)
+ {
+ printfPQExpBuffer(&conn->errorMessage,
+ "connectDBStart() -- "
+ "socket name can only be specified with "
+ "non-TCP\n");
+ return 1;
+ }
+ *tmp2 = '\0';
+ if (conn->pgunixsocket)
+ free(conn->pgunixsocket);
+ conn->pgunixsocket = strdup(tmp + 1);
+ }
+ else
+ {
+ if (conn->pgport)
+ free(conn->pgport);
+ conn->pgport = strdup(tmp + 1);
+ if (conn->pgunixsocket)
+ free(conn->pgunixsocket);
+ conn->pgunixsocket = NULL;
+ }
}
if (strncmp(old, "unix:", 5) == 0)
{
+ if (conn->pghost)
+ free(conn->pghost);
conn->pghost = NULL;
if (strcmp(old + offset, "localhost") != 0)
{
}
}
else
+ {
+ if (conn->pghost)
+ free(conn->pghost);
conn->pghost = strdup(old + offset);
-
+ }
free(old);
}
}
}
#ifdef HAVE_UNIX_SOCKETS
else
- conn->raddr_len = UNIXSOCK_PATH(conn->raddr.un, portno);
+ {
+ UNIXSOCK_PATH(conn->raddr.un, portno, conn->pgunixsocket);
+ conn->raddr_len = UNIXSOCK_LEN(conn->raddr.un);
+ }
#endif
conn->pghost ? conn->pghost : "localhost",
(family == AF_INET) ?
"TCP/IP port" : "Unix socket",
- conn->pgport);
+ (family == AF_UNIX && conn->pgunixsocket) ?
+ conn->pgunixsocket : conn->pgport);
goto connect_errReturn;
}
}
conn->pghost ? conn->pghost : "localhost",
(conn->raddr.sa.sa_family == AF_INET) ?
"TCP/IP port" : "Unix socket",
- conn->pgport);
+ (conn->raddr.sa.sa_family == AF_UNIX && conn->pgunixsocket) ?
+ conn->pgunixsocket : conn->pgport);
goto error_return;
}
free(conn->pghostaddr);
if (conn->pgport)
free(conn->pgport);
+ if (conn->pgunixsocket)
+ free(conn->pgunixsocket);
if (conn->pgtty)
free(conn->pgtty);
if (conn->pgoptions)
return conn->pgport;
}
+char *
+PQunixsocket(const PGconn *conn)
+{
+ if (!conn)
+ return (char *) NULL;
+ return conn->pgunixsocket;
+}
+
char *
PQtty(const PGconn *conn)
{
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: libpq-fe.h,v 1.67 2000/08/30 14:54:23 momjian Exp $
+ * $Id: libpq-fe.h,v 1.68 2000/11/13 15:18:15 momjian Exp $
*
*-------------------------------------------------------------------------
*/
extern char *PQpass(const PGconn *conn);
extern char *PQhost(const PGconn *conn);
extern char *PQport(const PGconn *conn);
+ extern char *PQunixsocket(const PGconn *conn);
extern char *PQtty(const PGconn *conn);
extern char *PQoptions(const PGconn *conn);
extern ConnStatusType PQstatus(const PGconn *conn);
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: libpq-int.h,v 1.27 2000/08/30 14:54:24 momjian Exp $
+ * $Id: libpq-int.h,v 1.28 2000/11/13 15:18:15 momjian Exp $
*
*-------------------------------------------------------------------------
*/
* numbers-and-dots notation. Takes
* precedence over above. */
char *pgport; /* the server's communication port */
+ char *pgunixsocket; /* the Unix-domain socket that the server is listening on;
+ * if NULL, uses a default constructed from pgport */
char *pgtty; /* tty on which the backend messages is
* displayed (NOT ACTUALLY USED???) */
char *pgoptions; /* options to start the backend with */
destroyPQExpBuffer @ 76
createPQExpBuffer @ 77
PQconninfoFree @ 78
+ PQunixsocket @ 79