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

Commit1314983

Browse files
committed
Code review for --no-data-for-failed-tables patch. Instead of trashing
one of the program's core data structures, make use of the existingability to selectively exclude TOC items by ID. Slightly more code butmuch less likely to create future maintenance problems.
1 parentf58eac8 commit1314983

File tree

4 files changed

+61
-31
lines changed

4 files changed

+61
-31
lines changed

‎doc/src/sgml/ref/pg_restore.sgml

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/ref/pg_restore.sgml,v 1.62 2006/10/07 20:59:04 petere Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/ref/pg_restore.sgml,v 1.63 2006/10/14 23:07:22 tgl Exp $ -->
22

33
<refentry id="APP-PGRESTORE">
44
<refmeta>
@@ -396,15 +396,23 @@
396396
</varlistentry>
397397

398398
<varlistentry>
399-
<term><option>--no-data-for-failed-tables</></term>
399+
<term><option>--no-data-for-failed-tables</option></term>
400400
<listitem>
401401
<para>
402-
By default, table data objects are restored even if the
403-
associated table could not be successfully created (e. g.
404-
because it already exists). With this option, such table
405-
data is silently ignored. This is useful for dumping and
406-
restoring databases with tables which contain auxiliary data
407-
for PostgreSQL extensions (e. g. PostGIS).
402+
By default, table data is restored even if the creation command
403+
for the table failed (e.g., because it already exists).
404+
With this option, data for such a table is skipped.
405+
This behavior is useful when the target database may already
406+
contain the desired table contents. For example,
407+
auxiliary tables for <productname>PostgreSQL</> extensions
408+
such as <productname>PostGIS</> may already be loaded in
409+
the target database; specifying this option prevents duplicate
410+
or obsolete data from being loaded into them.
411+
</para>
412+
413+
<para>
414+
This option is effective only when restoring directly into a
415+
database, not when producing SQL script output.
408416
</para>
409417
</listitem>
410418
</varlistentry>

‎src/bin/pg_dump/pg_backup.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup.h,v 1.43 2006/10/04 00:30:05 momjian Exp $
18+
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup.h,v 1.44 2006/10/14 23:07:22 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -112,15 +112,12 @@ typedef struct _restoreOptions
112112
intnoDataForFailedTables;
113113
intrequirePassword;
114114
intexit_on_error;
115-
116-
bool*idWanted;
117-
boollimitToList;
118115
intcompression;
119-
120116
intsuppressDumpWarnings;/* Suppress output of WARNING entries
121117
* to stderr */
122118
boolsingle_txn;
123119

120+
bool*idWanted;/* array showing which dump IDs to emit */
124121
}RestoreOptions;
125122

126123
/*
@@ -176,8 +173,9 @@ extern void PrintTOCSummary(Archive *AH, RestoreOptions *ropt);
176173

177174
externRestoreOptions*NewRestoreOptions(void);
178175

179-
/* Rearrange TOC entries */
180-
externvoidSortTocFromFile(Archive*AH,RestoreOptions*ropt);
176+
/* Rearrange and filter TOC entries */
177+
externvoidSortTocFromFile(Archive*AHX,RestoreOptions*ropt);
178+
externvoidInitDummyWantedList(Archive*AHX,RestoreOptions*ropt);
181179

182180
/* Convenience functions used only when writing DATA */
183181
externintarchputs(constchar*s,Archive*AH);

‎src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.136 2006/10/04 00:30:05 momjian Exp $
18+
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.137 2006/10/14 23:07:22 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -279,23 +279,27 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
279279
defnDumped= true;
280280

281281
/*
282-
* If we could not create a table, ignore the respective TABLE
283-
*DATA if -X no-data-for-failed-tables is given
282+
* If we could not create a table and --no-data-for-failed-tables
283+
*was given, ignore the corresponding TABLE DATA
284284
*/
285-
if (ropt->noDataForFailedTables&&AH->lastErrorTE==te&&strcmp(te->desc,"TABLE")==0)
285+
if (ropt->noDataForFailedTables&&
286+
AH->lastErrorTE==te&&
287+
strcmp(te->desc,"TABLE")==0)
286288
{
287-
TocEntry*tes,
288-
*last;
289+
TocEntry*tes;
289290

290-
ahlog(AH,1,"table %s could not be created, will not restore its data\n",te->tag);
291+
ahlog(AH,1,"table \"%s\" could not be created, will not restore its data\n",
292+
te->tag);
291293

292-
for (last=te,tes=te->next;tes!=AH->toc;last=tes,tes=tes->next)
294+
for (tes=te->next;tes!=AH->toc;tes=tes->next)
293295
{
294-
if (strcmp(tes->desc,"TABLE DATA")==0&&strcmp(tes->tag,te->tag)==0&&
295-
strcmp(tes->namespace ?tes->namespace :"",te->namespace ?te->namespace :"")==0)
296+
if (strcmp(tes->desc,"TABLE DATA")==0&&
297+
strcmp(tes->tag,te->tag)==0&&
298+
strcmp(tes->namespace ?tes->namespace :"",
299+
te->namespace ?te->namespace :"")==0)
296300
{
297-
/*remove this node */
298-
last->next=tes->next;
301+
/*mark it unwanted */
302+
ropt->idWanted[tes->dumpId-1]= false;
299303
break;
300304
}
301305
}
@@ -789,7 +793,6 @@ SortTocFromFile(Archive *AHX, RestoreOptions *ropt)
789793
/* Allocate space for the 'wanted' array, and init it */
790794
ropt->idWanted= (bool*)malloc(sizeof(bool)*AH->maxDumpId);
791795
memset(ropt->idWanted,0,sizeof(bool)*AH->maxDumpId);
792-
ropt->limitToList= true;
793796

794797
/* Set prev entry as head of list */
795798
tePrev=AH->toc;
@@ -837,6 +840,19 @@ SortTocFromFile(Archive *AHX, RestoreOptions *ropt)
837840
strerror(errno));
838841
}
839842

843+
/*
844+
* Set up a dummy ID filter that selects all dump IDs
845+
*/
846+
void
847+
InitDummyWantedList(Archive*AHX,RestoreOptions*ropt)
848+
{
849+
ArchiveHandle*AH= (ArchiveHandle*)AHX;
850+
851+
/* Allocate space for the 'wanted' array, and init it to 1's */
852+
ropt->idWanted= (bool*)malloc(sizeof(bool)*AH->maxDumpId);
853+
memset(ropt->idWanted,1,sizeof(bool)*AH->maxDumpId);
854+
}
855+
840856
/**********************
841857
* 'Convenience functions that look like standard IO functions
842858
* for writing data when in dump mode.
@@ -2066,8 +2082,8 @@ _tocEntryRequired(TocEntry *te, RestoreOptions *ropt, bool include_acls)
20662082
if (!te->defn||strlen(te->defn)==0)
20672083
res=res& ~REQ_SCHEMA;
20682084

2069-
/* Finally, ifwe used a list, limit based on that as well */
2070-
if (ropt->limitToList&& !ropt->idWanted[te->dumpId-1])
2085+
/* Finally, ifthere's a per-ID filter, limit based on that as well */
2086+
if (ropt->idWanted&& !ropt->idWanted[te->dumpId-1])
20712087
return0;
20722088

20732089
returnres;

‎src/bin/pg_dump/pg_restore.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
*
3535
*
3636
* IDENTIFICATION
37-
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_restore.c,v 1.83 2006/10/07 20:59:05 petere Exp $
37+
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_restore.c,v 1.84 2006/10/14 23:07:22 tgl Exp $
3838
*
3939
*-------------------------------------------------------------------------
4040
*/
@@ -338,6 +338,14 @@ main(int argc, char **argv)
338338

339339
if (opts->tocFile)
340340
SortTocFromFile(AH,opts);
341+
elseif (opts->noDataForFailedTables)
342+
{
343+
/*
344+
* we implement this option by clearing idWanted entries, so must
345+
* create a dummy idWanted array if there wasn't a tocFile
346+
*/
347+
InitDummyWantedList(AH,opts);
348+
}
341349

342350
if (opts->tocSummary)
343351
PrintTOCSummary(AH,opts);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp