MCPcopy Create free account
hub / github.com/apache/cloudberry / dumpExtension

Function dumpExtension

src/bin/pg_dump/pg_dump.c:11640–11762  ·  view source on GitHub ↗

* dumpExtension * writes out to fout the queries to recreate an extension */

Source from the content-addressed store, hash-verified

11638 * writes out to fout the queries to recreate an extension
11639 */
11640static void
11641dumpExtension(Archive *fout, const ExtensionInfo *extinfo)
11642{
11643 DumpOptions *dopt = fout->dopt;
11644 PQExpBuffer q;
11645 PQExpBuffer delq;
11646 char *qextname;
11647
11648 /* Skip if not to be dumped */
11649 if (!extinfo->dobj.dump || dopt->dataOnly)
11650 return;
11651
11652 q = createPQExpBuffer();
11653 delq = createPQExpBuffer();
11654
11655 qextname = pg_strdup(fmtId(extinfo->dobj.name));
11656
11657 appendPQExpBuffer(delq, "DROP EXTENSION %s;\n", qextname);
11658
11659 if (!dopt->binary_upgrade)
11660 {
11661 /*
11662 * In a regular dump, we simply create the extension, intentionally
11663 * not specifying a version, so that the destination installation's
11664 * default version is used.
11665 *
11666 * Use of IF NOT EXISTS here is unlike our behavior for other object
11667 * types; but there are various scenarios in which it's convenient to
11668 * manually create the desired extension before restoring, so we
11669 * prefer to allow it to exist already.
11670 */
11671 appendPQExpBuffer(q, "CREATE EXTENSION IF NOT EXISTS %s WITH SCHEMA %s;\n",
11672 qextname, fmtId(extinfo->namespace));
11673 }
11674 else
11675 {
11676 /*
11677 * In binary-upgrade mode, it's critical to reproduce the state of the
11678 * database exactly, so our procedure is to create an empty extension,
11679 * restore all the contained objects normally, and add them to the
11680 * extension one by one. This function performs just the first of
11681 * those steps. binary_upgrade_extension_member() takes care of
11682 * adding member objects as they're created.
11683 */
11684 int i;
11685 int n;
11686
11687 appendPQExpBufferStr(q, "-- For binary upgrade, create an empty extension and insert objects into it\n");
11688
11689 /*
11690 * We unconditionally create the extension, so we must drop it if it
11691 * exists. This could happen if the user deleted 'plpgsql' and then
11692 * readded it, causing its oid to be greater than g_last_builtin_oid.
11693 */
11694 appendPQExpBuffer(q, "DROP EXTENSION IF EXISTS %s;\n", qextname);
11695
11696 appendPQExpBufferStr(q,
11697 "SELECT pg_catalog.binary_upgrade_create_empty_extension(");

Callers 1

dumpDumpableObjectFunction · 0.85

Calls 11

createPQExpBufferFunction · 0.85
pg_strdupFunction · 0.85
fmtIdFunction · 0.85
appendPQExpBufferFunction · 0.85
appendPQExpBufferStrFunction · 0.85
findObjectByDumpIdFunction · 0.85
appendPQExpBufferCharFunction · 0.85
ArchiveEntryFunction · 0.85
dumpCommentFunction · 0.85
dumpSecLabelFunction · 0.85
destroyPQExpBufferFunction · 0.85

Tested by

no test coverage detected