Skip to content

Commit 2b1263f

Browse files
Yashneet Vinayakthephantomthief
authored andcommitted
unrestrict psql meta-commands for using backslash command for pg_dump and pg_dumpall in Babelfish
1 parent b8d5726 commit 2b1263f

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

src/bin/pg_dump/dump_babel_utils.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,11 @@ dumpBabelRestoreChecks(Archive *fout)
258258
* Note that it can only be used in plain text dump (archNull).
259259
*/
260260
if (format == archNull)
261+
{
262+
appendPQExpBuffer(qry, "\\unrestrict %s\n", fout->dopt->restrict_key);
261263
appendPQExpBufferStr(qry, "\\set ON_ERROR_STOP on\n\n");
264+
appendPQExpBuffer(qry, "\\restrict %s\n", fout->dopt->restrict_key);
265+
}
262266
appendPQExpBuffer(qry,
263267
"DO $$"
264268
"\nDECLARE"
@@ -295,7 +299,11 @@ dumpBabelRestoreChecks(Archive *fout)
295299
"\nEND$$;\n\n"
296300
, source_migration_mode);
297301
if (format == archNull)
302+
{
303+
appendPQExpBuffer(qry, "\\unrestrict %s\n", fout->dopt->restrict_key);
298304
appendPQExpBufferStr(qry, "\\set ON_ERROR_STOP off\n");
305+
appendPQExpBuffer(qry, "\\restrict %s\n", fout->dopt->restrict_key);
306+
}
299307
PQclear(res);
300308

301309
ArchiveEntry(fout, nilCatalogId, createDumpId(),

src/bin/pg_dump/dumpall_babel_utils.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ isBabelfishDatabase(PGconn *conn)
112112
* or not.
113113
*/
114114
void
115-
dumpBabelRestoreChecks(FILE *OPF, PGconn *conn, int binary_upgrade)
115+
dumpBabelRestoreChecks(FILE *OPF, PGconn *conn, int binary_upgrade, char *restrict_key)
116116
{
117117
PGresult *res;
118118
int source_server_version_num;
@@ -137,7 +137,9 @@ dumpBabelRestoreChecks(FILE *OPF, PGconn *conn, int binary_upgrade)
137137
* Temporarily enable ON_ERROR_STOP so that whole restore script
138138
* execution fails if the following do block raises an error.
139139
*/
140+
appendPQExpBuffer(qry, "\\unrestrict %s\n", restrict_key);
140141
appendPQExpBufferStr(qry, "\\set ON_ERROR_STOP on\n\n");
142+
appendPQExpBuffer(qry, "\\restrict %s\n", restrict_key);
141143
appendPQExpBuffer(qry,
142144
"DO $$"
143145
"\nDECLARE"
@@ -173,7 +175,10 @@ dumpBabelRestoreChecks(FILE *OPF, PGconn *conn, int binary_upgrade)
173175
"\n END IF;"
174176
"\nEND$$;\n\n"
175177
, source_migration_mode);
178+
179+
appendPQExpBuffer(qry, "\\unrestrict %s\n", restrict_key);
176180
appendPQExpBufferStr(qry, "\\set ON_ERROR_STOP off\n");
181+
appendPQExpBuffer(qry, "\\restrict %s\n", restrict_key);
177182
PQclear(res);
178183

179184
fprintf(OPF, "%s", qry->data);

src/bin/pg_dump/dumpall_babel_utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ extern void getBabelfishRolesQuery(PGconn *conn, PQExpBuffer buf,
2222
extern void getBabelfishRoleMembershipQuery(PGconn *conn, PQExpBuffer buf,
2323
char *role_catalog, int binary_upgrade);
2424
extern bool isBabelfishDatabase(PGconn *conn);
25-
extern void dumpBabelRestoreChecks(FILE *OPF, PGconn *conn, int binary_upgrade);
25+
extern void dumpBabelRestoreChecks(FILE *OPF, PGconn *conn, int binary_upgrade, char *restrict_key);
2626

2727
#endif

src/bin/pg_dump/pg_dumpall.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ main(int argc, char *argv[])
570570
fprintf(OPF, "SET escape_string_warning = off;\n");
571571
fprintf(OPF, "\n");
572572

573-
dumpBabelRestoreChecks(OPF, conn, binary_upgrade);
573+
dumpBabelRestoreChecks(OPF, conn, binary_upgrade, restrict_key);
574574

575575
if (!data_only)
576576
{

0 commit comments

Comments
 (0)