Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f000ffd

Browse files
committed
Add -U and -W options to pg_dump and friends to support non-interactive
specification of username (like in psql). pg_dumpall now works with password authentication.
1 parent 761a0bb commit f000ffd

File tree

11 files changed

+267
-151
lines changed

11 files changed

+267
-151
lines changed

doc/src/sgml/backup.sgml

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/backup.sgml,v 2.7 2001/03/19 16:19:26 petere Exp $ -->
1+
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/backup.sgml,v 2.8 2001/05/17 21:12:48 petere Exp $ -->
22
<chapter id="backup">
33
<title>Backup and Restore</title>
44

@@ -61,11 +61,10 @@ pg_dump <replaceable class="parameter">dbname</replaceable> &gt; <replaceable cl
6161
As any other <productname>Postgres</> client application,
6262
<application>pg_dump</> will by default connect with the database
6363
user name that is equal to the current Unix user name. To override
64-
this, either specify the <option>-u</option> option to force a prompt for
65-
the user name, or set the environment variable
66-
<envar>PGUSER</envar>. Remember that <application>pg_dump</>
67-
connections are subject to the normal client authentication
68-
mechanisms (which are described in <xref
64+
this, either specify the <option>-U</option> option or set the
65+
environment variable <envar>PGUSER</envar>. Remember that
66+
<application>pg_dump</> connections are subject to the normal
67+
client authentication mechanisms (which are described in <xref
6968
linkend="client-authentication">).
7069
</para>
7170

@@ -163,20 +162,6 @@ pg_dumpall &gt; <replaceable>outfile</>
163162
you have database superuser access, as that is required to restore
164163
the user and group information.
165164
</para>
166-
167-
<para>
168-
<application>pg_dumpall</application> has one little flaw: It is
169-
not prepared for interactively authenticating to each database it
170-
dumps. If you are using password authentication then you need to
171-
set it the environment variable <envar>PGPASSWORD</envar> to
172-
communicate the password the the underlying calls to
173-
<application>pg_dump</>. More severely, if you have different
174-
passwords set up for each database, then
175-
<application>pg_dumpall</> will fail. You can either choose a
176-
different authentication mechanism for the purposes of backup or
177-
adjust the <filename>pg_dumpall</filename> shell script to your
178-
needs.
179-
</para>
180165
</sect2>
181166

182167
<sect2 id="backup-dump-large">

doc/src/sgml/ref/pg_dump.sgml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/pg_dump.sgml,v 1.31 2001/03/17 16:27:31 petere Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/pg_dump.sgml,v 1.32 2001/05/17 21:12:48 petere Exp $
33
Postgres documentation
44
-->
55

@@ -46,7 +46,8 @@ Postgres documentation
4646
<arg>-Z <replaceable>0...9</replaceable></arg>
4747
<arg>-h <replaceable>host</replaceable></arg>
4848
<arg>-p <replaceable>port</replaceable></arg>
49-
<arg>-u</arg>
49+
<arg>-U <replaceable>username</replaceable></arg>
50+
<arg>-W</arg>
5051
<arg choice="plain"><replaceable>dbname</replaceable></arg>
5152
</cmdsynopsis>
5253
</refsynopsisdiv>
@@ -412,13 +413,20 @@ Postgres documentation
412413
</varlistentry>
413414

414415
<varlistentry>
415-
<term>-u</term>
416+
<term>-U <replaceable>username</replaceable></term>
416417
<listitem>
417418
<para>
418-
Use password authentication.
419-
Prompts for
420-
<replaceable class="parameter">username</replaceable>
421-
and <replaceable class="parameter">password</replaceable>.
419+
Connect as the given user.
420+
</para>
421+
</listitem>
422+
</varlistentry>
423+
424+
<varlistentry>
425+
<term>-W</term>
426+
<listitem>
427+
<para>
428+
Force a password prompt. This should happen automatically if
429+
the server requires password authentication.
422430
</para>
423431
</listitem>
424432
</varlistentry>

doc/src/sgml/ref/pg_dumpall.sgml

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/pg_dumpall.sgml,v 1.21 2001/03/05 18:42:57 momjian Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/pg_dumpall.sgml,v 1.22 2001/05/17 21:12:48 petere Exp $
33
Postgres documentation
44
-->
55

@@ -23,9 +23,11 @@ Postgres documentation
2323
<cmdsynopsis>
2424
<command>pg_dumpall</command>
2525
<group><arg>-c</arg><arg>--clean</arg></group>
26+
<group><arg>-g</arg><arg>--globals-only</arg></group>
2627
<arg>-h <replaceable>host</replaceable></arg>
2728
<arg>-p <replaceable>port</replaceable></arg>
28-
<group><arg>-g</arg><arg>--globals-only</arg></group>
29+
<arg>-U <replaceable>username</replaceable></arg>
30+
<arg>-W</arg>
2931
</cmdsynopsis>
3032
</refsynopsisdiv>
3133

@@ -81,6 +83,15 @@ Postgres documentation
8183
</listitem>
8284
</varlistentry>
8385

86+
<varlistentry>
87+
<term>-g, --globals-only</term>
88+
<listitem>
89+
<para>
90+
Only dump global objects (users and groups), no databases.
91+
</para>
92+
</listitem>
93+
</varlistentry>
94+
8495
<varlistentry>
8596
<term>-h <replaceable>host</replaceable></term>
8697
<listitem>
@@ -106,14 +117,23 @@ Postgres documentation
106117
</varlistentry>
107118

108119
<varlistentry>
109-
<term>-g, --globals-only</term>
120+
<term>-U <replaceable>username</replaceable></term>
110121
<listitem>
111122
<para>
112-
Only dump global objects (users and groups), no databases.
123+
Connect as the given user.
113124
</para>
114125
</listitem>
115126
</varlistentry>
116127

128+
<varlistentry>
129+
<term>-W</term>
130+
<listitem>
131+
<para>
132+
Force a password prompt. This should happen automatically if
133+
the server requires password authentication.
134+
</para>
135+
</listitem>
136+
</varlistentry>
117137
</variablelist>
118138
</para>
119139

@@ -128,8 +148,8 @@ Postgres documentation
128148
</refsect2>
129149
</refsect1>
130150

131-
<refsect1 id="app-pg-dumpall-usage">
132-
<title>Usage</title>
151+
<refsect1 id="app-pg-dumpall-ex">
152+
<title>Examples</title>
133153
<para>
134154
To dump all databases:
135155

doc/src/sgml/ref/pg_restore.sgml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/ref/pg_restore.sgml,v 1.10 2001/03/17 16:27:31 petere Exp $ -->
1+
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/ref/pg_restore.sgml,v 1.11 2001/05/17 21:12:48 petere Exp $ -->
22

33
<refentry id="APP-PGRESTORE">
44
<docinfo>
@@ -46,7 +46,8 @@
4646
<arg> -x </arg>
4747
<arg> -h <replaceable class="parameter">host</replaceable> </arg>
4848
<arg> -p <replaceable class="parameter">port</replaceable> </arg>
49-
<arg> -u </arg>
49+
<arg> -U <replaceable>username</replaceable> </arg>
50+
<arg> -W </arg>
5051
<arg> <replaceable class="parameter">archive-file</replaceable> </arg>
5152
</cmdsynopsis>
5253
</refsynopsisdiv>
@@ -448,10 +449,20 @@
448449
</varlistentry>
449450

450451
<varlistentry>
451-
<term>-u</term>
452+
<term>-U <replaceable>username</replaceable></term>
452453
<listitem>
453454
<para>
454-
Use password authentication. Prompts for user name and password.
455+
Connect as the given user.
456+
</para>
457+
</listitem>
458+
</varlistentry>
459+
460+
<varlistentry>
461+
<term>-W</term>
462+
<listitem>
463+
<para>
464+
Force a password prompt. This should happen automatically if
465+
the server requires password authentication.
455466
</para>
456467
</listitem>
457468
</varlistentry>

src/bin/pg_dump/pg_backup.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup.h,v 1.11 2001/04/25 07:03:19 pjw Exp $
18+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup.h,v 1.12 2001/05/17 21:12:48 petere Exp $
1919
*
2020
* Modifications - 28-Jun-2000 - pjw@rhyme.com.au
2121
*
@@ -114,6 +114,7 @@ typedef struct _restoreOptions
114114
char *dbname;
115115
char *pgport;
116116
char *pghost;
117+
char *username;
117118
int ignoreVersion;
118119
int requirePassword;
119120

@@ -130,12 +131,16 @@ typedef struct _restoreOptions
130131

131132
extern void exit_horribly(Archive *AH, const char *fmt,...);
132133

134+
extern char *
135+
simple_prompt(const char *prompt, int maxlen, bool echo);
136+
133137
/* Lets the archibe know we have a DB connection to shutdown if it dies */
134138

135139
PGconn *ConnectDatabase(Archive *AH,
136140
const char *dbname,
137141
const char *pghost,
138142
const char *pgport,
143+
const char *username,
139144
const int reqPwd,
140145
const int ignoreVersion);
141146

src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.26 2001/05/12 01:03:59 pjw Exp $
18+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.27 2001/05/17 21:12:48 petere Exp $
1919
*
2020
* Modifications - 28-Jun-2000 - pjw@rhyme.com.au
2121
*
@@ -180,7 +180,7 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
180180
AHX->minRemoteVersion = 070100;
181181
AHX->maxRemoteVersion = 999999;
182182

183-
ConnectDatabase(AHX, ropt->dbname, ropt->pghost, ropt->pgport,
183+
ConnectDatabase(AHX, ropt->dbname, ropt->pghost, ropt->pgport, ropt->username,
184184
ropt->requirePassword, ropt->ignoreVersion);
185185

186186
/*

src/bin/pg_dump/pg_backup_archiver.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*
1818
*
1919
* IDENTIFICATION
20-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.33 2001/05/12 01:03:59 pjw Exp $
20+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.34 2001/05/17 21:12:48 petere Exp $
2121
*
2222
* Modifications - 28-Jun-2000 - pjw@rhyme.com.au
2323
* - Initial version.
@@ -203,11 +203,12 @@ typedef struct _archiveHandle
203203
CustomOutPtr CustomOutPtr; /* Alternate script output routine */
204204

205205
/* Stuff for direct DB connection */
206-
char username[100];
206+
char *username;
207207
char *dbname; /* Name of db for connection */
208208
char *archdbname; /* DB name *read* from archive */
209209
char *pghost;
210210
char *pgport;
211+
bool requirePassword;
211212
PGconn *connection;
212213
PGconn *blobConnection; /* Connection for BLOB xref */
213214
int txActive; /* Flag set if TX active on connection */

0 commit comments

Comments
 (0)