diff options
| author | Bruce Momjian <bruce@momjian.us> | 2000-11-13 15:18:15 +0000 |
|---|---|---|
| committer | Bruce Momjian <bruce@momjian.us> | 2000-11-13 15:18:15 +0000 |
| commit | 2150c2edf184f4e1a136b235e36b96c1e7fdfd60 (patch) | |
| tree | 5f043f8b1f668e74c92e9095adb62f287fe46094 /src/bin/pg_dump | |
| parent | 7633cada54aad935b16410c6ebc3a1ee8e606033 (diff) | |
| download | postgresql-2150c2edf184f4e1a136b235e36b96c1e7fdfd60.tar.gz | |
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
Diffstat (limited to 'src/bin/pg_dump')
| -rw-r--r-- | src/bin/pg_dump/pg_backup.h | 4 | ||||
| -rw-r--r-- | src/bin/pg_dump/pg_backup_archiver.c | 5 | ||||
| -rw-r--r-- | src/bin/pg_dump/pg_backup_archiver.h | 1 | ||||
| -rw-r--r-- | src/bin/pg_dump/pg_backup_db.c | 12 | ||||
| -rw-r--r-- | src/bin/pg_dump/pg_dump.c | 13 | ||||
| -rw-r--r-- | src/bin/pg_dump/pg_restore.c | 9 |
6 files changed, 36 insertions, 8 deletions
diff --git a/src/bin/pg_dump/pg_backup.h b/src/bin/pg_dump/pg_backup.h index 8fceb26c8e..ffe071a665 100644 --- a/src/bin/pg_dump/pg_backup.h +++ b/src/bin/pg_dump/pg_backup.h @@ -99,8 +99,9 @@ typedef struct _restoreOptions { int useDB; char *dbname; - char *pgport; char *pghost; + char *pgport; + char *pgunixsocket; int ignoreVersion; int requirePassword; @@ -122,6 +123,7 @@ PGconn* ConnectDatabase(Archive *AH, const char* dbname, const char* pghost, const char* pgport, + const char* pgunixsocket, const int reqPwd, const int ignoreVersion); diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c index d8a969b41e..085a2eb329 100644 --- a/src/bin/pg_dump/pg_backup_archiver.c +++ b/src/bin/pg_dump/pg_backup_archiver.c @@ -131,8 +131,9 @@ void RestoreArchive(Archive* AHX, RestoreOptions *ropt) if (AH->version < K_VERS_1_3) die_horribly(AH, "Direct database connections are not supported in pre-1.3 archives"); - ConnectDatabase(AHX, ropt->dbname, ropt->pghost, ropt->pgport, - ropt->requirePassword, ropt->ignoreVersion); + ConnectDatabase(AHX, ropt->dbname, ropt->pghost, ropt->pgport, + ropt->pgunixsocket, ropt->requirePassword, + ropt->ignoreVersion); /* * If no superuser was specified then see if the current user will do... diff --git a/src/bin/pg_dump/pg_backup_archiver.h b/src/bin/pg_dump/pg_backup_archiver.h index 2c7291e6c6..a938f5e339 100644 --- a/src/bin/pg_dump/pg_backup_archiver.h +++ b/src/bin/pg_dump/pg_backup_archiver.h @@ -187,6 +187,7 @@ typedef struct _archiveHandle { char *archdbname; /* DB name *read* from archive */ char *pghost; char *pgport; + char *pgunixsocket; PGconn *connection; PGconn *blobConnection; /* Connection for BLOB xref */ int txActive; /* Flag set if TX active on connection */ diff --git a/src/bin/pg_dump/pg_backup_db.c b/src/bin/pg_dump/pg_backup_db.c index 4b8873c3a2..082edd5824 100644 --- a/src/bin/pg_dump/pg_backup_db.c +++ b/src/bin/pg_dump/pg_backup_db.c @@ -1,7 +1,7 @@ /*------------------------------------------------------------------------- * * -*------------------------------------------------------------------------- + *------------------------------------------------------------------------- */ #include <unistd.h> /* for getopt() */ @@ -273,6 +273,7 @@ PGconn* ConnectDatabase(Archive *AHX, const char* dbname, const char* pghost, const char* pgport, + const char* pgunixsocket, const int reqPwd, const int ignoreVersion) { @@ -307,6 +308,15 @@ PGconn* ConnectDatabase(Archive *AHX, else AH->pgport = NULL; + if (pgunixsocket != NULL) + { + AH->pgport = strdup(pgunixsocket); + sprintf(tmp_string, "unixsocket=%s ", AH->pgunixsocket); + strcat(connect_string, tmp_string); + } + else + AH->pgunixsocket = NULL; + sprintf(tmp_string, "dbname=%s ", AH->dbname); strcat(connect_string, tmp_string); diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 4b765f5288..738425a3eb 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -22,7 +22,7 @@ * * * 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 * @@ -200,6 +200,7 @@ help(const char *progname) " -F, --format {c|f|p} output file format (custom, files, plain text)\n" " -h, --host <hostname> server host name\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, --quotes enable most quotes around identifiers\n" " -o, --oids dump object ids (oids)\n" @@ -226,6 +227,7 @@ help(const char *progname) " -F {c|f|p} output file format (custom, files, plain text)\n" " -h <hostname> server host name\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 enable most quotes around identifiers\n" " -o dump object ids (oids)\n" @@ -629,6 +631,7 @@ main(int argc, char **argv) const char *dbname = NULL; const char *pghost = NULL; const char *pgport = NULL; + const char *pgunixsocket = NULL; char *tablename = NULL; bool oids = false; TableInfo *tblinfo; @@ -658,6 +661,7 @@ main(int argc, char **argv) {"attribute-inserts", no_argument, NULL, 'D'}, {"host", required_argument, NULL, 'h'}, {"ignore-version", no_argument, NULL, 'i'}, + {"unixsocket", required_argument, NULL, 'k'}, {"no-reconnect", no_argument, NULL, 'R'}, {"no-quotes", no_argument, NULL, 'n'}, {"quotes", no_argument, NULL, 'N'}, @@ -752,6 +756,10 @@ main(int argc, char **argv) ignore_version = true; break; + case 'k': /* server Unix-domain socket */ + pgunixsocket = optarg; + break; + case 'n': /* Do not force double-quotes on * identifiers */ force_quotes = false; @@ -948,7 +956,8 @@ main(int argc, char **argv) dbname = argv[optind]; /* Open the database using the Archiver, so it knows about it. Errors mean death */ - g_conn = ConnectDatabase(g_fout, dbname, pghost, pgport, use_password, ignore_version); + g_conn = ConnectDatabase(g_fout, dbname, pghost, pgport, pgunixsocket, + use_password, ignore_version); /* * Start serializable transaction to dump consistent data diff --git a/src/bin/pg_dump/pg_restore.c b/src/bin/pg_dump/pg_restore.c index 458482ed51..cafb7e9df6 100644 --- a/src/bin/pg_dump/pg_restore.c +++ b/src/bin/pg_dump/pg_restore.c @@ -101,6 +101,7 @@ struct option cmdopts[] = { { "ignore-version", 0, NULL, 'i'}, { "index", 2, NULL, 'I'}, { "list", 0, NULL, 'l'}, + { "unixsocket", 1, NULL, 'k' }, { "no-acl", 0, NULL, 'x' }, { "no-owner", 0, NULL, 'O'}, { "no-reconnect", 0, NULL, 'R' }, @@ -132,9 +133,9 @@ int main(int argc, char **argv) progname = *argv; #ifdef HAVE_GETOPT_LONG - while ((c = getopt_long(argc, argv, "acCd:f:F:h:i:lNoOp:P:rRsS:t:T:uU:vx", cmdopts, NULL)) != EOF) + while ((c = getopt_long(argc, argv, "acCd:f:F:h:i:k:lNoOp:P:rRsS:t:T:uU:vx", cmdopts, NULL)) != EOF) #else - while ((c = getopt(argc, argv, "acCd:f:F:h:i:lNoOp:P:rRsS:t:T:uU:vx")) != -1) + while ((c = getopt(argc, argv, "acCd:f:F:h:i:k:lNoOp:P:rRsS:t:T:uU:vx")) != -1) #endif { switch (c) @@ -170,6 +171,10 @@ int main(int argc, char **argv) case 'i': opts->ignoreVersion = 1; break; + case 'k': + if (strlen(optarg) != 0) + opts->pgunixsocket = strdup(optarg); + break; case 'N': opts->origOrder = 1; break; |
