Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit40853dd

Browse files
committed
Allow pg_dumpall to work with previous releases again. Don't pass the -c
option down to pg_dump, where it's useless, and clarify the meaning of -cin the documentation.
1 parent123baf8 commit40853dd

File tree

7 files changed

+95
-72
lines changed

7 files changed

+95
-72
lines changed

‎doc/src/sgml/ref/pg_dump.sgml

Lines changed: 12 additions & 9 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.50 2002/09/06 21:58:36 petere Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/pg_dump.sgml,v 1.51 2002/09/07 16:14:33 petere Exp $
33
PostgreSQL documentation
44
-->
55

@@ -289,14 +289,17 @@ PostgreSQL documentation
289289
<term><option>--ignore-version</></term>
290290
<listitem>
291291
<para>
292-
Ignore version mismatch between <command>pg_dump</command>
293-
and the database server. Since <command>pg_dump</command>
294-
knows a great deal about system catalogs, any given version of
295-
<command>pg_dump</command> is only intended to work with
296-
the corresponding release of the database server. Use this option
297-
if you need to override the version check (and if
298-
<command>pg_dump</command> then fails, don't
299-
say you weren't warned).
292+
Ignore version mismatch between
293+
<application>pg_dump</application> and the database server.
294+
</para>
295+
296+
<para>
297+
<application>pg_dump</application> can handle databases from
298+
previous releases of PostgreSQL, but very old versions are not
299+
supported anymore (currently prior to 7.0). Use this option
300+
if you need to override the version check (and if
301+
<application>pg_dump</application> then fails, don't say you
302+
weren't warned).
300303
</para>
301304
</listitem>
302305
</varlistentry>

‎doc/src/sgml/ref/pg_dumpall.sgml

Lines changed: 15 additions & 13 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.33 2002/09/05 22:05:50 momjian Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/pg_dumpall.sgml,v 1.34 2002/09/07 16:14:33 petere Exp $
33
PostgreSQL documentation
44
-->
55

@@ -79,13 +79,12 @@ PostgreSQL documentation
7979

8080
<variablelist>
8181
<varlistentry>
82-
<term>-c, --clean</term>
82+
<term><option>-c</option></term>
83+
<term><option>--clean</option></term>
8384
<listitem>
8485
<para>
85-
Include SQL commands to clean (drop) database objects before
86-
recreating them. (This option is fairly useless, since the
87-
output script expects to create the databases themselves;
88-
they would always be empty upon creation.)
86+
Include SQL commands to clean (drop) the databases before
87+
recreating them.
8988
</para>
9089
</listitem>
9190
</varlistentry>
@@ -120,10 +119,11 @@ PostgreSQL documentation
120119
</varlistentry>
121120

122121
<varlistentry>
123-
<term>-g, --globals-only</term>
122+
<term><option>-g</option></term>
123+
<term><option>--globals-only</option></term>
124124
<listitem>
125125
<para>
126-
Only dump global objects (users and groups), no databases.
126+
Dump only global objects (users and groups), no databases.
127127
</para>
128128
</listitem>
129129
</varlistentry>
@@ -135,11 +135,13 @@ PostgreSQL documentation
135135
<para>
136136
Ignore version mismatch between
137137
<application>pg_dumpall</application> and the database server.
138-
Since <application>pg_dumpall</application> knows a great deal
139-
about system catalogs, any given version of
140-
<application>pg_dumpall</application> is only intended to work
141-
with the corresponding release of the database server. Use
142-
this option if you need to override the version check (and if
138+
</para>
139+
140+
<para>
141+
<application>pg_dumpall</application> can handle databases
142+
from previous releases of PostgreSQL, but very old versions
143+
are not supported anymore (currently prior to 7.0). Use this
144+
option if you need to override the version check (and if
143145
<application>pg_dumpall</application> then fails, don't say
144146
you weren't warned).
145147
</para>

‎src/bin/pg_dump/dumputils.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1994, Regents of the University of California
77
*
88
*
9-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/dumputils.c,v 1.2 2002/09/04 20:31:34 momjian Exp $
9+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/dumputils.c,v 1.3 2002/09/07 16:14:33 petere Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -131,3 +131,24 @@ appendStringLiteral(PQExpBuffer buf, const char *str, bool escapeAll)
131131
}
132132
appendPQExpBufferChar(buf,'\'');
133133
}
134+
135+
136+
137+
int
138+
parse_version(constchar*versionString)
139+
{
140+
intcnt;
141+
intvmaj,
142+
vmin,
143+
vrev;
144+
145+
cnt=sscanf(versionString,"%d.%d.%d",&vmaj,&vmin,&vrev);
146+
147+
if (cnt<2)
148+
return-1;
149+
150+
if (cnt==2)
151+
vrev=0;
152+
153+
return (100*vmaj+vmin)*100+vrev;
154+
}

‎src/bin/pg_dump/dumputils.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1994, Regents of the University of California
77
*
88
*
9-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/dumputils.h,v 1.3 2002/09/04 20:31:34 momjian Exp $
9+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/dumputils.h,v 1.4 2002/09/07 16:14:33 petere Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -22,5 +22,6 @@ extern char *simple_prompt(const char *prompt, int maxlen, bool echo);
2222

2323
externconstchar*fmtId(constchar*identifier);
2424
externvoidappendStringLiteral(PQExpBufferbuf,constchar*str,boolescapeAll);
25+
externintparse_version(constchar*versionString);
2526

2627
#endif/* DUMPUTILS_H */

‎src/bin/pg_dump/pg_backup_db.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*Implements the basic DB functions used by the archiver.
66
*
77
* IDENTIFICATION
8-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.40 2002/09/04 20:31:34 momjian Exp $
8+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.41 2002/09/07 16:14:33 petere Exp $
99
*
1010
*-------------------------------------------------------------------------
1111
*/
@@ -41,20 +41,13 @@ static char *_sendCopyLine(ArchiveHandle *AH, char *qry, char *eos);
4141
staticint
4242
_parse_version(ArchiveHandle*AH,constchar*versionString)
4343
{
44-
intcnt;
45-
intvmaj,
46-
vmin,
47-
vrev;
44+
intv;
4845

49-
cnt=sscanf(versionString,"%d.%d.%d",&vmaj,&vmin,&vrev);
50-
51-
if (cnt<2)
46+
v=parse_version(versionString);
47+
if (v<0)
5248
die_horribly(AH,modulename,"unable to parse version string \"%s\"\n",versionString);
5349

54-
if (cnt==2)
55-
vrev=0;
56-
57-
return (100*vmaj+vmin)*100+vrev;
50+
returnv;
5851
}
5952

6053
staticvoid

‎src/bin/pg_dump/pg_dump.c

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*
2323
*
2424
* IDENTIFICATION
25-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.297 2002/09/04 20:31:34 momjian Exp $
25+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.298 2002/09/07 16:14:33 petere Exp $
2626
*
2727
*-------------------------------------------------------------------------
2828
*/
@@ -75,7 +75,6 @@ typedef struct _dumpContext
7575
}DumpContext;
7676

7777
staticvoidhelp(constchar*progname);
78-
staticintparse_version(constchar*versionString);
7978
staticNamespaceInfo*findNamespace(constchar*nsoid,constchar*objoid);
8079
staticvoiddumpClasses(constTableInfo*tblinfo,constintnumTables,
8180
Archive*fout,constbooloids);
@@ -535,12 +534,18 @@ main(int argc, char **argv)
535534
/* Let the archiver know how noisy to be */
536535
g_fout->verbose=g_verbose;
537536

537+
g_fout->minRemoteVersion=70000;/* we can handle back to 7.0 */
538+
g_fout->maxRemoteVersion=parse_version(PG_VERSION);
539+
if (g_fout->maxRemoteVersion<0)
540+
{
541+
write_msg(NULL,"unable to parse version string \"%s\"\n",PG_VERSION);
542+
exit(1);
543+
}
544+
538545
/*
539546
* Open the database using the Archiver, so it knows about it. Errors
540547
* mean death.
541548
*/
542-
g_fout->minRemoteVersion=70000;/* we can handle back to 7.0 */
543-
g_fout->maxRemoteVersion=parse_version(PG_VERSION);
544549
g_conn=ConnectDatabase(g_fout,dbname,pghost,pgport,username,force_password,ignore_version);
545550

546551
/*
@@ -726,28 +731,6 @@ help(const char *progname)
726731
printf(_("Report bugs to <pgsql-bugs@postgresql.org>.\n"));
727732
}
728733

729-
staticint
730-
parse_version(constchar*versionString)
731-
{
732-
intcnt;
733-
intvmaj,
734-
vmin,
735-
vrev;
736-
737-
cnt=sscanf(versionString,"%d.%d.%d",&vmaj,&vmin,&vrev);
738-
739-
if (cnt<2)
740-
{
741-
write_msg(NULL,"unable to parse version string \"%s\"\n",versionString);
742-
exit(1);
743-
}
744-
745-
if (cnt==2)
746-
vrev=0;
747-
748-
return (100*vmaj+vmin)*100+vrev;
749-
}
750-
751734
void
752735
exit_nicely(void)
753736
{

‎src/bin/pg_dump/pg_dumpall.c

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1994, Regents of the University of California
77
*
88
*
9-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.6 2002/09/04 20:31:35 momjian Exp $
9+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.7 2002/09/07 16:14:33 petere Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -56,6 +56,7 @@ char *pgdumploc;
5656
PQExpBufferpgdumpopts;
5757
booloutput_clean= false;
5858
boolverbose= false;
59+
intserver_version;
5960

6061

6162

@@ -127,7 +128,6 @@ main(int argc, char *argv[])
127128
{
128129
case'c':
129130
output_clean= true;
130-
appendPQExpBuffer(pgdumpopts," -c");
131131
break;
132132

133133
case'd':
@@ -217,10 +217,10 @@ help(void)
217217

218218
printf(_("Options:\n"));
219219
#ifdefHAVE_GETOPT_LONG
220-
printf(_(" -c, --clean clean (drop)schema prior to create\n"));
220+
printf(_(" -c, --clean clean (drop)databases prior to create\n"));
221221
printf(_(" -d, --inserts dump data as INSERT, rather than COPY, commands\n"));
222222
printf(_(" -D, --column-inserts dump data as INSERT commands with column names\n"));
223-
printf(_(" -g, --globals-onlyonlydump global objects, no databases\n"));
223+
printf(_(" -g, --globals-only dump only global objects, no databases\n"));
224224
printf(_(" -h, --host=HOSTNAME database server host name\n"));
225225
printf(_(" -i, --ignore-version proceed even when server version mismatches\n"
226226
" pg_dumpall version\n"));
@@ -230,10 +230,10 @@ help(void)
230230
printf(_(" -v, --verbose verbose mode\n"));
231231
printf(_(" -W, --password force password prompt (should happen automatically)\n"));
232232
#else/* not HAVE_GETOPT_LONG */
233-
printf(_(" -c clean (drop)schema prior to create\n"));
233+
printf(_(" -c clean (drop)databases prior to create\n"));
234234
printf(_(" -d dump data as INSERT, rather than COPY, commands\n"));
235235
printf(_(" -D dump data as INSERT commands with column names\n"));
236-
printf(_(" -gonlydump global objects, no databases\n"));
236+
printf(_(" -g dump only global objects, no databases\n"));
237237
printf(_(" -h HOSTNAME database server host name\n"));
238238
printf(_(" -i proceed even when server version mismatches\n"
239239
" pg_dumpall version\n"));
@@ -301,7 +301,8 @@ dumpUsers(PGconn *conn)
301301
printf("%s",buf->data);
302302
destroyPQExpBuffer(buf);
303303

304-
dumpUserConfig(conn,username);
304+
if (server_version >=70300)
305+
dumpUserConfig(conn,username);
305306
}
306307

307308
PQclear(res);
@@ -431,7 +432,8 @@ dumpCreateDB(PGconn *conn)
431432
printf("%s",buf->data);
432433
destroyPQExpBuffer(buf);
433434

434-
dumpDatabaseConfig(conn,dbname);
435+
if (server_version >=70300)
436+
dumpDatabaseConfig(conn,dbname);
435437
}
436438

437439
PQclear(res);
@@ -609,6 +611,7 @@ connectDatabase(const char *dbname, const char *pghost, const char *pgport,
609611
PGconn*conn;
610612
char*password=NULL;
611613
boolneed_pass= false;
614+
PGresult*res;
612615

613616
if (require_password)
614617
password=simple_prompt("Password: ",100, false);
@@ -626,7 +629,7 @@ connectDatabase(const char *dbname, const char *pghost, const char *pgport,
626629
{
627630
fprintf(stderr,_("%s: could not connect to database %s\n"),
628631
progname,dbname);
629-
exit(0);
632+
exit(1);
630633
}
631634

632635
if (PQstatus(conn)==CONNECTION_BAD&&
@@ -649,7 +652,24 @@ connectDatabase(const char *dbname, const char *pghost, const char *pgport,
649652
{
650653
fprintf(stderr,_("%s: could not connect to database %s: %s\n"),
651654
progname,dbname,PQerrorMessage(conn));
652-
exit(0);
655+
exit(1);
656+
}
657+
658+
res=executeQuery(conn,"SELECT version();");
659+
if (PQntuples(res)!=1)
660+
{
661+
fprintf(stderr,_("%s: could not get server version\n"),progname);
662+
exit(1);
663+
}
664+
else
665+
{
666+
char*val=PQgetvalue(res,0,0);
667+
server_version=parse_version(val+strcspn(val,"0123456789"));
668+
if (server_version<0)
669+
{
670+
fprintf(stderr,_("%s: could not parse server version \"%s\"\n"),progname,val);
671+
exit(1);
672+
}
653673
}
654674

655675
returnconn;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp