From 28125ed5e0b967b71dc9cc686a8e16e1dd9996f8 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Tue, 18 Jan 2000 00:03:37 +0000 Subject: [PATCH] Updated user interfaces on initdb, initlocation, pg_dump, ipcclean to a GNU-compliant'ish state. Made ipcclean work on Linux. --- doc/src/sgml/ref/initdb.sgml | 6 +- doc/src/sgml/ref/initlocation.sgml | 158 ++++----------------- doc/src/sgml/ref/pg_dump.sgml | 17 +-- doc/src/sgml/ref/pg_dumpall.sgml | 8 +- src/bin/initdb/initdb.sh | 8 +- src/bin/initlocation/initlocation.sh | 198 ++++++++++++++++----------- src/bin/ipcclean/ipcclean.sh | 102 +++++++++++++- src/bin/pg_dump/pg_dump.c | 168 +++++++++++++---------- 8 files changed, 351 insertions(+), 314 deletions(-) diff --git a/doc/src/sgml/ref/initdb.sgml b/doc/src/sgml/ref/initdb.sgml index e08ab377f9..5f3bce4f83 100644 --- a/doc/src/sgml/ref/initdb.sgml +++ b/doc/src/sgml/ref/initdb.sgml @@ -1,5 +1,5 @@ @@ -26,7 +26,7 @@ Postgres documentation initdb [ --pgdata|-D dbdir ] [ --sysid|-i sysid ] [ --pwprompt|-W ] - [ --encoding|-e encoding ] + [ --encoding|-E encoding ] [ --pglib|-L libdir ] [ --username|-u name ] [ --noclean | -n ] [ --debug | -d ] [ --template | -t ] @@ -85,7 +85,7 @@ initdb [ --pgdata|-D dbdir ] --encoding=encoding - -e encoding + -E encoding Selects the multibyte encoding of the template database. This will also diff --git a/doc/src/sgml/ref/initlocation.sgml b/doc/src/sgml/ref/initlocation.sgml index edbc6613ed..2a12349866 100644 --- a/doc/src/sgml/ref/initlocation.sgml +++ b/doc/src/sgml/ref/initlocation.sgml @@ -1,5 +1,5 @@ @@ -15,17 +15,15 @@ Postgres documentation initlocation - Create a secondary Postgres database storage area + Create a secondary PostgreSQL database storage area - 1999-07-20 + 2000-01-17 -initlocation [ --location=er">alble> | -D altdir ] - [ --username=name | -u name ] - [ altdir ] +initlocation directory @@ -39,45 +37,14 @@ initlocation [ --location=er">alble - --location=altdir - -D altdir - altdir + directory Where in your Unix filesystem do you want alternate databases to go? - The top level directory is called the PGDATA directory, so you - might want to point your first alternate location at - PGDATA2. - - --username=name - -u name - PGUSER - - - Who will be the Unix filesystem owner of this database storage area? - The - Postgres superuser is a Unix user - who owns all files that store the database - system and also owns the postmaster and backend processes that access them. - Usually, this is the user who should run initlocation - and who will thus have ownership of the directories and files. - - - - Only the Unix superuser can create a database system with a - different user as the Postgres superuser. - Specifying a user other than the Postgres superuser - may lead to database security and data integrity problems. Refer to the - PostgreSQL Administrator's Guide - for more information. - - - - @@ -92,65 +59,6 @@ initlocation [ --location=er">alble initlocation will create directories in the specified place. - - - - -We are initializing the database area with username postgres (uid=500). -This user will own all the files and must also own the server process. -Creating Postgres database system directory altdir -Creating Postgres database system directory altdir - - - - Successful completion. - - - - - - -We are initializing the database area with username postgres (uid=500). -This user will own all the files and must also own the server process. -Creating Postgres database system directory /usr/local/src/testlocation -mkdir: cannot make directory `altdir': Permission denied - - - - You do not have filesystem permission to write to the specified directory area. - - - - - - -Valid username not given. You must specify the username for -the Postgres superuser for the database system you are -initializing, either with the --username option or by default -to the USER environment variable. - - - - The username which you have specified is not the - Postgres superuser. - - - - - - -Can't tell what username to use. You don't have the USER -environment variable set to your username and didn't specify the ---username option - - - - Specify the command line option. - - - - - @@ -164,41 +72,16 @@ environment variable set to your username and didn't specify the initlocation - creates a new Postgres secondary database storage area. - A secondary storage area contains a required tree of directories with - the correct file permissions on those directories. - - - Creating a database storage area consists of creating the directories in which - database data might live. + creates a new PostgreSQL secondary database storage area. + See the discussion under + about how to manage and use secondary storage areas. If the argument does not contain + a slash and is not valid as a path, it is assumed to be an environment variable, + which is referenced. See the examples at the end. - There are two kinds of arguments for initlocation. - - First, you can specify an environment variable (e.g. PGDATA2). - This environment variable should be known to the backend for later use in - CREATE DATABASE/WITH LOCATION - or - createdb -D altdir. - However, the backend daemon must have this variable in it's - environment for this to succeed. - - Second, you may be able to specify an explicit - absolute path to the top directory of the storage area. However,this second - option is possible only if explicitly enabled during the - Postgres installation. It is usually disabled - to alleviate security and data integrity concerns. + In order to use this command you must be logged in (using 'su', for example) + the database superuser. - - - Postgres will add /base/ - to the specified path to create the storage area. - - - The backend requires that any argument to which is - in all uppercase and which has no path delimiters is an environment variable. - - @@ -210,12 +93,19 @@ environment variable set to your username and didn't specify the To create a database in an alternate location, using an environment variable: + +$ export PGDATA2=/opt/postgres/data +$ initlocation PGDATA2 +$ createdb 'testdb' -D 'PGDATA2/testdb' + + - -% setenv PGDATA2 /opt/postgres/data -% initlocation PGDATA2 -% createdb -D PGDATA2 - + + Alternatively, if you allow absolute paths you could write: + +$ initlocation /opt/postgres/data +$ createdb 'testdb' -D '/opt/postgres/data/testdb' + diff --git a/doc/src/sgml/ref/pg_dump.sgml b/doc/src/sgml/ref/pg_dump.sgml index a11a366b43..d8f6bb6b57 100644 --- a/doc/src/sgml/ref/pg_dump.sgml +++ b/doc/src/sgml/ref/pg_dump.sgml @@ -1,5 +1,5 @@ @@ -25,9 +25,9 @@ Postgres documentation pg_dump [ dbname ] pg_dump [ -h host ] [ -p port ] - [ -t table ] [ -f outputfile ] + [ -t table ] [ -a ] [ -c ] [ -d ] [ -D ] [ -n ] [ -N ] - [ -o ] [ -s ] [ -u ] [ -v ] [ -x ] + [ -O ] [ -s ] [ -u ] [ -v ] [ -x ] [ dbname ] @@ -92,15 +92,6 @@ pg_dump [ -h host ] [ -p - - -f filename - - - Specifies the output file. Defaults to stdout. - - - - -n @@ -124,7 +115,7 @@ pg_dump [ -h host ] [ -p - -o + -O Dump object identifiers (OIDs) for every table. diff --git a/doc/src/sgml/ref/pg_dumpall.sgml b/doc/src/sgml/ref/pg_dumpall.sgml index b604ed6c55..cfe3b62f7f 100644 --- a/doc/src/sgml/ref/pg_dumpall.sgml +++ b/doc/src/sgml/ref/pg_dumpall.sgml @@ -1,5 +1,5 @@ @@ -24,7 +24,7 @@ Postgres documentation pg_dumpall -pg_dumpall [ -h host ] [ -p port ] [ -a ] [ -d ] [ -D ] [ -o ] [ -s ] [ -u ] [ -v ] [ -x ] +pg_dumpall [ -h host ] [ -p port ] [ -a ] [ -d ] [ -D ] [ -O ] [ -s ] [ -u ] [ -v ] [ -x ] @@ -77,7 +77,7 @@ pg_dumpall [ -h host ] [ -p - -o + -O Dump object identifiers (OIDs) for every table. @@ -277,7 +277,7 @@ dumpSequence(table): SELECT failed To dump all databases: -% pg_dumpall -o > db.out +% pg_dumpall > db.out diff --git a/src/bin/initdb/initdb.sh b/src/bin/initdb/initdb.sh index 14fd35ebcd..02818be924 100644 --- a/src/bin/initdb/initdb.sh +++ b/src/bin/initdb/initdb.sh @@ -26,7 +26,7 @@ # # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.79 2000/01/15 18:30:31 petere Exp $ +# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.80 2000/01/18 00:03:35 petere Exp $ # #------------------------------------------------------------------------- @@ -199,14 +199,14 @@ do ;; # The encoding of the template1 database. Defaults to what you chose # at configure time. (see above) - --encoding|-e) + --encoding|-E) MULTIBYTE="$2" shift;; --encoding=*) MULTIBYTE=`echo $1 | sed 's/^--encoding=//'` ;; - -e*) - MULTIBYTE=`echo $1 | sed 's/^-e//'` + -E*) + MULTIBYTE=`echo $1 | sed 's/^-E//'` ;; *) PGDATA=$1 diff --git a/src/bin/initlocation/initlocation.sh b/src/bin/initlocation/initlocation.sh index 61c5267972..07b9ed69e2 100644 --- a/src/bin/initlocation/initlocation.sh +++ b/src/bin/initlocation/initlocation.sh @@ -1,107 +1,112 @@ #!/bin/sh #------------------------------------------------------------------------- # -# initarea.sh-- -# Create (initialize) a secondary Postgres database storage area. +# initlocation.sh-- +# Create a secondary PostgreSQL database storage area. # -# A database storage area contains individual Postgres databases. -# -# To create the database storage area, we create a root directory tree. -# # Copyright (c) 1994, Regents of the University of California # # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/bin/initlocation/Attic/initlocation.sh,v 1.3 1999/12/16 20:09:57 momjian Exp $ +# $Header: /cvsroot/pgsql/src/bin/initlocation/Attic/initlocation.sh,v 1.4 2000/01/18 00:03:36 petere Exp $ # #------------------------------------------------------------------------- +exit_nicely(){ + echo "$CMDNAME failed." + rm -rf "$PGALTDATA" + exit 1 +} + + CMDNAME=`basename $0` -POSTGRES_SUPERUSERNAME=$USER +EffectiveUser=`id -n -u 2>/dev/null || whoami 2>/dev/null` + +if [ "$USER" = 'root' -o "$LOGNAME" = 'root' ] +then + echo "You cannot run $CMDNAME as root. Please log in (using, e.g., 'su')" + echo "as the (unprivileged) user that will own the server process." + exit 1 +fi + +Location= while [ "$#" -gt 0 ] do - case "$1" in - --location=*) PGALTDATA="`echo $1 | sed 's/^--pgdata=//'`"; ;; - --username=*) POSTGRES_SUPERUSERNAME="`echo $1 | sed 's/^--username=//'`" ;; - - --location) shift; PGALTDATA="$1"; ;; - --username) shift; POSTGRES_SUPERUSERNAME="$1"; ;; - --help) usage=1; ;; - - -u) shift; POSTGRES_SUPERUSERNAME="$1"; ;; - -D) shift; PGALTDATA="$1"; ;; - -h) usage=t; ;; - -\?) usage=t; ;; - -*) badparm=$1; ;; - *) PGALTDATA="$1"; ;; + case "$1" in + # These options are not really necessary, but what the heck. + --location=*) + Location=`echo $1 | sed 's/^--pgdata=//'` + ;; + --location) + Location="$2" + shift;; + -D) + Location="$2" + shift;; + + --help|-\?) + usage=t + break;; + + -*) + echo "$CMDNAME: unrecognized option $badparm" + echo "Try -? for help." + exit 1 + ;; + *) + Location="$1" + ;; esac shift done -if [ -n "$badparm" ]; then - echo "$CMDNAME: Unrecognized parameter '$badparm'. Try -? for help." - exit 1 -fi if [ "$usage" ]; then + echo "$CMDNAME initializes an alternative filesystem location for database creation." echo "" - echo "Usage: $CMDNAME [options] datadir" + echo "Usage:" + echo " $CMDNAME " echo "" - echo " -u SUPERUSER, --username=SUPERUSER " - echo " -D DATADIR, --location=DATADIR " - echo " -?, --help " - echo "" - exit 1 + echo "Report bugs to ." + exit 0 fi -#------------------------------------------------------------------------- -# Make sure he told us where to build the database area -#------------------------------------------------------------------------- - -PGENVAR="$PGALTDATA" -PGENVAR=`printenv $PGENVAR` -if [ ! -z "$PGENVAR" ]; then - PGALTDATA=$PGENVAR - echo "$CMDNAME: input argument points to $PGALTDATA" -fi -if [ -z "$PGALTDATA" ]; then - echo "$CMDNAME: You must identify the target area, where the new data" - echo "for this database system can reside. Do this with --location" +if [ -z "$Location" ]; then + echo "$CMDNAME: missing required argument " + echo "Try -? for help." exit 1 fi -#--------------------------------------------------------------------------- -# Figure out who the Postgres superuser for the new database system will be. -#--------------------------------------------------------------------------- -if [ -z "$POSTGRES_SUPERUSERNAME" ]; then - echo "Can't tell what username to use. You don't have the USER" - echo "environment variable set to your username and didn't specify the " - echo "--username option" - exit 1 -fi - -POSTGRES_SUPERUID=`pg_id $POSTGRES_SUPERUSERNAME` - -if [ $POSTGRES_SUPERUID = NOUSER ]; then - echo "Valid username not given. You must specify the username for " - echo "the Postgres superuser for the database system you are " - echo "initializing, either with the --username option or by default " - echo "to the USER environment variable." - exit 1 -fi +# +# Here's what's going on: +# +# You can call initlocation ENVAR (no dollar sign), then ENVAR will +# (a) be tested whether it is valid as a path, or +# (b) be resolved as an environment variable. +# The latter has been the traditional behaviour. +# +# You can call initlocation $ENVAR, which will of course be resolved +# by the shell, or initlocation some/path (containing at least one slash). +# Then you just take that path. +# This should apease users who are confused by the above behaviour. +# -if [ $POSTGRES_SUPERUID -ne `pg_id` -a `pg_id` -ne 0 ]; then - echo "Only the unix superuser may initialize a database with a different" - echo "Postgres superuser. (You must be able to create files that belong" - echo "to the specified unix user)." - exit 1 +if ! echo "$Location" | grep -s '/' >/dev/null 2>&1 && [ ! -d "$Location" ]; then + PGALTDATA=`printenv $Location 2> /dev/null` + if [ -z "$PGALTDATA" ]; then + echo "$CMDNAME: environment variable $PGALTDATA not set" + exit 1 + fi + haveenv=t +else + PGALTDATA="$Location" + haveenv=f fi -echo "We are initializing the database area with username" \ - "$POSTGRES_SUPERUSERNAME (uid=$POSTGRES_SUPERUID)." +echo "The location will be initialized with username \"$EffectiveUser\"." echo "This user will own all the files and must also own the server process." echo @@ -109,22 +114,51 @@ echo # Create the data directory if necessary # ----------------------------------------------------------------------- +# don't want to leave anything lying around +trap 'echo "Caught signal." ; exit_nicely' 1 2 3 15 + # umask must disallow access to group, other for files and dirs umask 077 if [ ! -d $PGALTDATA ]; then - echo "Creating Postgres database system directory $PGALTDATA" - echo - mkdir $PGALTDATA - if [ $? -ne 0 ]; then exit 1; fi - chown $POSTGRES_SUPERUSERNAME $PGALTDATA + echo "Creating directory $PGALTDATA" + mkdir "$PGALTDATA" + if [ $? -ne 0 ]; then + echo "$CMDNAME: could not create $PGALTDATA" + echo "Make sure $PGALTDATA is a valid path and that you have permission to access it." + exit_nicely + fi +else + echo "Fixing permissions on pre-existing directory $PGALTDATA" + chmod go-rwx "$PGALTDATA" || exit_nicely fi + + if [ ! -d $PGALTDATA/base ]; then - echo "Creating Postgres database system directory $PGALTDATA/base" - echo - mkdir $PGALTDATA/base - if [ $? -ne 0 ]; then exit 1; fi - chown $POSTGRES_SUPERUSERNAME $PGALTDATA/base + echo "Creating directory $PGALTDATA/base" + mkdir "$PGALTDATA/base" + if [ $? -ne 0 ]; then + echo "$CMDNAME: could not create $PGALTDATA/base" + echo "Make sure $PGALTDATA/base is a valid path and that you have permission to access it." + exit_nicely + fi +else + echo "Fixing permissions on pre-existing directory $PGALTDATA/base" + chmod go-rwx "$PGALTDATA/base" || exit_nicely fi -exit +echo +echo "$CMDNAME is complete." +# We can only suggest them these commands if they used the environment +# variable notation. Otherwise they would be induced to use an absolute +# path, which the backend won't allow by default. +if [ "$haveenv" = "t" ]; then + echo "You can now create a database using" + echo " CREATE DATABASE WITH LOCATION = '$Location/'" + echo "in SQL, or" + echo " createdb -D '$Location/'" + echo "from the shell." +fi +echo + +exit 0 diff --git a/src/bin/ipcclean/ipcclean.sh b/src/bin/ipcclean/ipcclean.sh index 64a01e062a..616ec3c964 100644 --- a/src/bin/ipcclean/ipcclean.sh +++ b/src/bin/ipcclean/ipcclean.sh @@ -1,8 +1,102 @@ #!/bin/sh # -# $Header: /cvsroot/pgsql/src/bin/ipcclean/Attic/ipcclean.sh,v 1.2 1998/08/22 05:19:31 momjian Exp $ +# $Header: /cvsroot/pgsql/src/bin/ipcclean/Attic/ipcclean.sh,v 1.3 2000/01/18 00:03:36 petere Exp $ # -PATH=PG_OPT_IPCCLEANPATH_PARAM:$PATH -export PATH -ipcs | egrep '^m .*|^s .*' | egrep "`whoami`|postgres" | \ + +CMDNAME=`basename $0` + +if [ "$1" = '-?' -o "$1" = "--help" ]; then + echo "$CMDNAME cleans up shared memory and semaphores from aborted PostgreSQL backends." + echo + echo "Usage:" + echo " $CMDNAME" + echo + echo "Note: Since the utilities underlying this script are very different" + echo "from platform to platform, chances are that it might not work on" + echo "yours. If that is the case, please write to " + echo "so that your platform can be supported in the future." + exit 0 +fi + +if [ "$USER" = 'root' -o "$LOGNAME" = 'root' ] +then + echo "You cannot run $CMDNAME as root. Please log in (using, e.g., 'su')" + echo "as the (unprivileged) user that owned the server process." + exit 1 +fi + +EffectiveUser=`id -n -u 2>/dev/null || whoami 2>/dev/null` + +#----------------------------------- +# List of platform-specific hacks +# Feel free to add yours here. +#----------------------------------- + +# +# This is based on RedHat 5.2. +# +if [ `uname` = 'Linux' ]; then + ipcs_id= + ipcs_cpid= + ipcs_lpid= + did_anything= + + if ps x | grep -s 'postmaster' >& /dev/null ; then + echo "$CMDNAME: You still have a postmaster running." + exit 1 + fi + + # shared memory + for val in `ipcs -m -p | grep '^[0-9]' | awk '{printf "%s %s\n", $1, $3, $4}'`; do + if [ -z "$ipcs_id" ]; then + ipcs_id=$val + # Note: We can do -n here, because we know the platform. + echo -n "Shared memory $ipcs_id ... " + continue + fi + + ipcs_lpid=$val + + # Don't do anything if process still running. + # (This check is conceptually phony, but it's + # useful anyway in practice.) + ps hj$ipcs_pid >& /dev/null + if [ $? -eq 0 ]; then + echo "skipped. Process still exists (pid $ipcs_pid)." + else + # try remove + ipcrm shm $ipcs_id + if [ $? -eq 0 ]; then + did_anything=t + else + exit + fi + fi + ipcs_id= + ipcs_cpid= + ipcs_lpid= + done + + # semaphores + for val in `ipcs -s -c | grep '^[0-9]' | awk '{printf "%s\n", $1}'`; do + echo -n "Semaphore $val ... " + # try remove + ipcrm sem $val + if [ $? -eq 0 ]; then + did_anything=t + else + exit + fi + done + + [ -z "$did_anything" ] && echo "$CMDNAME: nothing removed" && exit 1 + exit 0 +fi # end Linux + + +# This is the original implementation. It seems to work +# on FreeBSD, SunOS/Solaris, HP-UX, IRIX, and probably +# some others. + +ipcs | egrep '^m .*|^s .*' | egrep "$EffectiveUser" | \ awk '{printf "ipcrm -%s %s\n", $1, $2}' '-' | sh diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index c7bf1e3e94..0818addc53 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -21,7 +21,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.132 2000/01/16 03:54:58 tgl Exp $ + * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.133 2000/01/18 00:03:37 petere Exp $ * * Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb * @@ -69,6 +69,7 @@ #include "catalog/pg_language.h" #include "catalog/pg_trigger.h" #include "catalog/pg_type.h" +#include "version.h" #include "libpq-fe.h" #ifndef HAVE_STRDUP @@ -122,61 +123,63 @@ char g_comment_end[10]; static void -usage(const char *progname) +help(const char *progname) { - fprintf(stderr, - "\nUsage: %s [options] dbname\n\n", progname); + printf("%s dumps a database to a text file.\n\n", progname); + puts( "Usage:"); + printf(" %s [options] dbname\n\n", progname); + puts( "Options:"); #ifdef HAVE_GETOPT_LONG - fprintf(stderr, - - " -a, --data-only dump out only the data, no schema\n" - " -c, --clean clean(drop) schema prior to create\n" - " -d, --insert-proper dump data as proper insert strings\n" - " -D, --insert-attr dump data as inserts with attribute names\n" - " -f, --out file script output filename\n" - " -h, --host hostname server host name\n" - " -n, --no-quotes suppress most quotes around identifiers\n" - " -N, --quotes enable most quotes around identifiers\n" - " -o, --oids dump object id's (oids)\n" - " -p, --port port server port number\n" - " -s, --schema-only dump out only the schema, no data\n" - " -t, --table table dump for this table only\n" - " -u, --password use password authentication\n" - " -v, --verbose verbose\n" - " -x, --no-acl do not dump ACL's (grant/revoke)\n" - " -?, --help show this help message\n" - - ); /* fprintf */ + puts( + " -a, --data-only dump out only the data, not the schema\n" + " -c, --clean clean (drop) schema prior to create\n" + " -d, --inserts dump data as INSERT, rather than COPY, commands\n" + " -D, --attribute-inserts dump data as INSERT commands with attribute names\n" + " -h, --host server host 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" + " -p, --port server port number\n" + " -s, --schema-only dump out only the schema, no data\n" + " -t, --table dump for this table only\n" + " -u, --password use password authentication\n" + " -v, --verbose verbose\n" + " -x, --no-acl do not dump ACL's (grant/revoke)\n" + ); #else - fprintf(stderr, - - " -a dump out only the data, no schema\n" - " -c clean(drop) schema prior to create\n" - " -d dump data as proper insert strings\n" - " -D dump data as inserts with attribute names\n" - " -f filename script output filename\n" - " -h hostname server host name\n" - " -n suppress most quotes around identifiers\n" - " -N enable most quotes around identifiers\n" - " -o dump object id's (oids)\n" - " -p port server port number\n" - " -s dump out only the schema, no data\n" - " -t table dump for this table only\n" - " -u use password authentication\n" - " -v verbose\n" - " -x do not dump ACL's (grant/revoke)\n" - " -? show this help message\n" - - ); /* fprintf */ + puts( + " -a dump out only the data, no schema\n" + " -c clean (drop) schema prior to create\n" + " -d dump data as INSERT, rather than COPY, commands\n" + " -D dump data as INSERT commands with attribute names\n" + " -h server host name\n" + " -n suppress most quotes around identifiers\n" + " -N enable most quotes around identifiers\n" + " -O dump object ids (oids)\n" + " -p server port number\n" + " -s dump out only the schema, no data\n" + " -t
dump for this table only\n" + " -u use password authentication\n" + " -v verbose\n" + " -x do not dump ACL's (grant/revoke)\n" + ); #endif + puts("If no database name is not supplied, then the PGDATABASE environment\nvariable value is used.\n"); + puts("Report bugs to ."); +} - fprintf(stderr, - "\nIf dbname is not supplied, then the DATABASE environment variable value is used.\n\n"); - exit(1); +static void +version(void) +{ + puts("pg_dump (PostgreSQL) " PG_RELEASE "." PG_VERSION "." PG_SUBVERSION); + puts("Copyright (C) 2000 PostgreSQL Global Development Team"); + puts("Copyright (C) 1996 Regents of the University of California"); + puts("Read the file COPYING to see the usage and distribution terms."); } + static void exit_nicely(PGconn *conn) { @@ -551,14 +554,13 @@ main(int argc, char **argv) static struct option long_options[] = { {"data-only", no_argument, NULL, 'a'}, {"clean", no_argument, NULL, 'c'}, - {"insert-proper",no_argument, NULL, 'd'}, - {"insert-attr", no_argument, NULL, 'D'}, - {"out", required_argument, NULL, 'f'}, - {"to-file", required_argument, NULL, 'f'}, + {"inserts",no_argument, NULL, 'd'}, + {"attribute-inserts", no_argument, NULL, 'D'}, + {"output", required_argument, NULL, '\037'}, /* see note below */ {"host", required_argument, NULL, 'h'}, {"no-quotes", no_argument, NULL, 'n'}, {"quotes", no_argument, NULL, 'N'}, - {"oids", no_argument, NULL, 'o'}, + {"oids", no_argument, NULL, 'O'}, {"port", required_argument, NULL, 'p'}, {"schema-only", no_argument, NULL, 's'}, {"table", required_argument, NULL, 't'}, @@ -566,6 +568,7 @@ main(int argc, char **argv) {"verbose", no_argument, NULL, 'v'}, {"no-acl", no_argument, NULL, 'x'}, {"help", no_argument, NULL, '?'}, + {"version", no_argument, NULL, 'V'} }; int optindex; #endif @@ -580,12 +583,33 @@ main(int argc, char **argv) dataOnly = schemaOnly = dumpData = attrNames = false; - progname = *argv; + if (!strrchr(argv[0], SEP_CHAR)) + progname = argv[0]; + else + progname = strrchr(argv[0], SEP_CHAR) + 1; + + /* + * A note on options: + * + * The standard option for specifying an output file is -o/--output. + * The standard option for specifying an input file is -f/--file. + * pg_dump used to use -f for specifying an output file. + * Unfortunately, -o is already in use for oids. + * + * Therefore I instituted the following: + * + The -f option is gone. Most people use > for output redirection anyway + * so there is really not a big point in supporting output files. + * + If you like, and can, you can use --output, but it's not documented. + * + The preferred option for oids is now -O. -o generates a warning. + * + In the (very far) future the -o option could be used to used for + * specifying an output file. + * -- petere 2000-01-17 + */ #ifdef HAVE_GETOPT_LONG - while ((c = getopt_long(argc, argv, "acdDf:h:nNop:st:uvxz?", long_options, &optindex)) != -1) + while ((c = getopt_long(argc, argv, "acdDh:nNoOp:st:uvxzV?\037", long_options, &optindex)) != -1) #else - while ((c = getopt(argc, argv, "acdDf:h:nNop:st:uvxz?")) != -1) + while ((c = getopt(argc, argv, "acdDh:nNoOp:st:uvxzV?")) != -1) #endif { switch (c) @@ -605,7 +629,7 @@ main(int argc, char **argv) dumpData = true; attrNames = true; break; - case 'f': /* output file name */ + case '\037': /* output file name, see note above */ filename = optarg; break; case 'h': /* server host */ @@ -618,7 +642,9 @@ main(int argc, char **argv) case 'N': /* Force double-quotes on identifiers */ force_quotes = true; break; - case 'o': /* Dump oids */ + case 'o': + fprintf(stderr, "%s: The -o option for dumping oids is deprecated. Please use -O."); + case 'O': /* Dump oids */ oids = true; break; case 'p': /* server port */ @@ -662,15 +688,17 @@ main(int argc, char **argv) case 'x': /* skip ACL dump */ aclsSkip = true; break; - case 'z': /* Old ACL option bjm 1999/05/27 */ - fprintf(stderr, - "%s: The -z option(dump ACLs) is now the default, continuing.\n", - progname); - break; + case 'V': + version(); + exit(0); + break; case '?': - default: - usage(progname); + help(progname); + exit(0); break; + default: + fprintf(stderr, "%s: unknown option -%c\nTry -? for help.\n", progname, c); + exit(1); } } @@ -679,7 +707,7 @@ main(int argc, char **argv) fprintf(stderr, "%s: INSERT's can not set oids, so INSERT and OID options can not be used together.\n", progname); - exit(2); + exit(1); } /* open the output file */ @@ -697,16 +725,16 @@ main(int argc, char **argv) fprintf(stderr, "%s: could not open output file named %s for writing\n", progname, filename); - exit(2); + exit(1); } } /* find database */ if (!(dbname = argv[optind]) && - !(dbname = getenv("DATABASE"))) + !(dbname = getenv("PGDATABASE"))) { fprintf(stderr, "%s: no database name specified\n", progname); - exit(2); + exit(1); } /* g_conn = PQsetdb(pghost, pgport, NULL, NULL, dbname); */ @@ -1417,7 +1445,7 @@ getFuncs(int *numFuncs) { fprintf(stderr, "failed sanity check: %s has %d args\n", finfo[i].proname, finfo[i].nargs); - exit(2); + exit(1); } parseNumericArray(PQgetvalue(res, i, i_proargtypes), finfo[i].argtypes, @@ -2922,7 +2950,7 @@ dumpIndices(FILE *fout, IndInfo *indinfo, int numIndices, { fprintf(stderr, "failed sanity check, table %s was not found\n", indinfo[i].indrelname); - exit(2); + exit(1); } if (strcmp(indinfo[i].indproc, "0") == 0) -- 2.40.0