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

Commit aa28eeb

Browse files
committed
- Only disable triggers in DataOnly (or implied data-only) restores.
- Change -U option to -L to allow -U to specify username in future.� (pg_restore)
1 parent 0ab27ad commit aa28eeb

File tree

3 files changed

+83
-45
lines changed

3 files changed

+83
-45
lines changed

src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
* Modifications - 27-Jan-2001 - pjw@rhyme.com.au
3838
* - When dropping the schema, reconnect as owner of each object.
3939
*
40+
* Modifications - 6-Mar-2001 - pjw@rhyme.com.au
41+
* - Only disable triggers in DataOnly (or implied data-only) restores.
42+
*
4043
*-------------------------------------------------------------------------
4144
*/
4245

@@ -65,8 +68,8 @@ static void _reconnectAsOwner(ArchiveHandle* AH, const char *dbname, TocEntry*
6568
static void _reconnectAsUser(ArchiveHandle* AH, const char *dbname, char *user);
6669

6770
static int _tocEntryRequired(TocEntry* te, RestoreOptions *ropt);
68-
static void _disableTriggers(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt);
69-
static void _enableTriggers(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt);
71+
static void _disableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt);
72+
static void _enableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt);
7073
static TocEntry* _getTocEntry(ArchiveHandle* AH, int id);
7174
static void _moveAfter(ArchiveHandle* AH, TocEntry* pos, TocEntry* te);
7275
static void _moveBefore(ArchiveHandle* AH, TocEntry* pos, TocEntry* te);
@@ -128,8 +131,9 @@ void RestoreArchive(Archive* AHX, RestoreOptions *ropt)
128131
{
129132
ArchiveHandle* AH = (ArchiveHandle*) AHX;
130133
TocEntry *te = AH->toc->next;
131-
int reqs;
134+
int reqs;
132135
OutputContext sav;
136+
int impliedDataOnly;
133137

134138
AH->ropt = ropt;
135139

@@ -159,6 +163,33 @@ void RestoreArchive(Archive* AHX, RestoreOptions *ropt)
159163

160164
}
161165

166+
/*
167+
* Work out if we have an implied data-only retore. This can happen if
168+
* the dump was data only or if the user has used a toc list to exclude
169+
* all of the schema data. All we do is look for schema entries - if none
170+
* are found then we set the dataOnly flag.
171+
*
172+
* We could scan for wanted TABLE entries, but that is not the same as
173+
* dataOnly. At this stage, it seems unnecessary (6-Mar-2001).
174+
*/
175+
if (!ropt->dataOnly) {
176+
te = AH->toc->next;
177+
impliedDataOnly = 1;
178+
while (te != AH->toc) {
179+
reqs = _tocEntryRequired(te, ropt);
180+
if ( (reqs & 1) != 0 ) { /* It's schema, and it's wanted */
181+
impliedDataOnly = 0;
182+
break;
183+
}
184+
te = te->next;
185+
}
186+
if (impliedDataOnly)
187+
{
188+
ropt->dataOnly = impliedDataOnly;
189+
ahlog(AH, 1, "Implied data-only restore\n", te->desc, te->name);
190+
}
191+
}
192+
162193
if (!ropt->superuser)
163194
fprintf(stderr, "\n%s: ******** WARNING ******** \n"
164195
" Data restoration may fail since any defined triggers\n"
@@ -244,7 +275,7 @@ void RestoreArchive(Archive* AHX, RestoreOptions *ropt)
244275

245276
} else {
246277

247-
_disableTriggers(AH, te, ropt);
278+
_disableTriggersIfNecessary(AH, te, ropt);
248279

249280
/* Reconnect if necessary (_disableTriggers may have reconnected) */
250281
_reconnectAsOwner(AH, "-", te);
@@ -263,7 +294,7 @@ void RestoreArchive(Archive* AHX, RestoreOptions *ropt)
263294

264295
(*AH->PrintTocDataPtr)(AH, te, ropt);
265296

266-
_enableTriggers(AH, te, ropt);
297+
_enableTriggersIfNecessary(AH, te, ropt);
267298
}
268299
}
269300
te = te->next;
@@ -275,7 +306,7 @@ void RestoreArchive(Archive* AHX, RestoreOptions *ropt)
275306
if (_canRestoreBlobs(AH) && AH->createdBlobXref)
276307
{
277308
/* NULL parameter means disable ALL user triggers */
278-
_disableTriggers(AH, NULL, ropt);
309+
_disableTriggersIfNecessary(AH, NULL, ropt);
279310

280311
te = AH->toc->next;
281312
while (te != AH->toc) {
@@ -302,7 +333,7 @@ void RestoreArchive(Archive* AHX, RestoreOptions *ropt)
302333
}
303334

304335
/* NULL parameter means enable ALL user triggers */
305-
_enableTriggers(AH, NULL, ropt);
336+
_enableTriggersIfNecessary(AH, NULL, ropt);
306337
}
307338

308339
/*
@@ -349,12 +380,13 @@ static int _canRestoreBlobs(ArchiveHandle *AH)
349380
return _restoringToDB(AH);
350381
}
351382

352-
static void _disableTriggers(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt)
383+
static void _disableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt)
353384
{
354385
char *oldUser = NULL;
355386

356387
/* Can't do much if we're connected & don't have a superuser */
357-
if (_restoringToDB(AH) && !ropt->superuser)
388+
/* Also, don't bother with triggers unless a data-only retore. */
389+
if ( !ropt->dataOnly || (_restoringToDB(AH) && !ropt->superuser) )
358390
return;
359391

360392
/*
@@ -404,12 +436,13 @@ static void _disableTriggers(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ro
404436
}
405437
}
406438

407-
static void _enableTriggers(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt)
439+
static void _enableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt)
408440
{
409441
char *oldUser = NULL;
410442

411443
/* Can't do much if we're connected & don't have a superuser */
412-
if (_restoringToDB(AH) && !ropt->superuser)
444+
/* Also, don't bother with triggers unless a data-only retore. */
445+
if ( !ropt->dataOnly || (_restoringToDB(AH) && !ropt->superuser) )
413446
return;
414447

415448
/*

src/bin/pg_dump/pg_backup_archiver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ typedef z_stream *z_streamp;
6262

6363
#define K_VERS_MAJOR 1
6464
#define K_VERS_MINOR 4
65-
#define K_VERS_REV 28
65+
#define K_VERS_REV 29
6666

6767
/* Data block types */
6868
#define BLK_DATA 1

src/bin/pg_dump/pg_restore.c

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
* Cleaned up code for reconnecting to database.
4848
* Force a reconnect as superuser before enabling/disabling triggers.
4949
*
50+
* Modifications - 6-Mar-2001 - pjw@rhyme.com.au
51+
* Change -U option to -L to allow -U to specify username in future.
52+
*
5053
*-------------------------------------------------------------------------
5154
*/
5255

@@ -100,7 +103,7 @@ struct option cmdopts[] = {
100103
{ "superuser", 1, NULL, 'S' },
101104
{ "table", 2, NULL, 't'},
102105
{ "trigger", 2, NULL, 'T' },
103-
{ "use-list", 1, NULL, 'U'},
106+
{ "use-list", 1, NULL, 'L'},
104107
{ "verbose", 0, NULL, 'v' },
105108
{ NULL, 0, NULL, 0}
106109
};
@@ -135,9 +138,9 @@ int main(int argc, char **argv)
135138
}
136139

137140
#ifdef HAVE_GETOPT_LONG
138-
while ((c = getopt_long(argc, argv, "acCd:f:F:h:i:lNoOp:P:rRsS:t:T:uU:vx", cmdopts, NULL)) != EOF)
141+
while ((c = getopt_long(argc, argv, "acCd:f:F:h:i:lL:NoOp:P:rRsS:t:T:uvx", cmdopts, NULL)) != EOF)
139142
#else
140-
while ((c = getopt(argc, argv, "acCd:f:F:h:i:lNoOp:P:rRsS:t:T:uU:vx")) != -1)
143+
while ((c = getopt(argc, argv, "acCd:f:F:h:i:lL:NoOp:P:rRsS:t:T:uvx")) != -1)
141144
#endif
142145
{
143146
switch (c)
@@ -173,6 +176,15 @@ int main(int argc, char **argv)
173176
case 'i':
174177
opts->ignoreVersion = 1;
175178
break;
179+
180+
case 'l': /* Dump the TOC summary */
181+
opts->tocSummary = 1;
182+
break;
183+
184+
case 'L': /* input TOC summary file name */
185+
opts->tocFile = strdup(optarg);
186+
break;
187+
176188
case 'N':
177189
opts->origOrder = 1;
178190
break;
@@ -219,18 +231,11 @@ int main(int argc, char **argv)
219231
opts->selTable = 1;
220232
opts->tableNames = _cleanupName(optarg);
221233
break;
222-
case 'l': /* Dump the TOC summary */
223-
opts->tocSummary = 1;
224-
break;
225234

226235
case 'u':
227236
opts->requirePassword = 1;
228237
break;
229238

230-
case 'U': /* input TOC summary file name */
231-
opts->tocFile = strdup(optarg);
232-
break;
233-
234239
case 'v': /* verbose */
235240
opts->verbose = 1;
236241
break;
@@ -251,29 +256,29 @@ int main(int argc, char **argv)
251256

252257
if (opts->formatName) {
253258

254-
switch (opts->formatName[0]) {
259+
switch (opts->formatName[0]) {
255260

256-
case 'c':
257-
case 'C':
258-
opts->format = archCustom;
259-
break;
261+
case 'c':
262+
case 'C':
263+
opts->format = archCustom;
264+
break;
260265

261-
case 'f':
262-
case 'F':
263-
opts->format = archFiles;
264-
break;
266+
case 'f':
267+
case 'F':
268+
opts->format = archFiles;
269+
break;
265270

266-
case 't':
267-
case 'T':
268-
opts->format = archTar;
269-
break;
271+
case 't':
272+
case 'T':
273+
opts->format = archTar;
274+
break;
270275

271-
default:
272-
fprintf(stderr, "%s: Unknown archive format '%s', please specify 't' or 'c'\n",
273-
progname, opts->formatName);
274-
exit (1);
275-
}
276-
}
276+
default:
277+
fprintf(stderr, "%s: Unknown archive format '%s', please specify 't' or 'c'\n",
278+
progname, opts->formatName);
279+
exit (1);
280+
}
281+
}
277282

278283
AH = OpenArchive(fileSpec, opts->format);
279284

@@ -329,6 +334,8 @@ static void usage(const char *progname)
329334
" -h, --host HOSTNAME server host name\n"
330335
" -i, --index[=NAME] dump indexes or named index\n"
331336
" -l, --list dump summarized TOC for this file\n"
337+
" -L, --use-list=FILENAME use specified table of contents for ordering\n"
338+
" output from this file\n"
332339
" -N, --orig-order dump in original dump order\n"
333340
" -o, --oid-order dump in oid order\n"
334341
" -O, --no-owner do not output reconnect to database to match\n"
@@ -343,8 +350,6 @@ static void usage(const char *progname)
343350
" -t [TABLE], --table[=TABLE] dump for this table only\n"
344351
" -T, --trigger[=NAME] dump triggers or named trigger\n"
345352
" -u, --password use password authentication\n"
346-
" -U, --use-list=FILENAME use specified table of contents for ordering\n"
347-
" output from this file\n"
348353
" -v, --verbose verbose\n"
349354
" -x, --no-acl skip dumping of ACLs (grant/revoke)\n");
350355

@@ -360,6 +365,8 @@ static void usage(const char *progname)
360365
" -h HOSTNAME server host name\n"
361366
" -i NAME dump indexes or named index\n"
362367
" -l dump summarized TOC for this file\n"
368+
" -L FILENAME use specified table of contents for ordering\n"
369+
" output from this file\n"
363370
" -N dump in original dump order\n"
364371
" -o dump in oid order\n"
365372
" -O do not output reconnect to database to match\n"
@@ -374,8 +381,6 @@ static void usage(const char *progname)
374381
" -t NAME dump for this table only\n"
375382
" -T NAME dump triggers or named trigger\n"
376383
" -u use password authentication\n"
377-
" -U FILENAME use specified table of contents for ordering\n"
378-
" output from this file\n"
379384
" -v verbose\n"
380385
" -x skip dumping of ACLs (grant/revoke)\n");
381386
#endif

0 commit comments

Comments
 (0)