Skip to content

Commit a4fdcce

Browse files
committed
Ensure schema qualification in pg_restore DISABLE/ENABLE TRIGGER commands.
Previously, this code blindly followed the common coding pattern of passing PQserverVersion(AH->connection) as the server-version parameter of fmtQualifiedId. That works as long as we have a connection; but in pg_restore with text output, we don't. Instead we got a zero from PQserverVersion, which fmtQualifiedId interpreted as "server is too old to have schemas", and so the name went unqualified. That still accidentally managed to work in many cases, which is probably why this ancient bug went undetected for so long. It only became obvious in the wake of the changes to force dump/restore to execute with restricted search_path. In HEAD/v11, let's deal with this by ripping out fmtQualifiedId's server- version behavioral dependency, and just making it schema-qualify all the time. We no longer support pg_dump from servers old enough to need the ability to omit schema name, let alone restoring to them. (Also, the few callers outside pg_dump already didn't work with pre-schema servers.) In older branches, that's not an acceptable solution, so instead just tweak the DISABLE/ENABLE TRIGGER logic to ensure it will schema-qualify its output regardless of server version. Per bug #15338 from Oleg somebody. Back-patch to all supported branches. Discussion: https://postgr.es/m/153452458706.1316.5328079417086507743@wrigleys.postgresql.org
1 parent 3cf3a65 commit a4fdcce

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -892,10 +892,12 @@ _disableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *rop
892892
_becomeUser(AH, ropt->superuser);
893893

894894
/*
895-
* Disable them.
895+
* Disable them. Assume that the table name should be schema-qualified
896+
* (we can't look at PQserverVersion, since we might not have any
897+
* connection; and anyway we don't promise our output will load pre-7.3).
896898
*/
897899
ahprintf(AH, "ALTER TABLE %s DISABLE TRIGGER ALL;\n\n",
898-
fmtQualifiedId(PQserverVersion(AH->connection),
900+
fmtQualifiedId(70300,
899901
te->namespace,
900902
te->tag));
901903
}
@@ -918,10 +920,10 @@ _enableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt
918920
_becomeUser(AH, ropt->superuser);
919921

920922
/*
921-
* Enable them.
923+
* Enable them. As above, force schema qualification.
922924
*/
923925
ahprintf(AH, "ALTER TABLE %s ENABLE TRIGGER ALL;\n\n",
924-
fmtQualifiedId(PQserverVersion(AH->connection),
926+
fmtQualifiedId(70300,
925927
te->namespace,
926928
te->tag));
927929
}

0 commit comments

Comments
 (0)