Skip to content

Commit 297b2c1

Browse files
committed
Fix placement of "SET row_security" command issuance in pg_dump.
Somebody apparently threw darts at the code to decide where to insert these. They certainly didn't proceed by adding them where other similar SETs were handled. This at least broke pg_restore, and perhaps other use-cases too.
1 parent 0e7e355 commit 297b2c1

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -434,17 +434,6 @@ RestoreArchive(Archive *AHX)
434434
ahprintf(AH, "BEGIN;\n\n");
435435
}
436436

437-
/*
438-
* Enable row-security if necessary.
439-
*/
440-
if (PQserverVersion(AH->connection) >= 90500)
441-
{
442-
if (!ropt->enable_row_security)
443-
ahprintf(AH, "SET row_security = off;\n");
444-
else
445-
ahprintf(AH, "SET row_security = on;\n");
446-
}
447-
448437
/*
449438
* Establish important parameter values right away.
450439
*/
@@ -2804,6 +2793,12 @@ _doSetFixedOutputState(ArchiveHandle *AH)
28042793
if (!AH->public.std_strings)
28052794
ahprintf(AH, "SET escape_string_warning = off;\n");
28062795

2796+
/* Adjust row-security state */
2797+
if (AH->ropt && AH->ropt->enable_row_security)
2798+
ahprintf(AH, "SET row_security = on;\n");
2799+
else
2800+
ahprintf(AH, "SET row_security = off;\n");
2801+
28072802
ahprintf(AH, "\n");
28082803
}
28092804

src/bin/pg_dump/pg_dump.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,17 @@ setup_connection(Archive *AH, DumpOptions *dopt, const char *dumpencoding,
10051005
if (quote_all_identifiers && AH->remoteVersion >= 90100)
10061006
ExecuteSqlStatement(AH, "SET quote_all_identifiers = true");
10071007

1008+
/*
1009+
* Adjust row-security mode, if supported.
1010+
*/
1011+
if (AH->remoteVersion >= 90500)
1012+
{
1013+
if (dopt->enable_row_security)
1014+
ExecuteSqlStatement(AH, "SET row_security = on");
1015+
else
1016+
ExecuteSqlStatement(AH, "SET row_security = off");
1017+
}
1018+
10081019
/*
10091020
* Start transaction-snapshot mode transaction to dump consistent data.
10101021
*/
@@ -1058,14 +1069,6 @@ setup_connection(Archive *AH, DumpOptions *dopt, const char *dumpencoding,
10581069
AH->remoteVersion >= 90200 &&
10591070
!dopt->no_synchronized_snapshots)
10601071
AH->sync_snapshot_id = get_synchronized_snapshot(AH);
1061-
1062-
if (AH->remoteVersion >= 90500)
1063-
{
1064-
if (dopt->enable_row_security)
1065-
ExecuteSqlStatement(AH, "SET row_security TO ON");
1066-
else
1067-
ExecuteSqlStatement(AH, "SET row_security TO OFF");
1068-
}
10691072
}
10701073

10711074
static void

0 commit comments

Comments
 (0)