Skip to content

Commit 5c60cc8

Browse files
Yashneet Vinayakthephantomthief
authored andcommitted
unrestrict psql meta-commands for using backslash command for pg_dump and pg_dumpall in Babelfish
1 parent e2f4557 commit 5c60cc8

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
@@ -270,7 +270,11 @@ dumpBabelRestoreChecks(Archive *fout)
270270
* Note that it can only be used in plain text dump (archNull).
271271
*/
272272
if (format == archNull)
273+
{
274+
appendPQExpBuffer(qry, "\\unrestrict %s\n", fout->dopt->restrict_key);
273275
appendPQExpBufferStr(qry, "\\set ON_ERROR_STOP on\n\n");
276+
appendPQExpBuffer(qry, "\\restrict %s\n", fout->dopt->restrict_key);
277+
}
274278
appendPQExpBuffer(qry,
275279
"DO $$"
276280
"\nDECLARE"
@@ -307,7 +311,11 @@ dumpBabelRestoreChecks(Archive *fout)
307311
"\nEND$$;\n\n"
308312
, source_migration_mode);
309313
if (format == archNull)
314+
{
315+
appendPQExpBuffer(qry, "\\unrestrict %s\n", fout->dopt->restrict_key);
310316
appendPQExpBufferStr(qry, "\\set ON_ERROR_STOP off\n");
317+
appendPQExpBuffer(qry, "\\restrict %s\n", fout->dopt->restrict_key);
318+
}
311319
PQclear(res);
312320

313321
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
@@ -123,7 +123,7 @@ isBabelfishDatabase(PGconn *conn)
123123
* or not.
124124
*/
125125
void
126-
dumpBabelRestoreChecks(FILE *OPF, PGconn *conn, int binary_upgrade)
126+
dumpBabelRestoreChecks(FILE *OPF, PGconn *conn, int binary_upgrade, char *restrict_key)
127127
{
128128
PGresult *res;
129129
int source_server_version_num;
@@ -151,7 +151,9 @@ dumpBabelRestoreChecks(FILE *OPF, PGconn *conn, int binary_upgrade)
151151
* Temporarily enable ON_ERROR_STOP so that whole restore script
152152
* execution fails if the following do block raises an error.
153153
*/
154+
appendPQExpBuffer(qry, "\\unrestrict %s\n", restrict_key);
154155
appendPQExpBufferStr(qry, "\\set ON_ERROR_STOP on\n\n");
156+
appendPQExpBuffer(qry, "\\restrict %s\n", restrict_key);
155157
appendPQExpBuffer(qry,
156158
"DO $$"
157159
"\nDECLARE"
@@ -187,7 +189,10 @@ dumpBabelRestoreChecks(FILE *OPF, PGconn *conn, int binary_upgrade)
187189
"\n END IF;"
188190
"\nEND$$;\n\n"
189191
, source_migration_mode);
192+
193+
appendPQExpBuffer(qry, "\\unrestrict %s\n", restrict_key);
190194
appendPQExpBufferStr(qry, "\\set ON_ERROR_STOP off\n");
195+
appendPQExpBuffer(qry, "\\restrict %s\n", restrict_key);
191196
PQclear(res);
192197

193198
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
@@ -595,7 +595,7 @@ main(int argc, char *argv[])
595595
fprintf(OPF, "SET escape_string_warning = off;\n");
596596
fprintf(OPF, "\n");
597597

598-
dumpBabelRestoreChecks(OPF, conn, binary_upgrade);
598+
dumpBabelRestoreChecks(OPF, conn, binary_upgrade, restrict_key);
599599

600600
if (!data_only)
601601
{

0 commit comments

Comments
 (0)