提交 029aa97f 编写于 作者: P Peter Eisentraut

Make sure all clients have the same understanding of default user name

and database.  In particular, make script wrappers understand the
PGDATABASE environment variable.
上级 60ac5b80
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/createdb.sgml,v 1.27 2002/07/28 15:22:20 petere Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/ref/createdb.sgml,v 1.28 2002/08/10 16:57:31 petere Exp $
PostgreSQL documentation PostgreSQL documentation
--> -->
...@@ -237,6 +237,16 @@ PostgreSQL documentation ...@@ -237,6 +237,16 @@ PostgreSQL documentation
<title>Environment</title> <title>Environment</title>
<variablelist> <variablelist>
<varlistentry>
<term><envar>PGDATABASE</envar></term>
<listitem>
<para>
If set, the name of the database to create, unless overridden on
the command line.
</para>
</listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term><envar>PGHOST</envar></term> <term><envar>PGHOST</envar></term>
<term><envar>PGPORT</envar></term> <term><envar>PGPORT</envar></term>
...@@ -246,7 +256,7 @@ PostgreSQL documentation ...@@ -246,7 +256,7 @@ PostgreSQL documentation
<para> <para>
Default connection parameters. <envar>PGUSER</envar> also Default connection parameters. <envar>PGUSER</envar> also
determines the name of the database to create, if it is not determines the name of the database to create, if it is not
specified in the command line. specified on the command line or by <envar>PGDATABASE</envar>.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -257,7 +267,6 @@ PostgreSQL documentation ...@@ -257,7 +267,6 @@ PostgreSQL documentation
<refsect1 id="R1-APP-CREATEDB-2"> <refsect1 id="R1-APP-CREATEDB-2">
<title>Examples</title> <title>Examples</title>
<informalexample>
<para> <para>
To create the database <literal>demo</literal> using the default To create the database <literal>demo</literal> using the default
database server: database server:
...@@ -268,9 +277,7 @@ PostgreSQL documentation ...@@ -268,9 +277,7 @@ PostgreSQL documentation
The response is the same as you would have gotten from running the The response is the same as you would have gotten from running the
<command>CREATE DATABASE</command> <acronym>SQL</acronym> command. <command>CREATE DATABASE</command> <acronym>SQL</acronym> command.
</para> </para>
</informalexample>
<informalexample>
<para> <para>
To create the database <literal>demo</literal> using the To create the database <literal>demo</literal> using the
server on host <literal>eden</>, port 5000, using the server on host <literal>eden</>, port 5000, using the
...@@ -282,7 +289,6 @@ PostgreSQL documentation ...@@ -282,7 +289,6 @@ PostgreSQL documentation
<computeroutput>CREATE DATABASE</computeroutput> <computeroutput>CREATE DATABASE</computeroutput>
</screen> </screen>
</para> </para>
</informalexample>
</refsect1> </refsect1>
......
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/createlang.sgml,v 1.25 2002/07/28 15:22:20 petere Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/ref/createlang.sgml,v 1.26 2002/08/10 16:57:31 petere Exp $
PostgreSQL documentation PostgreSQL documentation
--> -->
...@@ -168,6 +168,7 @@ PostgreSQL documentation ...@@ -168,6 +168,7 @@ PostgreSQL documentation
<variablelist> <variablelist>
<varlistentry> <varlistentry>
<term><envar>PGDATABASE</envar></term>
<term><envar>PGHOST</envar></term> <term><envar>PGHOST</envar></term>
<term><envar>PGPORT</envar></term> <term><envar>PGPORT</envar></term>
<term><envar>PGUSER</envar></term> <term><envar>PGUSER</envar></term>
...@@ -214,7 +215,6 @@ PostgreSQL documentation ...@@ -214,7 +215,6 @@ PostgreSQL documentation
<refsect1> <refsect1>
<title>Examples</title> <title>Examples</title>
<informalexample>
<para> <para>
To install <literal>pltcl</literal> into the database To install <literal>pltcl</literal> into the database
<literal>template1</literal>: <literal>template1</literal>:
...@@ -222,7 +222,6 @@ PostgreSQL documentation ...@@ -222,7 +222,6 @@ PostgreSQL documentation
<prompt>$ </prompt><userinput>createlang pltcl template1</userinput> <prompt>$ </prompt><userinput>createlang pltcl template1</userinput>
</screen> </screen>
</para> </para>
</informalexample>
</refsect1> </refsect1>
<refsect1> <refsect1>
......
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/createuser.sgml,v 1.26 2002/07/28 15:22:20 petere Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/ref/createuser.sgml,v 1.27 2002/08/10 16:57:31 petere Exp $
PostgreSQL documentation PostgreSQL documentation
--> -->
...@@ -128,7 +128,7 @@ PostgreSQL documentation ...@@ -128,7 +128,7 @@ PostgreSQL documentation
<listitem> <listitem>
<para> <para>
The new user is allowed to create other users. The new user is allowed to create other users.
(Note: actually, this makes the new user a <firstterm>superuser</>. (Note: Actually, this makes the new user a <firstterm>superuser</>.
The option is poorly named.) The option is poorly named.)
</para> </para>
</listitem> </listitem>
...@@ -264,7 +264,6 @@ PostgreSQL documentation ...@@ -264,7 +264,6 @@ PostgreSQL documentation
<refsect1> <refsect1>
<title>Examples</title> <title>Examples</title>
<informalexample>
<para> <para>
To create a user <literal>joe</literal> on the default database To create a user <literal>joe</literal> on the default database
server: server:
...@@ -275,9 +274,7 @@ PostgreSQL documentation ...@@ -275,9 +274,7 @@ PostgreSQL documentation
<computeroutput>CREATE USER</computeroutput> <computeroutput>CREATE USER</computeroutput>
</screen> </screen>
</para> </para>
</informalexample>
<informalexample>
<para> <para>
To create the same user <literal>joe</literal> using the To create the same user <literal>joe</literal> using the
server on host <literal>eden</>, port 5000, avoiding the prompts and server on host <literal>eden</>, port 5000, avoiding the prompts and
...@@ -288,7 +285,6 @@ PostgreSQL documentation ...@@ -288,7 +285,6 @@ PostgreSQL documentation
<computeroutput>CREATE USER</computeroutput> <computeroutput>CREATE USER</computeroutput>
</screen> </screen>
</para> </para>
</informalexample>
</refsect1> </refsect1>
......
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/dropdb.sgml,v 1.16 2002/07/28 15:22:20 petere Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/ref/dropdb.sgml,v 1.17 2002/08/10 16:57:31 petere Exp $
PostgreSQL documentation PostgreSQL documentation
--> -->
...@@ -191,7 +191,6 @@ PostgreSQL documentation ...@@ -191,7 +191,6 @@ PostgreSQL documentation
<refsect1 id="R1-APP-DROPDB-2"> <refsect1 id="R1-APP-DROPDB-2">
<title>Examples</title> <title>Examples</title>
<informalexample>
<para> <para>
To destroy the database <literal>demo</literal> on the default To destroy the database <literal>demo</literal> on the default
database server: database server:
...@@ -200,9 +199,7 @@ PostgreSQL documentation ...@@ -200,9 +199,7 @@ PostgreSQL documentation
<computeroutput>DROP DATABASE</computeroutput> <computeroutput>DROP DATABASE</computeroutput>
</screen> </screen>
</para> </para>
</informalexample>
<informalexample>
<para> <para>
To destroy the database <literal>demo</literal> using the To destroy the database <literal>demo</literal> using the
server on host <literal>eden</literal>, port 5000, with verification and a peek server on host <literal>eden</literal>, port 5000, with verification and a peek
...@@ -215,7 +212,6 @@ Are you sure? (y/n) </computeroutput><userinput>y</userinput> ...@@ -215,7 +212,6 @@ Are you sure? (y/n) </computeroutput><userinput>y</userinput>
DROP DATABASE</computeroutput> DROP DATABASE</computeroutput>
</screen> </screen>
</para> </para>
</informalexample>
</refsect1> </refsect1>
......
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/droplang.sgml,v 1.19 2002/07/28 15:22:20 petere Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/ref/droplang.sgml,v 1.20 2002/08/10 16:57:31 petere Exp $
PostgreSQL documentation PostgreSQL documentation
--> -->
...@@ -157,6 +157,7 @@ PostgreSQL documentation ...@@ -157,6 +157,7 @@ PostgreSQL documentation
<variablelist> <variablelist>
<varlistentry> <varlistentry>
<term><envar>PGDATABASE</envar></term>
<term><envar>PGHOST</envar></term> <term><envar>PGHOST</envar></term>
<term><envar>PGPORT</envar></term> <term><envar>PGPORT</envar></term>
<term><envar>PGUSER</envar></term> <term><envar>PGUSER</envar></term>
...@@ -196,14 +197,12 @@ PostgreSQL documentation ...@@ -196,14 +197,12 @@ PostgreSQL documentation
<refsect1> <refsect1>
<title>Examples</title> <title>Examples</title>
<informalexample>
<para> <para>
To remove <literal>pltcl</literal>: To remove <literal>pltcl</literal>:
<screen> <screen>
<prompt>$ </prompt><userinput>droplang pltcl dbname</userinput> <prompt>$ </prompt><userinput>droplang pltcl dbname</userinput>
</screen> </screen>
</para> </para>
</informalexample>
</refsect1> </refsect1>
<refsect1> <refsect1>
......
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/dropuser.sgml,v 1.19 2002/07/28 15:22:20 petere Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/ref/dropuser.sgml,v 1.20 2002/08/10 16:57:31 petere Exp $
PostgreSQL documentation PostgreSQL documentation
--> -->
...@@ -181,7 +181,6 @@ PostgreSQL documentation ...@@ -181,7 +181,6 @@ PostgreSQL documentation
<refsect1> <refsect1>
<title>Examples</title> <title>Examples</title>
<informalexample>
<para> <para>
To remove user <literal>joe</literal> from the default database To remove user <literal>joe</literal> from the default database
server: server:
...@@ -190,9 +189,7 @@ PostgreSQL documentation ...@@ -190,9 +189,7 @@ PostgreSQL documentation
<computeroutput>DROP USER</computeroutput> <computeroutput>DROP USER</computeroutput>
</screen> </screen>
</para> </para>
</informalexample>
<informalexample>
<para> <para>
To remove user <literal>joe</literal> using the postmaster on host To remove user <literal>joe</literal> using the postmaster on host
<literal>eden</literal>, port 5000, with verification and a peek at the underlying <literal>eden</literal>, port 5000, with verification and a peek at the underlying
...@@ -205,7 +202,6 @@ Are you sure? (y/n) </computeroutput><userinput>y</userinput> ...@@ -205,7 +202,6 @@ Are you sure? (y/n) </computeroutput><userinput>y</userinput>
DROP USER</computeroutput> DROP USER</computeroutput>
</screen> </screen>
</para> </para>
</informalexample>
</refsect1> </refsect1>
......
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/pg_dump.sgml,v 1.46 2002/07/28 15:22:20 petere Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/ref/pg_dump.sgml,v 1.47 2002/08/10 16:57:31 petere Exp $
PostgreSQL documentation PostgreSQL documentation
--> -->
...@@ -43,7 +43,7 @@ PostgreSQL documentation ...@@ -43,7 +43,7 @@ PostgreSQL documentation
<arg>-p <replaceable>port</replaceable></arg> <arg>-p <replaceable>port</replaceable></arg>
<arg>-U <replaceable>username</replaceable></arg> <arg>-U <replaceable>username</replaceable></arg>
<arg>-W</arg> <arg>-W</arg>
<arg choice="plain"><replaceable>dbname</replaceable></arg> <arg><replaceable>dbname</replaceable></arg>
</cmdsynopsis> </cmdsynopsis>
</refsynopsisdiv> </refsynopsisdiv>
...@@ -126,7 +126,10 @@ PostgreSQL documentation ...@@ -126,7 +126,10 @@ PostgreSQL documentation
<term><replaceable class="parameter">dbname</replaceable></term> <term><replaceable class="parameter">dbname</replaceable></term>
<listitem> <listitem>
<para> <para>
Specifies the name of the database to be dumped. Specifies the name of the database to be dumped. If this is
not specified, the environment variable
<envar>PGDATABASE</envar> is used. If that is not set, the
user name specified for the connection is used.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -562,7 +565,7 @@ PostgreSQL documentation ...@@ -562,7 +565,7 @@ PostgreSQL documentation
<term><option>-U <replaceable>username</replaceable></option></term> <term><option>-U <replaceable>username</replaceable></option></term>
<listitem> <listitem>
<para> <para>
Connect as the given user. Connect as the given user
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -588,15 +591,6 @@ PostgreSQL documentation ...@@ -588,15 +591,6 @@ PostgreSQL documentation
<variablelist> <variablelist>
<varlistentry> <varlistentry>
<term><envar>PGDATABASE</envar></term> <term><envar>PGDATABASE</envar></term>
<listitem>
<para>
Database to dump, unless overridden on the command line.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><envar>PGHOST</envar></term> <term><envar>PGHOST</envar></term>
<term><envar>PGPORT</envar></term> <term><envar>PGPORT</envar></term>
<term><envar>PGUSER</envar></term> <term><envar>PGUSER</envar></term>
......
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/ref/pg_restore.sgml,v 1.29 2002/07/28 15:22:20 petere Exp $ --> <!-- $Header: /cvsroot/pgsql/doc/src/sgml/ref/pg_restore.sgml,v 1.30 2002/08/10 16:57:31 petere Exp $ -->
<refentry id="APP-PGRESTORE"> <refentry id="APP-PGRESTORE">
<docinfo> <docinfo>
...@@ -475,7 +475,7 @@ ...@@ -475,7 +475,7 @@
<term><option>-U <replaceable>username</replaceable></option></term> <term><option>-U <replaceable>username</replaceable></option></term>
<listitem> <listitem>
<para> <para>
Connect as the given user. Connect as the given user
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
......
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/vacuumdb.sgml,v 1.22 2002/07/28 15:22:21 petere Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/ref/vacuumdb.sgml,v 1.23 2002/08/10 16:57:31 petere Exp $
PostgreSQL documentation PostgreSQL documentation
--> -->
...@@ -75,6 +75,11 @@ PostgreSQL documentation ...@@ -75,6 +75,11 @@ PostgreSQL documentation
<listitem> <listitem>
<para> <para>
Specifies the name of the database to be cleaned or analyzed. Specifies the name of the database to be cleaned or analyzed.
If this is not specified and <option>-a</option> (or
<option>--all</option>) is not used, the database name is read
from the environment variable <envar>PGDATABASE</envar>. If
that is not set, the user name specified for the connection is
used.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -251,6 +256,7 @@ PostgreSQL documentation ...@@ -251,6 +256,7 @@ PostgreSQL documentation
<variablelist> <variablelist>
<varlistentry> <varlistentry>
<term><envar>PGDATABASE</envar></term>
<term><envar>PGHOST</envar></term> <term><envar>PGHOST</envar></term>
<term><envar>PGPORT</envar></term> <term><envar>PGPORT</envar></term>
<term><envar>PGUSER</envar></term> <term><envar>PGUSER</envar></term>
...@@ -268,16 +274,13 @@ PostgreSQL documentation ...@@ -268,16 +274,13 @@ PostgreSQL documentation
<refsect1> <refsect1>
<title>Examples</title> <title>Examples</title>
<informalexample>
<para> <para>
To clean the database <literal>test</literal>: To clean the database <literal>test</literal>:
<screen> <screen>
<prompt>$ </prompt><userinput>vacuumdb test</userinput> <prompt>$ </prompt><userinput>vacuumdb test</userinput>
</screen> </screen>
</para> </para>
</informalexample>
<informalexample>
<para> <para>
To clean and analyze for the optimizer a database named To clean and analyze for the optimizer a database named
<literal>bigdb</literal>: <literal>bigdb</literal>:
...@@ -285,9 +288,7 @@ PostgreSQL documentation ...@@ -285,9 +288,7 @@ PostgreSQL documentation
<prompt>$ </prompt><userinput>vacuumdb --analyze bigdb</userinput> <prompt>$ </prompt><userinput>vacuumdb --analyze bigdb</userinput>
</screen> </screen>
</para> </para>
</informalexample>
<informalexample>
<para> <para>
To clean a single table To clean a single table
<literal>foo</literal> in a database named <literal>foo</literal> in a database named
...@@ -297,7 +298,6 @@ PostgreSQL documentation ...@@ -297,7 +298,6 @@ PostgreSQL documentation
<prompt>$ </prompt><userinput>vacuumdb --analyze --verbose --table 'foo(bar)' xyzzy</userinput> <prompt>$ </prompt><userinput>vacuumdb --analyze --verbose --table 'foo(bar)' xyzzy</userinput>
</screen> </screen>
</para> </para>
</informalexample>
</refsect1> </refsect1>
......
...@@ -11,61 +11,11 @@ ...@@ -11,61 +11,11 @@
* as this notice is not removed. * as this notice is not removed.
* *
* The author is not responsible for loss or damages that may * The author is not responsible for loss or damages that may
* result from it's use. * result from its use.
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.52 2002/07/04 15:35:07 momjian Exp $ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.53 2002/08/10 16:57:31 petere Exp $
*
* Modifications - 28-Jun-2000 - pjw@rhyme.com.au
*
* Initial version.
*
* Modifications - 31-Jul-2000 - pjw@rhyme.com.au (1.46, 1.47)
* Fixed version number initialization in _allocAH (pg_backup_archiver.c)
*
*
* Modifications - 30-Oct-2000 - pjw@rhyme.com.au
* Added {Start,End}RestoreBlobs to allow extended TX during BLOB restore.
*
* Modifications - 04-Jan-2001 - pjw@rhyme.com.au
* - strdup() the current user just in case it's deallocated from it's TOC
* entry. Should *never* happen, but that's what they said about the
* Titanic...
*
* - Check results of IO routines more carefully.
*
* Modifications - 27-Jan-2001 - pjw@rhyme.com.au
* - When dropping the schema, reconnect as owner of each object.
*
* Modifications - 6-Mar-2001 - pjw@rhyme.com.au
* - Only disable triggers in DataOnly (or implied data-only) restores.
*
* Modifications - 31-Mar-2001 - pjw@rhyme.com.au
*
* - Rudimentary support for dependencies in archives. Current implementation
* uses dependencies to modify the OID used in sorting TOC entries.
* This will NOT handle multi-level dependencies, but will manage simple
* relationships like UDTs & their functions.
*
* - Treat OIDs with more respect (avoid using ints, use macros for
* conversion & comparison).
*
* Modifications - 10-May-2001 - pjw@rhyme.com.au
* - Treat SEQUENCE SET TOC entries as data entries rather than schema
* entries.
* - Make allowance for data entries that did not have a data dumper
* routine (eg. SEQUENCE SET)
*
* Modifications - 01-Nov-2001 - pjw@rhyme.com.au
* - Fix handling of {data/schema}-only restores when using a full
* backup file; prior version was restoring schema in data-only
* restores. Added enum to make code easier to understand.
*
* Modifications - 18-Jan-2002 - pjw@rhyme.com.au
* - Modified _tocEntryRequired to handle '<Init>/Max OID' as a special
* case (ie. as a DATA item) as per bugs reported by Bruce Momjian
* around 17-Jan-2002.
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -2263,7 +2213,7 @@ WriteHead(ArchiveHandle *AH) ...@@ -2263,7 +2213,7 @@ WriteHead(ArchiveHandle *AH)
WriteInt(AH, crtm.tm_mon); WriteInt(AH, crtm.tm_mon);
WriteInt(AH, crtm.tm_year); WriteInt(AH, crtm.tm_year);
WriteInt(AH, crtm.tm_isdst); WriteInt(AH, crtm.tm_isdst);
WriteStr(AH, AH->dbname); WriteStr(AH, PQdb(AH->connection));
} }
void void
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.44 2002/07/04 15:35:07 momjian Exp $ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.45 2002/08/10 16:57:31 petere Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -195,11 +195,7 @@ typedef struct _archiveHandle ...@@ -195,11 +195,7 @@ typedef struct _archiveHandle
CustomOutPtr CustomOutPtr; /* Alternate script output routine */ CustomOutPtr CustomOutPtr; /* Alternate script output routine */
/* Stuff for direct DB connection */ /* Stuff for direct DB connection */
char *username;
char *dbname; /* Name of db for connection */
char *archdbname; /* DB name *read* from archive */ char *archdbname; /* DB name *read* from archive */
char *pghost;
char *pgport;
bool requirePassword; bool requirePassword;
PGconn *connection; PGconn *connection;
PGconn *blobConnection; /* Connection for BLOB xref */ PGconn *blobConnection; /* Connection for BLOB xref */
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* Implements the basic DB functions used by the archiver. * Implements the basic DB functions used by the archiver.
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.35 2002/07/06 20:12:30 momjian Exp $ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.36 2002/08/10 16:57:31 petere Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -129,10 +129,6 @@ ReconnectToServer(ArchiveHandle *AH, const char *dbname, const char *username) ...@@ -129,10 +129,6 @@ ReconnectToServer(ArchiveHandle *AH, const char *dbname, const char *username)
PQfinish(AH->connection); PQfinish(AH->connection);
AH->connection = newConn; AH->connection = newConn;
free(AH->username);
AH->username = strdup(newusername);
/* XXX Why don't we update AH->dbname? */
/* don't assume we still know the output schema */ /* don't assume we still know the output schema */
if (AH->currSchema) if (AH->currSchema)
free(AH->currSchema); free(AH->currSchema);
...@@ -241,26 +237,6 @@ ConnectDatabase(Archive *AHX, ...@@ -241,26 +237,6 @@ ConnectDatabase(Archive *AHX,
if (AH->connection) if (AH->connection)
die_horribly(AH, modulename, "already connected to a database\n"); die_horribly(AH, modulename, "already connected to a database\n");
if (!dbname && !(dbname = getenv("PGDATABASE")))
die_horribly(AH, modulename, "no database name specified\n");
AH->dbname = strdup(dbname);
if (pghost != NULL)
AH->pghost = strdup(pghost);
else
AH->pghost = NULL;
if (pgport != NULL)
AH->pgport = strdup(pgport);
else
AH->pgport = NULL;
if (username != NULL)
AH->username = strdup(username);
else
AH->username = NULL;
if (reqPwd) if (reqPwd)
{ {
password = simple_prompt("Password: ", 100, false); password = simple_prompt("Password: ", 100, false);
...@@ -278,8 +254,8 @@ ConnectDatabase(Archive *AHX, ...@@ -278,8 +254,8 @@ ConnectDatabase(Archive *AHX,
do do
{ {
need_pass = false; need_pass = false;
AH->connection = PQsetdbLogin(AH->pghost, AH->pgport, NULL, NULL, AH->connection = PQsetdbLogin(pghost, pgport, NULL, NULL,
AH->dbname, AH->username, password); dbname, username, password);
if (!AH->connection) if (!AH->connection)
die_horribly(AH, modulename, "failed to connect to database\n"); die_horribly(AH, modulename, "failed to connect to database\n");
...@@ -302,7 +278,7 @@ ConnectDatabase(Archive *AHX, ...@@ -302,7 +278,7 @@ ConnectDatabase(Archive *AHX,
/* check to see that the backend connection was successfully made */ /* check to see that the backend connection was successfully made */
if (PQstatus(AH->connection) == CONNECTION_BAD) if (PQstatus(AH->connection) == CONNECTION_BAD)
die_horribly(AH, modulename, "connection to database \"%s\" failed: %s", die_horribly(AH, modulename, "connection to database \"%s\" failed: %s",
AH->dbname, PQerrorMessage(AH->connection)); PQdb(AH->connection), PQerrorMessage(AH->connection));
/* check for version mismatch */ /* check for version mismatch */
_check_database_version(AH, ignoreVersion); _check_database_version(AH, ignoreVersion);
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.280 2002/08/04 05:03:29 momjian Exp $ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.281 2002/08/10 16:57:31 petere Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -480,16 +480,9 @@ main(int argc, char **argv) ...@@ -480,16 +480,9 @@ main(int argc, char **argv)
exit(1); exit(1);
} }
/* Get the target database name */ /* Get database name from command line */
if (optind < argc) if (optind < argc)
dbname = argv[optind]; dbname = argv[optind];
else
dbname = getenv("PGDATABASE");
if (!dbname)
{
write_msg(NULL, "no database name specified\n");
exit(1);
}
if (dataOnly && schemaOnly) if (dataOnly && schemaOnly)
{ {
...@@ -588,7 +581,7 @@ main(int argc, char **argv) ...@@ -588,7 +581,7 @@ main(int argc, char **argv)
if (g_fout->remoteVersion < 70300) if (g_fout->remoteVersion < 70300)
{ {
if (g_fout->remoteVersion >= 70100) if (g_fout->remoteVersion >= 70100)
g_last_builtin_oid = findLastBuiltinOid_V71(dbname); g_last_builtin_oid = findLastBuiltinOid_V71(PQdb(((ArchiveHandle *)g_conn)->connection));
else else
g_last_builtin_oid = findLastBuiltinOid_V70(); g_last_builtin_oid = findLastBuiltinOid_V70();
if (g_verbose) if (g_verbose)
......
...@@ -30,11 +30,11 @@ ...@@ -30,11 +30,11 @@
* as this notice is not removed. * as this notice is not removed.
* *
* The author is not responsible for loss or damages that may * The author is not responsible for loss or damages that may
* result from it's use. * result from its use.
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_restore.c,v 1.37 2002/07/11 02:00:14 momjian Exp $ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_restore.c,v 1.38 2002/08/10 16:57:32 petere Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
......
...@@ -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.52 2002/07/15 01:56:25 momjian Exp $ * $Header: /cvsroot/pgsql/src/bin/psql/help.c,v 1.53 2002/08/10 16:57:32 petere Exp $
*/ */
#include "postgres_fe.h" #include "postgres_fe.h"
#include "print.h" #include "print.h"
...@@ -58,7 +58,7 @@ usage(void) ...@@ -58,7 +58,7 @@ usage(void)
#endif #endif
/* Find default user, in case we need it. */ /* Find default user, in case we need it. */
user = getenv("USER"); user = getenv("PGUSER");
if (!user) if (!user)
{ {
#ifndef WIN32 #ifndef WIN32
...@@ -70,9 +70,13 @@ usage(void) ...@@ -70,9 +70,13 @@ usage(void)
psql_error("could not get current user name: %s\n", strerror(errno)); psql_error("could not get current user name: %s\n", strerror(errno));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
#else #else /* WIN32 */
user = "?"; char buf[128];
#endif DWORD bufsize = sizeof(buf) - 1;
if (GetUserName(buf, &bufsize))
user = buf;
#endif /* WIN32 */
} }
/* If this " is the start of the string then it ought to end there to fit in 80 columns >> " */ /* If this " is the start of the string then it ought to end there to fit in 80 columns >> " */
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
# #
# #
# IDENTIFICATION # IDENTIFICATION
# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createdb,v 1.23 2002/06/20 20:29:42 momjian Exp $ # $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createdb,v 1.24 2002/08/10 16:57:32 petere Exp $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
...@@ -166,7 +166,9 @@ then ...@@ -166,7 +166,9 @@ then
fi fi
if [ -z "$dbname" ]; then if [ -z "$dbname" ]; then
if [ "$PGUSER" ]; then if [ "$PGDATABASE" ]; then
dbname="$PGDATABASE"
elif [ "$PGUSER" ]; then
dbname="$PGUSER" dbname="$PGUSER"
else else
dbname=`${PATHNAME}pg_id -u -n` dbname=`${PATHNAME}pg_id -u -n`
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
# Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group # Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
# Portions Copyright (c) 1994, Regents of the University of California # Portions Copyright (c) 1994, Regents of the University of California
# #
# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createlang.sh,v 1.36 2002/06/20 20:29:42 momjian Exp $ # $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createlang.sh,v 1.37 2002/08/10 16:57:32 petere Exp $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
...@@ -147,7 +147,9 @@ fi ...@@ -147,7 +147,9 @@ fi
if [ -z "$dbname" ]; then if [ -z "$dbname" ]; then
if [ "$PGUSER" ]; then if [ "$PGDATABASE" ]; then
dbname="$PGDATABASE"
elif [ "$PGUSER" ]; then
dbname="$PGUSER" dbname="$PGUSER"
else else
dbname=`${PATHNAME}pg_id -u -n` dbname=`${PATHNAME}pg_id -u -n`
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
# Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group # Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
# Portions Copyright (c) 1994, Regents of the University of California # Portions Copyright (c) 1994, Regents of the University of California
# #
# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/droplang,v 1.23 2002/06/20 20:29:42 momjian Exp $ # $Header: /cvsroot/pgsql/src/bin/scripts/Attic/droplang,v 1.24 2002/08/10 16:57:32 petere Exp $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
...@@ -136,7 +136,9 @@ fi ...@@ -136,7 +136,9 @@ fi
if [ -z "$dbname" ]; then if [ -z "$dbname" ]; then
if [ "$PGUSER" ]; then if [ "$PGDATABASE" ]; then
dbname="$PGDATABASE"
elif [ "$PGUSER" ]; then
dbname="$PGUSER" dbname="$PGUSER"
else else
dbname=`${PATHNAME}pg_id -u -n` dbname=`${PATHNAME}pg_id -u -n`
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
# #
# #
# IDENTIFICATION # IDENTIFICATION
# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/vacuumdb,v 1.22 2002/06/20 20:29:42 momjian Exp $ # $Header: /cvsroot/pgsql/src/bin/scripts/Attic/vacuumdb,v 1.23 2002/08/10 16:57:32 petere Exp $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
...@@ -156,7 +156,9 @@ if [ "$alldb" ]; then ...@@ -156,7 +156,9 @@ if [ "$alldb" ]; then
dbname=`${PATHNAME}psql $PSQLOPT -q -t -A -d template1 -c 'SELECT datname FROM pg_database WHERE datallowconn'` dbname=`${PATHNAME}psql $PSQLOPT -q -t -A -d template1 -c 'SELECT datname FROM pg_database WHERE datallowconn'`
elif [ -z "$dbname" ]; then elif [ -z "$dbname" ]; then
if [ "$PGUSER" ]; then if [ "$PGDATABASE" ]; then
dbname="$PGDATABASE"
elif [ "$PGUSER" ]; then
dbname="$PGUSER" dbname="$PGUSER"
else else
dbname=`${PATHNAME}pg_id -u -n` dbname=`${PATHNAME}pg_id -u -n`
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册