1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-27 12:41:57 +03:00

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
This commit is contained in:
Bruce Momjian
2000-11-13 15:18:15 +00:00
parent 7633cada54
commit 2150c2edf1
42 changed files with 627 additions and 87 deletions

View File

@ -47,16 +47,17 @@ $ export PATH
</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
server machine is a remote machine, you
will need to set the <Acronym>PGHOST</Acronym> environment variable to the name
of the database server machine. The environment variable
<Acronym>PGPORT</Acronym> 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 <Application>postmaster</Application>,
you should immediately consult your site administrator to make sure that your
environment is properly set up.
</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 server
machine is a remote machine, you will need to set the
<Acronym>PGHOST</Acronym> environment variable to the name of the
database server machine. The environment variable
<Acronym>PGPORT</Acronym> or <envar>PGUNIXSOCKET</envar> 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
<Application>postmaster</Application>, you should immediately consult
your site administrator to make sure that your environment is properly
set up. </Para>
</Chapter>

View File

@ -1,5 +1,5 @@
<!--
$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">
@ -91,6 +91,13 @@ $Header: /cvsroot/pgsql/doc/src/sgml/Attic/libpq++.sgml,v 1.17 2000/09/29 20:21:
backend.
</para>
</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>
<para>
<envar>PGDATABASE</envar> sets the default

View File

@ -1,5 +1,5 @@
<!--
$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">
@ -133,6 +133,15 @@ PGconn *PQconnectdb(const char *conninfo)
</listitem>
</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>
<term><literal>dbname</literal></term>
<listitem>
@ -554,6 +563,16 @@ char *PQport(const PGconn *conn)
</para>
</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>
<para>
<function>PQtty</function>
@ -1832,6 +1851,13 @@ backend.
</listitem>
<listitem>
<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
<productname>Postgres</productname> database name.
</para>

View File

@ -1,5 +1,5 @@
<!--
$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
-->
@ -56,6 +56,18 @@ Postgres documentation
</listitem>
</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>
<term>-U, --username <replaceable class="parameter">username</replaceable></term>
<listitem>

View File

@ -1,5 +1,5 @@
<!--
$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
-->
@ -101,6 +101,18 @@ Postgres documentation
</listitem>
</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>
<term>-U, --username <replaceable class="parameter">username</replaceable></term>
<listitem>

View File

@ -1,5 +1,5 @@
<!--
$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
-->
@ -55,6 +55,18 @@ Postgres documentation
</listitem>
</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>
<term>-e, --echo</term>
<listitem>

View File

@ -1,5 +1,5 @@
<!--
$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
-->
@ -55,6 +55,18 @@ Postgres documentation
</listitem>
</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>
<term>-U, --username <replaceable class="parameter">username</replaceable></term>
<listitem>

View File

@ -1,5 +1,5 @@
<!--
$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
-->
@ -101,6 +101,18 @@ Postgres documentation
</listitem>
</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>
<term>-U, --username <replaceable class="parameter">username</replaceable></term>
<listitem>

View File

@ -1,5 +1,5 @@
<!--
$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
-->
@ -55,6 +55,18 @@ Postgres documentation
</listitem>
</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>
<term>-e, --echo</term>
<listitem>

View File

@ -1,5 +1,5 @@
<!--
$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
-->
@ -24,7 +24,9 @@ Postgres documentation
</refsynopsisdivinfo>
<synopsis>
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> ]
[ -a ] [ -c ] [ -d ] [ -D ] [ -i ] [ -n ] [ -N ]
[ -o ] [ -s ] [ -u ] [ -v ] [ -x ]
@ -204,6 +206,21 @@ pg_dump [ -h <replaceable class="parameter">host</replaceable> ] [ -p <replaceab
</listitem>
</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>
<term>-p <replaceable class="parameter">port</replaceable></term>
<listitem>

View File

@ -1,5 +1,5 @@
<!--
$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
-->
@ -23,7 +23,7 @@ Postgres documentation
<date>1999-07-20</date>
</refsynopsisdivinfo>
<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>
<refsect2 id="R2-APP-PG-DUMPALL-1">
@ -149,6 +149,21 @@ pg_dumpall [ -h <replaceable class="parameter">host</replaceable> ] [ -p <replac
</listitem>
</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>
<term>-p <replaceable class="parameter">port</replaceable></term>
<listitem>

View File

@ -1,5 +1,5 @@
<!--
$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
-->
@ -24,7 +24,9 @@ Postgres documentation
</refsynopsisdivinfo>
<synopsis>
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 ]
</synopsis>
@ -123,6 +125,36 @@ postmaster [ -B <replaceable class="parameter">nBuffers</replaceable> ] [ -D <re
</listitem>
</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>
<term>-i</term>
<listitem>
@ -134,6 +166,35 @@ postmaster [ -B <replaceable class="parameter">nBuffers</replaceable> ] [ -D <re
</listitem>
</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>
<term>-l</term>
<listitem>

View File

@ -1,5 +1,5 @@
<!--
$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
-->
@ -1329,6 +1329,19 @@ Access permissions for database "test"
</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>
<term>-H, --html</term>
<listitem>

View File

@ -1,5 +1,5 @@
<!--
$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
-->
@ -136,6 +136,18 @@ Postgres documentation
</listitem>
</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>
<term>-U <replaceable class="parameter">username</replaceable></term>
<term>--username <replaceable class="parameter">username</replaceable></term>

View File

@ -1,5 +1,5 @@
<!--
$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">
@ -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
variable to the name
of the database server machine. The environment variable
<acronym>PGPORT</acronym> may also have to be set. The bottom
line is this: if
<acronym>PGPORT</acronym> or <acronym>PGUNIXSOCKET</acronym> 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 <application>postmaster</application>,
you should immediately consult your site administrator to make