Commit 2150c2ed authored by Bruce Momjian's avatar Bruce Momjian

UUNET is looking into offering PostgreSQL as a part of a managed web

hosting product, on both shared and dedicated machines.  We currently
offer Oracle and MySQL, and it would be a nice middle-ground.
However, as shipped, PostgreSQL lacks the following features we need
that MySQL has:

1. The ability to listen only on a particular IP address.  Each
   hosting customer has their own IP address, on which all of their
   servers (http, ftp, real media, etc.) run.
2. The ability to place the Unix-domain socket in a mode 700 directory.
   This allows us to automatically create an empty database, with an
   empty DBA password, for new or upgrading customers without having
   to interactively set a DBA password and communicate it to (or from)
   the customer.  This in turn cuts down our install and upgrade times.
3. The ability to connect to the Unix-domain socket from within a
   change-rooted environment.  We run CGI programs chrooted to the
   user's home directory, which is another reason why we need to be
   able to specify where the Unix-domain socket is, instead of /tmp.
4. The ability to, if run as root, open a pid file in /var/run as
   root, and then setuid to the desired user.  (mysqld -u can almost
   do this; I had to patch it, too).

The patch below fixes problem 1-3.  I plan to address #4, also, but
haven't done so yet.  These diffs are big enough that they should give
the PG development team something to think about in the meantime :-)
Also, I'm about to leave for 2 weeks' vacation, so I thought I'd get
out what I have, which works (for the problems it tackles), now.

With these changes, we can set up and run PostgreSQL with scripts the
same way we can with apache or proftpd or mysql.

In summary, this patch makes the following enhancements:

1. Adds an environment variable PGUNIXSOCKET, analogous to MYSQL_UNIX_PORT,
   and command line options -k --unix-socket to the relevant programs.
2. Adds a -h option to postmaster to set the hostname or IP address to
   listen on instead of the default INADDR_ANY.
3. Extends some library interfaces to support the above.
4. Fixes a few memory leaks in PQconnectdb().

The default behavior is unchanged from stock 7.0.2; if you don't use
any of these new features, they don't change the operation.

David J. MacKenzie
parent 7633cada
...@@ -47,16 +47,17 @@ $ export PATH ...@@ -47,16 +47,17 @@ $ export PATH
</Para> </Para>
<Para> <Para>
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 If your site administrator has not set things up in the default way,
server machine is a remote machine, you you may have some more work to do. For example, if the database server
will need to set the <Acronym>PGHOST</Acronym> environment variable to the name machine is a remote machine, you will need to set the
of the database server machine. The environment variable <Acronym>PGHOST</Acronym> environment variable to the name of the
<Acronym>PGPORT</Acronym> may also have to be set. The bottom line is this: if database server machine. The environment variable
you try to start an application program and it complains <Acronym>PGPORT</Acronym> or <envar>PGUNIXSOCKET</envar> may also have
that it cannot connect to the <Application>postmaster</Application>, to be set. The bottom line is this: if you try to start an application
you should immediately consult your site administrator to make sure that your program and it complains that it cannot connect to the
environment is properly set up. <Application>postmaster</Application>, you should immediately consult
</Para> your site administrator to make sure that your environment is properly
set up. </Para>
</Chapter> </Chapter>
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/Attic/libpq++.sgml,v 1.17 2000/09/29 20:21:34 petere Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/Attic/libpq++.sgml,v 1.18 2000/11/13 15:18:07 momjian Exp $
--> -->
<chapter id="libpqplusplus"> <chapter id="libpqplusplus">
...@@ -91,6 +91,13 @@ $Header: /cvsroot/pgsql/doc/src/sgml/Attic/libpq++.sgml,v 1.17 2000/09/29 20:21: ...@@ -91,6 +91,13 @@ $Header: /cvsroot/pgsql/doc/src/sgml/Attic/libpq++.sgml,v 1.17 2000/09/29 20:21:
backend. backend.
</para> </para>
</listitem> </listitem>
<listitem>
<para>
<envar>PGUNIXSOCKET</envar> sets the full Unix domain socket
file name for communicating with the <productname>Postgres</productname>
backend.
</para>
</listitem>
<listitem> <listitem>
<para> <para>
<envar>PGDATABASE</envar> sets the default <envar>PGDATABASE</envar> sets the default
......
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/libpq.sgml,v 1.44 2000/10/17 14:27:50 momjian Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/libpq.sgml,v 1.45 2000/11/13 15:18:07 momjian Exp $
--> -->
<chapter id="libpq-chapter"> <chapter id="libpq-chapter">
...@@ -133,6 +133,15 @@ PGconn *PQconnectdb(const char *conninfo) ...@@ -133,6 +133,15 @@ PGconn *PQconnectdb(const char *conninfo)
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><literal>unixsocket</literal></term>
<listitem>
<para>
Full path to Unix-domain socket file to connect to at the server host.
</para>
</listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term><literal>dbname</literal></term> <term><literal>dbname</literal></term>
<listitem> <listitem>
...@@ -554,6 +563,16 @@ char *PQport(const PGconn *conn) ...@@ -554,6 +563,16 @@ char *PQport(const PGconn *conn)
</para> </para>
</listitem> </listitem>
<listitem>
<para>
<function>PQunixsocket</function>
Returns the name of the Unix-domain socket of the connection.
<synopsis>
char *PQunixsocket(const PGconn *conn)
</synopsis>
</para>
</listitem>
<listitem> <listitem>
<para> <para>
<function>PQtty</function> <function>PQtty</function>
...@@ -1832,6 +1851,13 @@ backend. ...@@ -1832,6 +1851,13 @@ backend.
</listitem> </listitem>
<listitem> <listitem>
<para> <para>
<envar>PGPORT</envar> sets the default port or local Unix domain socket
file extension for communicating with the <productname>Postgres</productname>
backend.
</para>
</listitem>
<listitem>
<para>
<envar>PGDATABASE</envar> sets the default <envar>PGDATABASE</envar> sets the default
<productname>Postgres</productname> database name. <productname>Postgres</productname> database name.
</para> </para>
......
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/createdb.sgml,v 1.11 2000/11/11 23:01:38 petere Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/ref/createdb.sgml,v 1.12 2000/11/13 15:18:08 momjian Exp $
Postgres documentation Postgres documentation
--> -->
...@@ -56,6 +56,18 @@ Postgres documentation ...@@ -56,6 +56,18 @@ Postgres documentation
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term>-k, --unixsocket <replaceable class="parameter">path</replaceable></term>
<listitem>
<para>
Specifies the Unix-domain socket on which the
<application>postmaster</application> is running.
Without this option, the socket is created in <filename>/tmp</filename>
based on the port number.
</para>
</listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term>-U, --username <replaceable class="parameter">username</replaceable></term> <term>-U, --username <replaceable class="parameter">username</replaceable></term>
<listitem> <listitem>
......
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/createlang.sgml,v 1.10 2000/11/11 23:01:38 petere Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/ref/createlang.sgml,v 1.11 2000/11/13 15:18:08 momjian Exp $
Postgres documentation Postgres documentation
--> -->
...@@ -101,6 +101,18 @@ Postgres documentation ...@@ -101,6 +101,18 @@ Postgres documentation
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term>-k, --unixsocket <replaceable class="parameter">path</replaceable></term>
<listitem>
<para>
Specifies the Unix-domain socket on which the
<application>postmaster</application> is running.
Without this option, the socket is created in <filename>/tmp</filename>
based on the port number.
</para>
</listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term>-U, --username <replaceable class="parameter">username</replaceable></term> <term>-U, --username <replaceable class="parameter">username</replaceable></term>
<listitem> <listitem>
......
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/createuser.sgml,v 1.10 2000/11/11 23:01:40 petere Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/ref/createuser.sgml,v 1.11 2000/11/13 15:18:08 momjian Exp $
Postgres documentation Postgres documentation
--> -->
...@@ -55,6 +55,18 @@ Postgres documentation ...@@ -55,6 +55,18 @@ Postgres documentation
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term>-k, --unixsocket <replaceable class="parameter">path</replaceable></term>
<listitem>
<para>
Specifies the Unix-domain socket on which the
<application>postmaster</application> is running.
Without this option, the socket is created in <filename>/tmp</filename>
based on the port number.
</para>
</listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term>-e, --echo</term> <term>-e, --echo</term>
<listitem> <listitem>
......
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/dropdb.sgml,v 1.4 2000/11/11 23:01:45 petere Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/ref/dropdb.sgml,v 1.5 2000/11/13 15:18:08 momjian Exp $
Postgres documentation Postgres documentation
--> -->
...@@ -55,6 +55,18 @@ Postgres documentation ...@@ -55,6 +55,18 @@ Postgres documentation
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term>-k, --unixsocket <replaceable class="parameter">path</replaceable></term>
<listitem>
<para>
Specifies the Unix-domain socket on which the
<application>postmaster</application> is running.
Without this option, the socket is created in <filename>/tmp</filename>
based on the port number.
</para>
</listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term>-U, --username <replaceable class="parameter">username</replaceable></term> <term>-U, --username <replaceable class="parameter">username</replaceable></term>
<listitem> <listitem>
......
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/droplang.sgml,v 1.4 2000/11/11 23:01:45 petere Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/ref/droplang.sgml,v 1.5 2000/11/13 15:18:08 momjian Exp $
Postgres documentation Postgres documentation
--> -->
...@@ -101,6 +101,18 @@ Postgres documentation ...@@ -101,6 +101,18 @@ Postgres documentation
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term>-k, --unixsocket <replaceable class="parameter">path</replaceable></term>
<listitem>
<para>
Specifies the Unix-domain socket on which the
<application>postmaster</application> is running.
Without this option, the socket is created in <filename>/tmp</filename>
based on the port number.
</para>
</listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term>-U, --username <replaceable class="parameter">username</replaceable></term> <term>-U, --username <replaceable class="parameter">username</replaceable></term>
<listitem> <listitem>
......
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/dropuser.sgml,v 1.5 2000/11/11 23:01:45 petere Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/ref/dropuser.sgml,v 1.6 2000/11/13 15:18:08 momjian Exp $
Postgres documentation Postgres documentation
--> -->
...@@ -55,6 +55,18 @@ Postgres documentation ...@@ -55,6 +55,18 @@ Postgres documentation
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term>-k, --unixsocket <replaceable class="parameter">path</replaceable></term>
<listitem>
<para>
Specifies the Unix-domain socket on which the
<application>postmaster</application> is running.
Without this option, the socket is created in <filename>/tmp</filename>
based on the port number.
</para>
</listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term>-e, --echo</term> <term>-e, --echo</term>
<listitem> <listitem>
......
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/pg_dump.sgml,v 1.20 2000/10/05 19:48:18 momjian Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/ref/pg_dump.sgml,v 1.21 2000/11/13 15:18:08 momjian Exp $
Postgres documentation Postgres documentation
--> -->
...@@ -24,7 +24,9 @@ Postgres documentation ...@@ -24,7 +24,9 @@ Postgres documentation
</refsynopsisdivinfo> </refsynopsisdivinfo>
<synopsis> <synopsis>
pg_dump [ <replaceable class="parameter">dbname</replaceable> ] pg_dump [ <replaceable class="parameter">dbname</replaceable> ]
pg_dump [ -h <replaceable class="parameter">host</replaceable> ] [ -p <replaceable class="parameter">port</replaceable> ] pg_dump [ -h <replaceable class="parameter">host</replaceable> ]
[ -k <replaceable class="parameter">path</replaceable> ]
[ -p <replaceable class="parameter">port</replaceable> ]
[ -t <replaceable class="parameter">table</replaceable> ] [ -t <replaceable class="parameter">table</replaceable> ]
[ -a ] [ -c ] [ -d ] [ -D ] [ -i ] [ -n ] [ -N ] [ -a ] [ -c ] [ -d ] [ -D ] [ -i ] [ -n ] [ -N ]
[ -o ] [ -s ] [ -u ] [ -v ] [ -x ] [ -o ] [ -s ] [ -u ] [ -v ] [ -x ]
...@@ -204,6 +206,21 @@ pg_dump [ -h <replaceable class="parameter">host</replaceable> ] [ -p <replaceab ...@@ -204,6 +206,21 @@ pg_dump [ -h <replaceable class="parameter">host</replaceable> ] [ -p <replaceab
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term>-k <replaceable class="parameter">path</replaceable></term>
<listitem>
<para>
Specifies the local Unix domain socket file path
on which the <application>postmaster</application>
is listening for connections.
Without this option, the socket path name defaults to
the value of the <envar>PGUNIXSOCKET</envar> environment
variable (if set), otherwise it is constructed
from the port number.
</para>
</listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term>-p <replaceable class="parameter">port</replaceable></term> <term>-p <replaceable class="parameter">port</replaceable></term>
<listitem> <listitem>
......
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/pg_dumpall.sgml,v 1.11 2000/11/02 21:13:31 petere Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/ref/pg_dumpall.sgml,v 1.12 2000/11/13 15:18:08 momjian Exp $
Postgres documentation Postgres documentation
--> -->
...@@ -23,7 +23,7 @@ Postgres documentation ...@@ -23,7 +23,7 @@ Postgres documentation
<date>1999-07-20</date> <date>1999-07-20</date>
</refsynopsisdivinfo> </refsynopsisdivinfo>
<synopsis> <synopsis>
pg_dumpall [ -h <replaceable class="parameter">host</replaceable> ] [ -p <replaceable class="parameter">port</replaceable> ] [ -a ] [ -d ] [ -D ] [ -O ] [ -s ] [ -u ] [ -v ] [ -x ] [ --accounts-only ] pg_dumpall [ -h <replaceable class="parameter">host</replaceable> ] [ -k <replaceable class="parameter">path</replaceable> ] [ -p <replaceable class="parameter">port</replaceable> ] [ -a ] [ -d ] [ -D ] [ -O ] [ -s ] [ -u ] [ -v ] [ -x ] [ --accounts-only ]
</synopsis> </synopsis>
<refsect2 id="R2-APP-PG-DUMPALL-1"> <refsect2 id="R2-APP-PG-DUMPALL-1">
...@@ -149,6 +149,21 @@ pg_dumpall [ -h <replaceable class="parameter">host</replaceable> ] [ -p <replac ...@@ -149,6 +149,21 @@ pg_dumpall [ -h <replaceable class="parameter">host</replaceable> ] [ -p <replac
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term>-k <replaceable class="parameter">path</replaceable></term>
<listitem>
<para>
Specifies the local Unix domain socket file path
on which the <application>postmaster</application>
is listening for connections.
Without this option, the socket path name defaults to
the value of the <envar>PGUNIXSOCKET</envar> environment
variable (if set), otherwise it is constructed
from the port number.
</para>
</listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term>-p <replaceable class="parameter">port</replaceable></term> <term>-p <replaceable class="parameter">port</replaceable></term>
<listitem> <listitem>
......
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/postmaster.sgml,v 1.12 2000/10/05 19:48:18 momjian Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/ref/postmaster.sgml,v 1.13 2000/11/13 15:18:08 momjian Exp $
Postgres documentation Postgres documentation
--> -->
...@@ -24,7 +24,9 @@ Postgres documentation ...@@ -24,7 +24,9 @@ Postgres documentation
</refsynopsisdivinfo> </refsynopsisdivinfo>
<synopsis> <synopsis>
postmaster [ -B <replaceable class="parameter">nBuffers</replaceable> ] [ -D <replaceable class="parameter">DataDir</replaceable> ] [ -N <replaceable class="parameter">maxBackends</replaceable> ] [ -S ] postmaster [ -B <replaceable class="parameter">nBuffers</replaceable> ] [ -D <replaceable class="parameter">DataDir</replaceable> ] [ -N <replaceable class="parameter">maxBackends</replaceable> ] [ -S ]
[ -d <replaceable class="parameter">DebugLevel</replaceable> ] [ -i ] [ -l ] [ -d <replaceable class="parameter">DebugLevel</replaceable> ]
[ -h <replaceable class="parameter">hostname</replaceable> ] [ -i ]
[ -k <replaceable class="parameter">path</replaceable> ] [ -l ]
[ -o <replaceable class="parameter">BackendOptions</replaceable> ] [ -p <replaceable class="parameter">port</replaceable> ] [ -n | -s ] [ -o <replaceable class="parameter">BackendOptions</replaceable> ] [ -p <replaceable class="parameter">port</replaceable> ] [ -n | -s ]
</synopsis> </synopsis>
...@@ -123,6 +125,36 @@ postmaster [ -B <replaceable class="parameter">nBuffers</replaceable> ] [ -D <re ...@@ -123,6 +125,36 @@ postmaster [ -B <replaceable class="parameter">nBuffers</replaceable> ] [ -D <re
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term>-h <replaceable class="parameter">hostName</replaceable></term>
<listitem>
<para>
Specifies the TCP/IP hostname or address
on which the <application>postmaster</application>
is to listen for connections from frontend applications. Defaults to
the value of the
<envar>PGHOST</envar>
environment variable, or if <envar>PGHOST</envar>
is not set, then defaults to "all", meaning listen on all configured addresses
(including localhost).
</para>
<para>
If you use a hostname or address other than "all", do not try to run
multiple instances of <application>postmaster</application> 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 <application>postmaster</application> instances are
listening must be distinct in the two last octets.
</para>
<para>
If you do use "all" (the default), then each instance must listen on a
different port (via -p or <envar>PGPORT</envar>). And, of course, do
not try to use both approaches on one host.
</para>
</listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term>-i</term> <term>-i</term>
<listitem> <listitem>
...@@ -134,6 +166,35 @@ postmaster [ -B <replaceable class="parameter">nBuffers</replaceable> ] [ -D <re ...@@ -134,6 +166,35 @@ postmaster [ -B <replaceable class="parameter">nBuffers</replaceable> ] [ -D <re
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term>-k <replaceable class="parameter">path</replaceable></term>
<listitem>
<para>
Specifies the local Unix domain socket path name
on which the <application>postmaster</application>
is to listen for connections from frontend applications. Defaults to
the value of the
<envar>PGUNIXSOCKET</envar>
environment variable, or if <envar>PGUNIXSOCKET</envar>
is not set, then defaults to a file in <filename>/tmp</filename>
constructed from the port number.
</para>
<para>
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 <filename>pg_hba.conf</filename>.
If you specify a socket path other than the
default then all frontend applications (including
<application>psql</application>) must specify the same
socket path using either command-line options or
<envar>PGUNIXSOCKET</envar>.
</para>
</listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term>-l</term> <term>-l</term>
<listitem> <listitem>
......
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.40 2000/10/24 01:38:21 tgl Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.41 2000/11/13 15:18:08 momjian Exp $
Postgres documentation Postgres documentation
--> -->
...@@ -1329,6 +1329,19 @@ Access permissions for database "test" ...@@ -1329,6 +1329,19 @@ Access permissions for database "test"
</varlistentry> </varlistentry>
<varlistentry>
<term>-k, --unixsocket <replaceable class="parameter">path</replaceable></term>
<listitem>
<para>
Specifies the Unix-domain socket on which the
<application>postmaster</application> is running.
Without this option, the socket is created in <filename>/tmp</filename>
based on the port number.
</para>
</listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term>-H, --html</term> <term>-H, --html</term>
<listitem> <listitem>
......
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/vacuumdb.sgml,v 1.10 2000/11/11 23:01:45 petere Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/ref/vacuumdb.sgml,v 1.11 2000/11/13 15:18:08 momjian Exp $
Postgres documentation Postgres documentation
--> -->
...@@ -136,6 +136,18 @@ Postgres documentation ...@@ -136,6 +136,18 @@ Postgres documentation
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term>-k, --unixsocket <replaceable class="parameter">path</replaceable></term>
<listitem>
<para>
Specifies the Unix-domain socket on which the
<application>postmaster</application> is running.
Without this option, the socket is created in <filename>/tmp</filename>
based on the port number.
</para>
</listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term>-U <replaceable class="parameter">username</replaceable></term> <term>-U <replaceable class="parameter">username</replaceable></term>
<term>--username <replaceable class="parameter">username</replaceable></term> <term>--username <replaceable class="parameter">username</replaceable></term>
......
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/start.sgml,v 1.13 2000/09/29 20:21:34 petere Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/start.sgml,v 1.14 2000/11/13 15:18:07 momjian Exp $
--> -->
<chapter id="start"> <chapter id="start">
...@@ -110,8 +110,8 @@ $Header: /cvsroot/pgsql/doc/src/sgml/start.sgml,v 1.13 2000/09/29 20:21:34 peter ...@@ -110,8 +110,8 @@ $Header: /cvsroot/pgsql/doc/src/sgml/start.sgml,v 1.13 2000/09/29 20:21:34 peter
will need to set the <acronym>PGHOST</acronym> environment will need to set the <acronym>PGHOST</acronym> environment
variable to the name variable to the name
of the database server machine. The environment variable of the database server machine. The environment variable
<acronym>PGPORT</acronym> may also have to be set. The bottom <acronym>PGPORT</acronym> or <acronym>PGUNIXSOCKET</acronym> may also have to be set.
line is this: if The bottom line is this: if
you try to start an application program and it complains you try to start an application program and it complains
that it cannot connect to the <application>postmaster</application>, that it cannot connect to the <application>postmaster</application>,
you should immediately consult your site administrator to make you should immediately consult your site administrator to make
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * 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 $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -169,13 +169,14 @@ StreamDoUnlink(void) ...@@ -169,13 +169,14 @@ StreamDoUnlink(void)
/* /*
* StreamServerPort -- open a sock stream "listening" port. * 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 * RETURNS: STATUS_OK or STATUS_ERROR
*/ */
int int
StreamServerPort(int family, unsigned short portName, int *fdP) StreamServerPort(int family, char *hostName, unsigned short portName,
char *unixSocketName, int *fdP)
{ {
SockAddr saddr; SockAddr saddr;
int fd, int fd,
...@@ -218,7 +219,8 @@ StreamServerPort(int family, unsigned short portName, int *fdP) ...@@ -218,7 +219,8 @@ StreamServerPort(int family, unsigned short portName, int *fdP)
#ifdef HAVE_UNIX_SOCKETS #ifdef HAVE_UNIX_SOCKETS
if (family == AF_UNIX) 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); strcpy(sock_path, saddr.un.sun_path);
/* /*
* If the socket exists but nobody has an advisory lock on it we * If the socket exists but nobody has an advisory lock on it we
...@@ -242,7 +244,27 @@ StreamServerPort(int family, unsigned short portName, int *fdP) ...@@ -242,7 +244,27 @@ StreamServerPort(int family, unsigned short portName, int *fdP)
if (family == AF_INET) 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); saddr.in.sin_port = htons(portName);
len = sizeof(struct sockaddr_in); len = sizeof(struct sockaddr_in);
} }
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* *
* *
* IDENTIFICATION * 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 * NOTES
* *
...@@ -114,6 +114,8 @@ static Dllist *PortList; ...@@ -114,6 +114,8 @@ static Dllist *PortList;
/* The socket number we are listening for connections on */ /* The socket number we are listening for connections on */
int PostPortName; int PostPortName;
char * UnixSocketName;
char * HostName;
/* /*
* This is a sequence number that indicates how many times we've had to * This is a sequence number that indicates how many times we've had to
...@@ -224,7 +226,7 @@ extern void SetThisStartUpID(void); ...@@ -224,7 +226,7 @@ extern void SetThisStartUpID(void);
static void pmdaemonize(int argc, char *argv[]); static void pmdaemonize(int argc, char *argv[]);
static Port *ConnCreate(int serverFd); static Port *ConnCreate(int serverFd);
static void ConnFree(Port *port); 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 SIGHUP_handler(SIGNAL_ARGS);
static void pmdie(SIGNAL_ARGS); static void pmdie(SIGNAL_ARGS);
static void reaper(SIGNAL_ARGS); static void reaper(SIGNAL_ARGS);
...@@ -366,7 +368,7 @@ PostmasterMain(int argc, char *argv[]) ...@@ -366,7 +368,7 @@ PostmasterMain(int argc, char *argv[])
* will occur. * will occur.
*/ */
opterr = 1; 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) switch(opt)
{ {
...@@ -422,7 +424,7 @@ PostmasterMain(int argc, char *argv[]) ...@@ -422,7 +424,7 @@ PostmasterMain(int argc, char *argv[])
#ifdef HAVE_INT_OPTRESET #ifdef HAVE_INT_OPTRESET
optreset = 1; optreset = 1;
#endif #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) switch (opt)
{ {
...@@ -456,9 +458,16 @@ PostmasterMain(int argc, char *argv[]) ...@@ -456,9 +458,16 @@ PostmasterMain(int argc, char *argv[])
case 'F': case 'F':
enableFsync = false; enableFsync = false;
break; break;
case 'h':
HostName = optarg;
break;
case 'i': case 'i':
NetServer = true; NetServer = true;
break; break;
case 'k':
/* Set PGUNIXSOCKET by hand. */
UnixSocketName = optarg;
break;
#ifdef USE_SSL #ifdef USE_SSL
case 'l': case 'l':
EnableSSL = true; EnableSSL = true;
...@@ -606,8 +615,9 @@ PostmasterMain(int argc, char *argv[]) ...@@ -606,8 +615,9 @@ PostmasterMain(int argc, char *argv[])
if (NetServer) if (NetServer)
{ {
status = StreamServerPort(AF_INET, (unsigned short) PostPortName, status = StreamServerPort(AF_INET, HostName,
&ServerSock_INET); (unsigned short) PostPortName, UnixSocketName,
&ServerSock_INET);
if (status != STATUS_OK) if (status != STATUS_OK)
{ {
fprintf(stderr, "%s: cannot create INET stream port\n", fprintf(stderr, "%s: cannot create INET stream port\n",
...@@ -617,8 +627,9 @@ PostmasterMain(int argc, char *argv[]) ...@@ -617,8 +627,9 @@ PostmasterMain(int argc, char *argv[])
} }
#ifdef HAVE_UNIX_SOCKETS #ifdef HAVE_UNIX_SOCKETS
status = StreamServerPort(AF_UNIX, (unsigned short) PostPortName, status = StreamServerPort(AF_UNIX, HostName,
&ServerSock_UNIX); (unsigned short) PostPortName, UnixSocketName,
&ServerSock_UNIX);
if (status != STATUS_OK) if (status != STATUS_OK)
{ {
fprintf(stderr, "%s: cannot create UNIX stream port\n", fprintf(stderr, "%s: cannot create UNIX stream port\n",
...@@ -789,7 +800,9 @@ usage(const char *progname) ...@@ -789,7 +800,9 @@ usage(const char *progname)
printf(" -d 1-5 debugging level\n"); printf(" -d 1-5 debugging level\n");
printf(" -D <directory> database directory\n"); printf(" -D <directory> database directory\n");
printf(" -F turn fsync off\n"); printf(" -F turn fsync off\n");
printf(" -h hostname specify hostname or IP address\n");
printf(" -i enable TCP/IP connections\n"); printf(" -i enable TCP/IP connections\n");
printf(" -k path specify Unix-domain socket name\n");
#ifdef USE_SSL #ifdef USE_SSL
printf(" -l enable SSL connections\n"); printf(" -l enable SSL connections\n");
#endif #endif
...@@ -1302,12 +1315,76 @@ ConnFree(Port *conn) ...@@ -1302,12 +1315,76 @@ ConnFree(Port *conn)
free(conn); 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 * reset_shared -- reset shared memory and semaphores
*/ */
static void 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; ipc_key = port * 1000 + shmem_seq * 100;
CreateSharedMemoryAndSemaphores(ipc_key, MaxBackends); CreateSharedMemoryAndSemaphores(ipc_key, MaxBackends);
shmem_seq += 1; shmem_seq += 1;
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* Support for grand unified configuration scheme, including SET * Support for grand unified configuration scheme, including SET
* command, configuration file, and command line options. * 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 * Copyright 2000 by PostgreSQL Global Development Group
* Written by Peter Eisentraut <peter_e@gmx.net>. * Written by Peter Eisentraut <peter_e@gmx.net>.
...@@ -304,6 +304,12 @@ ConfigureNamesString[] = ...@@ -304,6 +304,12 @@ ConfigureNamesString[] =
{"unix_socket_group", PGC_POSTMASTER, &Unix_socket_group, {"unix_socket_group", PGC_POSTMASTER, &Unix_socket_group,
"", NULL}, "", NULL},
{"unixsocket", PGC_POSTMASTER, &UnixSocketName,
"", NULL},
{"hostname", PGC_POSTMASTER, &HostName,
"", NULL},
{NULL, 0, NULL, NULL, NULL} {NULL, 0, NULL, NULL, NULL}
}; };
......
...@@ -99,8 +99,9 @@ typedef struct _restoreOptions { ...@@ -99,8 +99,9 @@ typedef struct _restoreOptions {
int useDB; int useDB;
char *dbname; char *dbname;
char *pgport;
char *pghost; char *pghost;
char *pgport;
char *pgunixsocket;
int ignoreVersion; int ignoreVersion;
int requirePassword; int requirePassword;
...@@ -122,6 +123,7 @@ PGconn* ConnectDatabase(Archive *AH, ...@@ -122,6 +123,7 @@ PGconn* ConnectDatabase(Archive *AH,
const char* dbname, const char* dbname,
const char* pghost, const char* pghost,
const char* pgport, const char* pgport,
const char* pgunixsocket,
const int reqPwd, const int reqPwd,
const int ignoreVersion); const int ignoreVersion);
......
...@@ -131,8 +131,9 @@ void RestoreArchive(Archive* AHX, RestoreOptions *ropt) ...@@ -131,8 +131,9 @@ void RestoreArchive(Archive* AHX, RestoreOptions *ropt)
if (AH->version < K_VERS_1_3) if (AH->version < K_VERS_1_3)
die_horribly(AH, "Direct database connections are not supported in pre-1.3 archives"); die_horribly(AH, "Direct database connections are not supported in pre-1.3 archives");
ConnectDatabase(AHX, ropt->dbname, ropt->pghost, ropt->pgport, ConnectDatabase(AHX, ropt->dbname, ropt->pghost, ropt->pgport,
ropt->requirePassword, ropt->ignoreVersion); ropt->pgunixsocket, ropt->requirePassword,
ropt->ignoreVersion);
/* /*
* If no superuser was specified then see if the current user will do... * If no superuser was specified then see if the current user will do...
......
...@@ -187,6 +187,7 @@ typedef struct _archiveHandle { ...@@ -187,6 +187,7 @@ typedef struct _archiveHandle {
char *archdbname; /* DB name *read* from archive */ char *archdbname; /* DB name *read* from archive */
char *pghost; char *pghost;
char *pgport; char *pgport;
char *pgunixsocket;
PGconn *connection; PGconn *connection;
PGconn *blobConnection; /* Connection for BLOB xref */ PGconn *blobConnection; /* Connection for BLOB xref */
int txActive; /* Flag set if TX active on connection */ int txActive; /* Flag set if TX active on connection */
......
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* *
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#include <unistd.h> /* for getopt() */ #include <unistd.h> /* for getopt() */
...@@ -273,6 +273,7 @@ PGconn* ConnectDatabase(Archive *AHX, ...@@ -273,6 +273,7 @@ PGconn* ConnectDatabase(Archive *AHX,
const char* dbname, const char* dbname,
const char* pghost, const char* pghost,
const char* pgport, const char* pgport,
const char* pgunixsocket,
const int reqPwd, const int reqPwd,
const int ignoreVersion) const int ignoreVersion)
{ {
...@@ -307,6 +308,15 @@ PGconn* ConnectDatabase(Archive *AHX, ...@@ -307,6 +308,15 @@ PGconn* ConnectDatabase(Archive *AHX,
else else
AH->pgport = NULL; 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); sprintf(tmp_string, "dbname=%s ", AH->dbname);
strcat(connect_string, tmp_string); strcat(connect_string, tmp_string);
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
* *
* *
* IDENTIFICATION * 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 $
* *
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb * Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
* *
...@@ -200,6 +200,7 @@ help(const char *progname) ...@@ -200,6 +200,7 @@ help(const char *progname)
" -F, --format {c|f|p} output file format (custom, files, plain text)\n" " -F, --format {c|f|p} output file format (custom, files, plain text)\n"
" -h, --host <hostname> server host name\n" " -h, --host <hostname> server host name\n"
" -i, --ignore-version proceed when database version != pg_dump version\n" " -i, --ignore-version proceed when database version != pg_dump version\n"
" -k, --unixsocket <path> server Unix-domain socket name\n"
" -n, --no-quotes suppress most quotes around identifiers\n" " -n, --no-quotes suppress most quotes around identifiers\n"
" -N, --quotes enable most quotes around identifiers\n" " -N, --quotes enable most quotes around identifiers\n"
" -o, --oids dump object ids (oids)\n" " -o, --oids dump object ids (oids)\n"
...@@ -226,6 +227,7 @@ help(const char *progname) ...@@ -226,6 +227,7 @@ help(const char *progname)
" -F {c|f|p} output file format (custom, files, plain text)\n" " -F {c|f|p} output file format (custom, files, plain text)\n"
" -h <hostname> server host name\n" " -h <hostname> server host name\n"
" -i proceed when database version != pg_dump version\n" " -i proceed when database version != pg_dump version\n"
" -k <path> server Unix-domain socket name\n"
" -n suppress most quotes around identifiers\n" " -n suppress most quotes around identifiers\n"
" -N enable most quotes around identifiers\n" " -N enable most quotes around identifiers\n"
" -o dump object ids (oids)\n" " -o dump object ids (oids)\n"
...@@ -629,6 +631,7 @@ main(int argc, char **argv) ...@@ -629,6 +631,7 @@ main(int argc, char **argv)
const char *dbname = NULL; const char *dbname = NULL;
const char *pghost = NULL; const char *pghost = NULL;
const char *pgport = NULL; const char *pgport = NULL;
const char *pgunixsocket = NULL;
char *tablename = NULL; char *tablename = NULL;
bool oids = false; bool oids = false;
TableInfo *tblinfo; TableInfo *tblinfo;
...@@ -658,6 +661,7 @@ main(int argc, char **argv) ...@@ -658,6 +661,7 @@ main(int argc, char **argv)
{"attribute-inserts", no_argument, NULL, 'D'}, {"attribute-inserts", no_argument, NULL, 'D'},
{"host", required_argument, NULL, 'h'}, {"host", required_argument, NULL, 'h'},
{"ignore-version", no_argument, NULL, 'i'}, {"ignore-version", no_argument, NULL, 'i'},
{"unixsocket", required_argument, NULL, 'k'},
{"no-reconnect", no_argument, NULL, 'R'}, {"no-reconnect", no_argument, NULL, 'R'},
{"no-quotes", no_argument, NULL, 'n'}, {"no-quotes", no_argument, NULL, 'n'},
{"quotes", no_argument, NULL, 'N'}, {"quotes", no_argument, NULL, 'N'},
...@@ -752,6 +756,10 @@ main(int argc, char **argv) ...@@ -752,6 +756,10 @@ main(int argc, char **argv)
ignore_version = true; ignore_version = true;
break; break;
case 'k': /* server Unix-domain socket */
pgunixsocket = optarg;
break;
case 'n': /* Do not force double-quotes on case 'n': /* Do not force double-quotes on
* identifiers */ * identifiers */
force_quotes = false; force_quotes = false;
...@@ -948,7 +956,8 @@ main(int argc, char **argv) ...@@ -948,7 +956,8 @@ main(int argc, char **argv)
dbname = argv[optind]; dbname = argv[optind];
/* Open the database using the Archiver, so it knows about it. Errors mean death */ /* 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 * Start serializable transaction to dump consistent data
......
...@@ -101,6 +101,7 @@ struct option cmdopts[] = { ...@@ -101,6 +101,7 @@ struct option cmdopts[] = {
{ "ignore-version", 0, NULL, 'i'}, { "ignore-version", 0, NULL, 'i'},
{ "index", 2, NULL, 'I'}, { "index", 2, NULL, 'I'},
{ "list", 0, NULL, 'l'}, { "list", 0, NULL, 'l'},
{ "unixsocket", 1, NULL, 'k' },
{ "no-acl", 0, NULL, 'x' }, { "no-acl", 0, NULL, 'x' },
{ "no-owner", 0, NULL, 'O'}, { "no-owner", 0, NULL, 'O'},
{ "no-reconnect", 0, NULL, 'R' }, { "no-reconnect", 0, NULL, 'R' },
...@@ -132,9 +133,9 @@ int main(int argc, char **argv) ...@@ -132,9 +133,9 @@ int main(int argc, char **argv)
progname = *argv; progname = *argv;
#ifdef HAVE_GETOPT_LONG #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 #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 #endif
{ {
switch (c) switch (c)
...@@ -170,6 +171,10 @@ int main(int argc, char **argv) ...@@ -170,6 +171,10 @@ int main(int argc, char **argv)
case 'i': case 'i':
opts->ignoreVersion = 1; opts->ignoreVersion = 1;
break; break;
case 'k':
if (strlen(optarg) != 0)
opts->pgunixsocket = strdup(optarg);
break;
case 'N': case 'N':
opts->origOrder = 1; opts->origOrder = 1;
break; break;
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* Copyright 2000 by PostgreSQL Global Development Group * 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 "postgres.h"
#include "command.h" #include "command.h"
...@@ -1202,6 +1202,7 @@ do_connect(const char *new_dbname, const char *new_user) ...@@ -1202,6 +1202,7 @@ do_connect(const char *new_dbname, const char *new_user)
SetVariable(pset.vars, "USER", NULL); SetVariable(pset.vars, "USER", NULL);
SetVariable(pset.vars, "HOST", NULL); SetVariable(pset.vars, "HOST", NULL);
SetVariable(pset.vars, "PORT", NULL); SetVariable(pset.vars, "PORT", NULL);
SetVariable(pset.vars, "UNIXSOCKET", NULL);
SetVariable(pset.vars, "ENCODING", NULL); SetVariable(pset.vars, "ENCODING", NULL);
/* If dbname is "" then use old name, else new one (even if NULL) */ /* If dbname is "" then use old name, else new one (even if NULL) */
...@@ -1231,6 +1232,7 @@ do_connect(const char *new_dbname, const char *new_user) ...@@ -1231,6 +1232,7 @@ do_connect(const char *new_dbname, const char *new_user)
do do
{ {
need_pass = false; need_pass = false;
/* FIXME use PQconnectdb to support passing the Unix socket */
pset.db = PQsetdbLogin(PQhost(oldconn), PQport(oldconn), pset.db = PQsetdbLogin(PQhost(oldconn), PQport(oldconn),
NULL, NULL, dbparam, userparam, pwparam); NULL, NULL, dbparam, userparam, pwparam);
...@@ -1307,6 +1309,7 @@ do_connect(const char *new_dbname, const char *new_user) ...@@ -1307,6 +1309,7 @@ do_connect(const char *new_dbname, const char *new_user)
SetVariable(pset.vars, "USER", PQuser(pset.db)); SetVariable(pset.vars, "USER", PQuser(pset.db));
SetVariable(pset.vars, "HOST", PQhost(pset.db)); SetVariable(pset.vars, "HOST", PQhost(pset.db));
SetVariable(pset.vars, "PORT", PQport(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)); SetVariable(pset.vars, "ENCODING", pg_encoding_to_char(pset.encoding));
pset.issuper = test_superuser(PQuser(pset.db)); pset.issuper = test_superuser(PQuser(pset.db));
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* Copyright 2000 by PostgreSQL Global Development Group * 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 "postgres.h"
#include "common.h" #include "common.h"
...@@ -329,6 +329,7 @@ PSQLexec(const char *query) ...@@ -329,6 +329,7 @@ PSQLexec(const char *query)
SetVariable(pset.vars, "DBNAME", NULL); SetVariable(pset.vars, "DBNAME", NULL);
SetVariable(pset.vars, "HOST", NULL); SetVariable(pset.vars, "HOST", NULL);
SetVariable(pset.vars, "PORT", NULL); SetVariable(pset.vars, "PORT", NULL);
SetVariable(pset.vars, "UNIXSOCKET", NULL);
SetVariable(pset.vars, "USER", NULL); SetVariable(pset.vars, "USER", NULL);
SetVariable(pset.vars, "ENCODING", NULL); SetVariable(pset.vars, "ENCODING", NULL);
return NULL; return NULL;
...@@ -508,6 +509,7 @@ SendQuery(const char *query) ...@@ -508,6 +509,7 @@ SendQuery(const char *query)
SetVariable(pset.vars, "DBNAME", NULL); SetVariable(pset.vars, "DBNAME", NULL);
SetVariable(pset.vars, "HOST", NULL); SetVariable(pset.vars, "HOST", NULL);
SetVariable(pset.vars, "PORT", NULL); SetVariable(pset.vars, "PORT", NULL);
SetVariable(pset.vars, "UNIXSOCKET", NULL);
SetVariable(pset.vars, "USER", NULL); SetVariable(pset.vars, "USER", NULL);
SetVariable(pset.vars, "ENCODING", NULL); SetVariable(pset.vars, "ENCODING", NULL);
return false; return false;
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* Copyright 2000 by PostgreSQL Global Development Group * 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 "postgres.h"
#include "help.h" #include "help.h"
...@@ -103,6 +103,16 @@ usage(void) ...@@ -103,6 +103,16 @@ usage(void)
puts(")"); puts(")");
puts(" -H HTML table output mode (-P format=html)"); puts(" -H HTML table output mode (-P format=html)");
/* Display default Unix-domain socket */
env = getenv("PGUNIXSOCKET");
printf(" -k <path> 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(" -l List available databases, then exit");
puts(" -n Disable readline"); puts(" -n Disable readline");
puts(" -o <filename> Send query output to filename (or |pipe)"); puts(" -o <filename> Send query output to filename (or |pipe)");
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* Copyright 2000 by PostgreSQL Global Development Group * 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 "postgres.h"
#include "prompt.h" #include "prompt.h"
...@@ -190,6 +190,11 @@ get_prompt(promptStatus_t status) ...@@ -190,6 +190,11 @@ get_prompt(promptStatus_t status)
if (pset.db && PQport(pset.db)) if (pset.db && PQport(pset.db))
strncpy(buf, PQport(pset.db), MAX_PROMPT_SIZE); strncpy(buf, PQport(pset.db), MAX_PROMPT_SIZE);
break; 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 */ /* DB server user name */
case 'n': case 'n':
if (pset.db) if (pset.db)
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* Copyright 2000 by PostgreSQL Global Development Group * 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" #include "postgres.h"
...@@ -65,6 +65,7 @@ struct adhoc_opts ...@@ -65,6 +65,7 @@ struct adhoc_opts
char *dbname; char *dbname;
char *host; char *host;
char *port; char *port;
char *unixsocket;
char *username; char *username;
enum _actions action; enum _actions action;
char *action_string; char *action_string;
...@@ -161,6 +162,7 @@ main(int argc, char *argv[]) ...@@ -161,6 +162,7 @@ main(int argc, char *argv[])
do do
{ {
need_pass = false; need_pass = false;
/* FIXME use PQconnectdb to allow setting the unix socket */
pset.db = PQsetdbLogin(options.host, options.port, NULL, NULL, pset.db = PQsetdbLogin(options.host, options.port, NULL, NULL,
options.action == ACT_LIST_DB ? "template1" : options.dbname, options.action == ACT_LIST_DB ? "template1" : options.dbname,
username, password); username, password);
...@@ -206,6 +208,7 @@ main(int argc, char *argv[]) ...@@ -206,6 +208,7 @@ main(int argc, char *argv[])
SetVariable(pset.vars, "USER", PQuser(pset.db)); SetVariable(pset.vars, "USER", PQuser(pset.db));
SetVariable(pset.vars, "HOST", PQhost(pset.db)); SetVariable(pset.vars, "HOST", PQhost(pset.db));
SetVariable(pset.vars, "PORT", PQport(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)); SetVariable(pset.vars, "ENCODING", pg_encoding_to_char(pset.encoding));
#ifndef WIN32 #ifndef WIN32
...@@ -320,6 +323,7 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options) ...@@ -320,6 +323,7 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
{"field-separator", required_argument, NULL, 'F'}, {"field-separator", required_argument, NULL, 'F'},
{"host", required_argument, NULL, 'h'}, {"host", required_argument, NULL, 'h'},
{"html", no_argument, NULL, 'H'}, {"html", no_argument, NULL, 'H'},
{"unixsocket", required_argument, NULL, 'k'},
{"list", no_argument, NULL, 'l'}, {"list", no_argument, NULL, 'l'},
{"no-readline", no_argument, NULL, 'n'}, {"no-readline", no_argument, NULL, 'n'},
{"output", required_argument, NULL, 'o'}, {"output", required_argument, NULL, 'o'},
...@@ -353,14 +357,14 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options) ...@@ -353,14 +357,14 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
memset(options, 0, sizeof *options); memset(options, 0, sizeof *options);
#ifdef HAVE_GETOPT_LONG #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 */ #else /* not HAVE_GETOPT_LONG */
/* /*
* Be sure to leave the '-' in here, so we can catch accidental long * Be sure to leave the '-' in here, so we can catch accidental long
* options. * 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 */ #endif /* not HAVE_GETOPT_LONG */
{ {
switch (c) switch (c)
...@@ -406,6 +410,9 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options) ...@@ -406,6 +410,9 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
case 'l': case 'l':
options->action = ACT_LIST_DB; options->action = ACT_LIST_DB;
break; break;
case 'k':
options->unixsocket = optarg;
break;
case 'n': case 'n':
options->no_readline = true; options->no_readline = true;
break; break;
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
# #
# #
# IDENTIFICATION # 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 $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
...@@ -50,6 +50,15 @@ do ...@@ -50,6 +50,15 @@ do
--port=*) --port=*)
PSQLOPT="$PSQLOPT -p "`echo $1 | sed 's/^--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) --username|-U)
PSQLOPT="$PSQLOPT -U $2" PSQLOPT="$PSQLOPT -U $2"
shift;; shift;;
...@@ -114,6 +123,7 @@ if [ "$usage" ]; then ...@@ -114,6 +123,7 @@ if [ "$usage" ]; then
echo " -E, --encoding=ENCODING Multibyte encoding for the database" echo " -E, --encoding=ENCODING Multibyte encoding for the database"
echo " -h, --host=HOSTNAME Database server host" echo " -h, --host=HOSTNAME Database server host"
echo " -p, --port=PORT Database server port" 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 " -U, --username=USERNAME Username to connect as"
echo " -W, --password Prompt for password" echo " -W, --password Prompt for password"
echo " -e, --echo Show the query being sent to the backend" echo " -e, --echo Show the query being sent to the backend"
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
# #
# #
# IDENTIFICATION # 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 $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
...@@ -65,6 +65,15 @@ do ...@@ -65,6 +65,15 @@ do
--port=*) --port=*)
PSQLOPT="$PSQLOPT -p "`echo $1 | sed 's/^--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) --username|-U)
PSQLOPT="$PSQLOPT -U $2" PSQLOPT="$PSQLOPT -U $2"
shift;; shift;;
...@@ -126,6 +135,7 @@ if [ "$usage" ]; then ...@@ -126,6 +135,7 @@ if [ "$usage" ]; then
echo "Options:" echo "Options:"
echo " -h, --host=HOSTNAME Database server host" echo " -h, --host=HOSTNAME Database server host"
echo " -p, --port=PORT Database server port" 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 " -U, --username=USERNAME Username to connect as"
echo " -W, --password Prompt for password" echo " -W, --password Prompt for password"
echo " -d, --dbname=DBNAME Database to install language in" echo " -d, --dbname=DBNAME Database to install language in"
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
# #
# #
# IDENTIFICATION # 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. # Note - this should NOT be setuid.
# #
...@@ -63,6 +63,15 @@ do ...@@ -63,6 +63,15 @@ do
--port=*) --port=*)
PSQLOPT="$PSQLOPT -p "`echo $1 | sed 's/^--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), # Note: These two specify the user to connect as (like in psql),
# not the user you're creating. # not the user you're creating.
--username|-U) --username|-U)
...@@ -135,6 +144,7 @@ if [ "$usage" ]; then ...@@ -135,6 +144,7 @@ if [ "$usage" ]; then
echo " -P, --pwprompt Assign a password to new user" echo " -P, --pwprompt Assign a password to new user"
echo " -h, --host=HOSTNAME Database server host" echo " -h, --host=HOSTNAME Database server host"
echo " -p, --port=PORT Database server port" 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 " -U, --username=USERNAME Username to connect as (not the one to create)"
echo " -W, --password Prompt for password to connect" echo " -W, --password Prompt for password to connect"
echo " -e, --echo Show the query being sent to the backend" echo " -e, --echo Show the query being sent to the backend"
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
# #
# #
# IDENTIFICATION # 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 $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
...@@ -59,6 +59,15 @@ do ...@@ -59,6 +59,15 @@ do
--port=*) --port=*)
PSQLOPT="$PSQLOPT -p "`echo $1 | sed 's/^--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) --username|-U)
PSQLOPT="$PSQLOPT -U $2" PSQLOPT="$PSQLOPT -U $2"
shift;; shift;;
...@@ -103,6 +112,7 @@ if [ "$usage" ]; then ...@@ -103,6 +112,7 @@ if [ "$usage" ]; then
echo "Options:" echo "Options:"
echo " -h, --host=HOSTNAME Database server host" echo " -h, --host=HOSTNAME Database server host"
echo " -p, --port=PORT Database server port" 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 " -U, --username=USERNAME Username to connect as"
echo " -W, --password Prompt for password" echo " -W, --password Prompt for password"
echo " -i, --interactive Prompt before deleting anything" echo " -i, --interactive Prompt before deleting anything"
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
# #
# #
# IDENTIFICATION # 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 $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
...@@ -65,6 +65,15 @@ do ...@@ -65,6 +65,15 @@ do
--port=*) --port=*)
PSQLOPT="$PSQLOPT -p "`echo $1 | sed 's/^--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) --username|-U)
PSQLOPT="$PSQLOPT -U $2" PSQLOPT="$PSQLOPT -U $2"
shift;; shift;;
...@@ -113,6 +122,7 @@ if [ "$usage" ]; then ...@@ -113,6 +122,7 @@ if [ "$usage" ]; then
echo "Options:" echo "Options:"
echo " -h, --host=HOSTNAME Database server host" echo " -h, --host=HOSTNAME Database server host"
echo " -p, --port=PORT Database server port" 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 " -U, --username=USERNAME Username to connect as"
echo " -W, --password Prompt for password" echo " -W, --password Prompt for password"
echo " -d, --dbname=DBNAME Database to remove language from" echo " -d, --dbname=DBNAME Database to remove language from"
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
# #
# #
# IDENTIFICATION # 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. # Note - this should NOT be setuid.
# #
...@@ -59,6 +59,15 @@ do ...@@ -59,6 +59,15 @@ do
--port=*) --port=*)
PSQLOPT="$PSQLOPT -p "`echo $1 | sed 's/^--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), # Note: These two specify the user to connect as (like in psql),
# not the user you're dropping. # not the user you're dropping.
--username|-U) --username|-U)
...@@ -105,6 +114,7 @@ if [ "$usage" ]; then ...@@ -105,6 +114,7 @@ if [ "$usage" ]; then
echo "Options:" echo "Options:"
echo " -h, --host=HOSTNAME Database server host" echo " -h, --host=HOSTNAME Database server host"
echo " -p, --port=PORT Database server port" 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 " -U, --username=USERNAME Username to connect as (not the one to drop)"
echo " -W, --password Prompt for password to connect" echo " -W, --password Prompt for password to connect"
echo " -i, --interactive Prompt before deleting anything" echo " -i, --interactive Prompt before deleting anything"
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
# #
# #
# IDENTIFICATION # 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 $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
...@@ -52,6 +52,15 @@ do ...@@ -52,6 +52,15 @@ do
--port=*) --port=*)
PSQLOPT="$PSQLOPT -p "`echo $1 | sed 's/^--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) --username|-U)
PSQLOPT="$PSQLOPT -U $2" PSQLOPT="$PSQLOPT -U $2"
shift;; shift;;
...@@ -121,6 +130,7 @@ if [ "$usage" ]; then ...@@ -121,6 +130,7 @@ if [ "$usage" ]; then
echo "Options:" echo "Options:"
echo " -h, --host=HOSTNAME Database server host" echo " -h, --host=HOSTNAME Database server host"
echo " -p, --port=PORT Database server port" 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 " -U, --username=USERNAME Username to connect as"
echo " -W, --password Prompt for password" echo " -W, --password Prompt for password"
echo " -d, --dbname=DBNAME Database to vacuum" echo " -d, --dbname=DBNAME Database to vacuum"
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * 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 $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -55,7 +55,8 @@ extern char PQerrormsg[PQERRORMSG_LENGTH]; /* in libpq/util.c */ ...@@ -55,7 +55,8 @@ extern char PQerrormsg[PQERRORMSG_LENGTH]; /* in libpq/util.c */
/* /*
* prototypes for functions in pqcomm.c * 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 int StreamConnection(int server_fd, Port *port);
extern void StreamClose(int sock); extern void StreamClose(int sock);
extern void pq_init(void); extern void pq_init(void);
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * 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 $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -51,12 +51,15 @@ typedef union SockAddr ...@@ -51,12 +51,15 @@ typedef union SockAddr
/* Configure the UNIX socket address for the well known port. */ /* Configure the UNIX socket address for the well known port. */
#if defined(SUN_LEN) #if defined(SUN_LEN)
#define UNIXSOCK_PATH(sun,port) \ #define UNIXSOCK_PATH(sun,port,defpath) \
(sprintf((sun).sun_path, "/tmp/.s.PGSQL.%d", (port)), SUN_LEN(&(sun))) ((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 #else
#define UNIXSOCK_PATH(sun,port) \ #define UNIXSOCK_PATH(sun,port,defpath) \
(sprintf((sun).sun_path, "/tmp/.s.PGSQL.%d", (port)), \ ((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)))
strlen((sun).sun_path)+ offsetof(struct sockaddr_un, sun_path)) #define UNIXSOCK_LEN(sun) \
(strlen((sun).sun_path)+ offsetof(struct sockaddr_un, sun_path))
#endif #endif
/* /*
...@@ -176,5 +179,7 @@ typedef struct CancelRequestPacket ...@@ -176,5 +179,7 @@ typedef struct CancelRequestPacket
extern int Unix_socket_permissions; extern int Unix_socket_permissions;
extern char * Unix_socket_group; extern char * Unix_socket_group;
extern char * UnixSocketName;
extern char * HostName;
#endif /* PQCOMM_H */ #endif /* PQCOMM_H */
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * 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 $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -130,6 +130,9 @@ static const PQconninfoOption PQconninfoOptions[] = { ...@@ -130,6 +130,9 @@ static const PQconninfoOption PQconninfoOptions[] = {
{"port", "PGPORT", DEF_PGPORT_STR, NULL, {"port", "PGPORT", DEF_PGPORT_STR, NULL,
"Database-Port", "", 6}, "Database-Port", "", 6},
{"unixsocket", "PGUNIXSOCKET", NULL, NULL,
"Unix-Socket", "", 80},
{"tty", "PGTTY", DefaultTty, NULL, {"tty", "PGTTY", DefaultTty, NULL,
"Backend-Debug-TTY", "D", 40}, "Backend-Debug-TTY", "D", 40},
...@@ -305,6 +308,8 @@ PQconnectStart(const char *conninfo) ...@@ -305,6 +308,8 @@ PQconnectStart(const char *conninfo)
conn->pghost = tmp ? strdup(tmp) : NULL; conn->pghost = tmp ? strdup(tmp) : NULL;
tmp = conninfo_getval(connOptions, "port"); tmp = conninfo_getval(connOptions, "port");
conn->pgport = tmp ? strdup(tmp) : NULL; conn->pgport = tmp ? strdup(tmp) : NULL;
tmp = conninfo_getval(connOptions, "unixsocket");
conn->pgunixsocket = tmp ? strdup(tmp) : NULL;
tmp = conninfo_getval(connOptions, "tty"); tmp = conninfo_getval(connOptions, "tty");
conn->pgtty = tmp ? strdup(tmp) : NULL; conn->pgtty = tmp ? strdup(tmp) : NULL;
tmp = conninfo_getval(connOptions, "options"); tmp = conninfo_getval(connOptions, "options");
...@@ -385,6 +390,9 @@ PQconndefaults(void) ...@@ -385,6 +390,9 @@ PQconndefaults(void)
* PGPORT identifies TCP port to which to connect if <pgport> argument * PGPORT identifies TCP port to which to connect if <pgport> argument
* is NULL or a null string. * 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 <pgtty> argument * PGTTY identifies tty to which to send messages if <pgtty> argument
* is NULL or a null string. * is NULL or a null string.
* *
...@@ -435,6 +443,14 @@ PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions, ...@@ -435,6 +443,14 @@ PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions,
else else
conn->pgport = strdup(pgport); 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 (pgtty == NULL)
{ {
if ((tmp = getenv("PGTTY")) == NULL) if ((tmp = getenv("PGTTY")) == NULL)
...@@ -510,13 +526,13 @@ PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions, ...@@ -510,13 +526,13 @@ PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions,
/* /*
* update_db_info - * update_db_info -
* get all additional infos out of dbName * get all additional info out of dbName
* *
*/ */
static int static int
update_db_info(PGconn *conn) update_db_info(PGconn *conn)
{ {
char *tmp, char *tmp, *tmp2,
*old = conn->dbName; *old = conn->dbName;
if (strchr(conn->dbName, '@') != NULL) if (strchr(conn->dbName, '@') != NULL)
...@@ -525,6 +541,8 @@ update_db_info(PGconn *conn) ...@@ -525,6 +541,8 @@ update_db_info(PGconn *conn)
tmp = strrchr(conn->dbName, ':'); tmp = strrchr(conn->dbName, ':');
if (tmp != NULL) /* port number given */ if (tmp != NULL) /* port number given */
{ {
if (conn->pgport)
free(conn->pgport);
conn->pgport = strdup(tmp + 1); conn->pgport = strdup(tmp + 1);
*tmp = '\0'; *tmp = '\0';
} }
...@@ -532,6 +550,8 @@ update_db_info(PGconn *conn) ...@@ -532,6 +550,8 @@ update_db_info(PGconn *conn)
tmp = strrchr(conn->dbName, '@'); tmp = strrchr(conn->dbName, '@');
if (tmp != NULL) /* host name given */ if (tmp != NULL) /* host name given */
{ {
if (conn->pghost)
free(conn->pghost);
conn->pghost = strdup(tmp + 1); conn->pghost = strdup(tmp + 1);
*tmp = '\0'; *tmp = '\0';
} }
...@@ -558,13 +578,15 @@ update_db_info(PGconn *conn) ...@@ -558,13 +578,15 @@ update_db_info(PGconn *conn)
/* /*
* new style: * new style:
* <tcp|unix>:postgresql://server[:port][/dbname][?options] * <tcp|unix>:postgresql://server[:port|:/unixsocket/path:][/dbname][?options]
*/ */
offset += strlen("postgresql://"); offset += strlen("postgresql://");
tmp = strrchr(conn->dbName + offset, '?'); tmp = strrchr(conn->dbName + offset, '?');
if (tmp != NULL) /* options given */ if (tmp != NULL) /* options given */
{ {
if (conn->pgoptions)
free(conn->pgoptions);
conn->pgoptions = strdup(tmp + 1); conn->pgoptions = strdup(tmp + 1);
*tmp = '\0'; *tmp = '\0';
} }
...@@ -572,26 +594,62 @@ update_db_info(PGconn *conn) ...@@ -572,26 +594,62 @@ update_db_info(PGconn *conn)
tmp = strrchr(conn->dbName + offset, '/'); tmp = strrchr(conn->dbName + offset, '/');
if (tmp != NULL) /* database name given */ if (tmp != NULL) /* database name given */
{ {
if (conn->dbName)
free(conn->dbName);
conn->dbName = strdup(tmp + 1); conn->dbName = strdup(tmp + 1);
*tmp = '\0'; *tmp = '\0';
} }
else else
{ {
/* Why do we default only this value from the environment again? */
if ((tmp = getenv("PGDATABASE")) != NULL) if ((tmp = getenv("PGDATABASE")) != NULL)
{
if (conn->dbName)
free(conn->dbName);
conn->dbName = strdup(tmp); conn->dbName = strdup(tmp);
}
else if (conn->pguser) else if (conn->pguser)
{
if (conn->dbName)
free(conn->dbName);
conn->dbName = strdup(conn->pguser); conn->dbName = strdup(conn->pguser);
}
} }
tmp = strrchr(old + offset, ':'); 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'; *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 (strncmp(old, "unix:", 5) == 0)
{ {
if (conn->pghost)
free(conn->pghost);
conn->pghost = NULL; conn->pghost = NULL;
if (strcmp(old + offset, "localhost") != 0) if (strcmp(old + offset, "localhost") != 0)
{ {
...@@ -603,8 +661,11 @@ update_db_info(PGconn *conn) ...@@ -603,8 +661,11 @@ update_db_info(PGconn *conn)
} }
} }
else else
{
if (conn->pghost)
free(conn->pghost);
conn->pghost = strdup(old + offset); conn->pghost = strdup(old + offset);
}
free(old); free(old);
} }
} }
...@@ -763,7 +824,10 @@ connectDBStart(PGconn *conn) ...@@ -763,7 +824,10 @@ connectDBStart(PGconn *conn)
} }
#ifdef HAVE_UNIX_SOCKETS #ifdef HAVE_UNIX_SOCKETS
else 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 #endif
...@@ -842,7 +906,8 @@ connectDBStart(PGconn *conn) ...@@ -842,7 +906,8 @@ connectDBStart(PGconn *conn)
conn->pghost ? conn->pghost : "localhost", conn->pghost ? conn->pghost : "localhost",
(family == AF_INET) ? (family == AF_INET) ?
"TCP/IP port" : "Unix socket", "TCP/IP port" : "Unix socket",
conn->pgport); (family == AF_UNIX && conn->pgunixsocket) ?
conn->pgunixsocket : conn->pgport);
goto connect_errReturn; goto connect_errReturn;
} }
} }
...@@ -1143,7 +1208,8 @@ keep_going: /* We will come back to here until there ...@@ -1143,7 +1208,8 @@ keep_going: /* We will come back to here until there
conn->pghost ? conn->pghost : "localhost", conn->pghost ? conn->pghost : "localhost",
(conn->raddr.sa.sa_family == AF_INET) ? (conn->raddr.sa.sa_family == AF_INET) ?
"TCP/IP port" : "Unix socket", "TCP/IP port" : "Unix socket",
conn->pgport); (conn->raddr.sa.sa_family == AF_UNIX && conn->pgunixsocket) ?
conn->pgunixsocket : conn->pgport);
goto error_return; goto error_return;
} }
...@@ -1819,6 +1885,8 @@ freePGconn(PGconn *conn) ...@@ -1819,6 +1885,8 @@ freePGconn(PGconn *conn)
free(conn->pghostaddr); free(conn->pghostaddr);
if (conn->pgport) if (conn->pgport)
free(conn->pgport); free(conn->pgport);
if (conn->pgunixsocket)
free(conn->pgunixsocket);
if (conn->pgtty) if (conn->pgtty)
free(conn->pgtty); free(conn->pgtty);
if (conn->pgoptions) if (conn->pgoptions)
...@@ -2528,6 +2596,14 @@ PQport(const PGconn *conn) ...@@ -2528,6 +2596,14 @@ PQport(const PGconn *conn)
return conn->pgport; return conn->pgport;
} }
char *
PQunixsocket(const PGconn *conn)
{
if (!conn)
return (char *) NULL;
return conn->pgunixsocket;
}
char * char *
PQtty(const PGconn *conn) PQtty(const PGconn *conn)
{ {
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * 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 $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -217,6 +217,7 @@ extern "C" ...@@ -217,6 +217,7 @@ extern "C"
extern char *PQpass(const PGconn *conn); extern char *PQpass(const PGconn *conn);
extern char *PQhost(const PGconn *conn); extern char *PQhost(const PGconn *conn);
extern char *PQport(const PGconn *conn); extern char *PQport(const PGconn *conn);
extern char *PQunixsocket(const PGconn *conn);
extern char *PQtty(const PGconn *conn); extern char *PQtty(const PGconn *conn);
extern char *PQoptions(const PGconn *conn); extern char *PQoptions(const PGconn *conn);
extern ConnStatusType PQstatus(const PGconn *conn); extern ConnStatusType PQstatus(const PGconn *conn);
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * 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 $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -203,6 +203,8 @@ struct pg_conn ...@@ -203,6 +203,8 @@ struct pg_conn
* numbers-and-dots notation. Takes * numbers-and-dots notation. Takes
* precedence over above. */ * precedence over above. */
char *pgport; /* the server's communication port */ 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 char *pgtty; /* tty on which the backend messages is
* displayed (NOT ACTUALLY USED???) */ * displayed (NOT ACTUALLY USED???) */
char *pgoptions; /* options to start the backend with */ char *pgoptions; /* options to start the backend with */
......
...@@ -79,3 +79,4 @@ EXPORTS ...@@ -79,3 +79,4 @@ EXPORTS
destroyPQExpBuffer @ 76 destroyPQExpBuffer @ 76
createPQExpBuffer @ 77 createPQExpBuffer @ 77
PQconninfoFree @ 78 PQconninfoFree @ 78
PQunixsocket @ 79
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment