From 348f856dc57902a8f951a570284918761da1776b Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 15 Apr 2005 16:40:36 +0000 Subject: [PATCH] Revert addition of poorly-thought-out DUMP TIMESTAMP archive entry, which induced bug #1597 in addition to having several other misbehaviors (like labeling the dump with a completion time having nothing to do with reality). Instead just print out the desired strings where RestoreArchive was already emitting the 'PostgreSQL database dump' and 'PostgreSQL database dump complete' strings. --- src/bin/pg_dump/pg_backup_archiver.c | 45 ++++++++++++++++++---------- src/bin/pg_dump/pg_dump.c | 40 ++----------------------- 2 files changed, 32 insertions(+), 53 deletions(-) diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c index 7643fdda44..36852157b4 100644 --- a/src/bin/pg_dump/pg_backup_archiver.c +++ b/src/bin/pg_dump/pg_backup_archiver.c @@ -15,7 +15,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.106 2005/03/18 17:32:55 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.107 2005/04/15 16:40:36 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -73,6 +73,8 @@ static void _die_horribly(ArchiveHandle *AH, const char *modulename, const char static int _canRestoreBlobs(ArchiveHandle *AH); static int _restoringToDB(ArchiveHandle *AH); +static void dumpTimestamp(ArchiveHandle *AH, const char *msg, time_t tim); + /* * Wrapper functions. @@ -129,7 +131,7 @@ void RestoreArchive(Archive *AHX, RestoreOptions *ropt) { ArchiveHandle *AH = (ArchiveHandle *) AHX; - TocEntry *te = AH->toc->next; + TocEntry *te; teReqs reqs; OutputContext sav; bool defnDumped; @@ -210,6 +212,9 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt) ahprintf(AH, "--\n-- PostgreSQL database dump\n--\n\n"); + if (AH->public.verbose) + dumpTimestamp(AH, "Started on", AH->createDate); + /* * Establish important parameter values right away. */ @@ -222,11 +227,10 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt) */ if (ropt->dropSchema) { - te = AH->toc->prev; - AH->currentTE = te; - - while (te != AH->toc) + for (te = AH->toc->prev; te != AH->toc; te = te->prev) { + AH->currentTE = te; + reqs = _tocEntryRequired(te, ropt, false /* needn't drop ACLs */); if (((reqs & REQ_SCHEMA) != 0) && te->dropStmt) { @@ -238,15 +242,13 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt) /* Drop it */ ahprintf(AH, "%s", te->dropStmt); } - te = te->prev; } } /* * Now process each non-ACL TOC entry */ - te = AH->toc->next; - while (te != AH->toc) + for (te = AH->toc->next; te != AH->toc; te = te->next) { AH->currentTE = te; @@ -376,14 +378,12 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt) _printTocEntry(AH, te, ropt, false, false); } } - te = te->next; } /* end loop over TOC entries */ /* * Scan TOC again to output ownership commands and ACLs */ - te = AH->toc->next; - while (te != AH->toc) + for (te = AH->toc->next; te != AH->toc; te = te->next) { AH->currentTE = te; @@ -396,10 +396,11 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt) te->desc, te->tag); _printTocEntry(AH, te, ropt, false, true); } - - te = te->next; } + if (AH->public.verbose) + dumpTimestamp(AH, "Completed on", time(NULL)); + ahprintf(AH, "--\n-- PostgreSQL database dump complete\n--\n\n"); /* @@ -1275,7 +1276,8 @@ warn_or_die_horribly(ArchiveHandle *AH, } if (AH->currentTE != NULL && AH->currentTE != AH->lastErrorTE) { - write_msg(modulename, "Error from TOC entry %d; %u %u %s %s %s\n", AH->currentTE->dumpId, + write_msg(modulename, "Error from TOC entry %d; %u %u %s %s %s\n", + AH->currentTE->dumpId, AH->currentTE->catalogId.tableoid, AH->currentTE->catalogId.oid, AH->currentTE->desc, AH->currentTE->tag, AH->currentTE->owner); } @@ -2766,3 +2768,16 @@ checkSeek(FILE *fp) else return true; } + + +/* + * dumpTimestamp + */ +static void +dumpTimestamp(ArchiveHandle *AH, const char *msg, time_t tim) +{ + char buf[256]; + + if (strftime(buf, 256, "%Y-%m-%d %H:%M:%S %Z", localtime(&tim)) != 0) + ahprintf(AH, "-- %s %s\n\n", msg, buf); +} diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 323c3d9182..9737dd3786 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -12,7 +12,7 @@ * by PostgreSQL * * IDENTIFICATION - * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.406 2005/04/12 04:26:27 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.407 2005/04/15 16:40:36 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -32,7 +32,6 @@ #ifdef HAVE_TERMIOS_H #include #endif -#include #ifndef HAVE_STRDUP #include "strdup.h" @@ -166,7 +165,6 @@ static char *myFormatType(const char *typname, int32 typmod); static const char *fmtQualifiedId(const char *schema, const char *id); static int dumpBlobs(Archive *AH, void *arg); static void dumpDatabase(Archive *AH); -static void dumpTimestamp(Archive *AH, char *msg); static void dumpEncoding(Archive *AH); static const char *getAttrName(int attrnum, TableInfo *tblInfo); static const char *fmtCopyColumnList(const TableInfo *ti); @@ -603,9 +601,6 @@ main(int argc, char **argv) * safe order. */ - if (g_fout->verbose) - dumpTimestamp(g_fout, "Started on"); - /* First the special encoding entry. */ dumpEncoding(g_fout); @@ -621,9 +616,6 @@ main(int argc, char **argv) for (i = 0; i < numObjs; i++) dumpDumpableObject(g_fout, dobjs[i]); - if (g_fout->verbose) - dumpTimestamp(g_fout, "Completed on"); - /* * And finally we can do the actual output. */ @@ -638,6 +630,7 @@ main(int argc, char **argv) ropt->noOwner = outputNoOwner; ropt->disable_triggers = disable_triggers; ropt->use_setsessauth = use_setsessauth; + ropt->dataOnly = dataOnly; if (compressLevel == -1) ropt->compression = 0; @@ -1300,35 +1293,6 @@ dumpDatabase(Archive *AH) } -/* - * dumpTimestamp - */ -static void -dumpTimestamp(Archive *AH, char *msg) -{ - char buf[256]; - time_t now = time(NULL); - - if (strftime(buf, 256, "%Y-%m-%d %H:%M:%S %Z", localtime(&now)) != 0) - { - PQExpBuffer qry = createPQExpBuffer(); - - appendPQExpBuffer(qry, "-- "); - appendPQExpBuffer(qry, msg); - appendPQExpBuffer(qry, " "); - appendPQExpBuffer(qry, buf); - appendPQExpBuffer(qry, "\n"); - - ArchiveEntry(AH, nilCatalogId, createDumpId(), - "DUMP TIMESTAMP", NULL, NULL, "", - false, "DUMP TIMESTAMP", qry->data, "", NULL, - NULL, 0, - NULL, NULL); - destroyPQExpBuffer(qry); - } -} - - /* * dumpEncoding: put the correct encoding into the archive */ -- 2.40.0