@@ -123,6 +123,9 @@ static SimpleOidList tabledata_exclude_oids = {NULL, NULL};
123
123
static SimpleStringList foreign_servers_include_patterns = {NULL, NULL};
124
124
static SimpleOidList foreign_servers_include_oids = {NULL, NULL};
125
125
126
+ static SimpleStringList extension_include_patterns = {NULL, NULL};
127
+ static SimpleOidList extension_include_oids = {NULL, NULL};
128
+
126
129
static const CatalogId nilCatalogId = {0, 0};
127
130
128
131
/* override for standard extra_float_digits setting */
@@ -151,6 +154,10 @@ static void expand_schema_name_patterns(Archive *fout,
151
154
SimpleStringList *patterns,
152
155
SimpleOidList *oids,
153
156
bool strict_names);
157
+ static void expand_extension_name_patterns(Archive *fout,
158
+ SimpleStringList *patterns,
159
+ SimpleOidList *oids,
160
+ bool strict_names);
154
161
static void expand_foreign_server_name_patterns(Archive *fout,
155
162
SimpleStringList *patterns,
156
163
SimpleOidList *oids);
@@ -335,6 +342,7 @@ main(int argc, char **argv)
335
342
{"clean", no_argument, NULL, 'c'},
336
343
{"create", no_argument, NULL, 'C'},
337
344
{"dbname", required_argument, NULL, 'd'},
345
+ {"extension", required_argument, NULL, 'e'},
338
346
{"file", required_argument, NULL, 'f'},
339
347
{"format", required_argument, NULL, 'F'},
340
348
{"host", required_argument, NULL, 'h'},
@@ -426,7 +434,7 @@ main(int argc, char **argv)
426
434
427
435
InitDumpOptions(&dopt);
428
436
429
- while ((c = getopt_long(argc, argv, "abBcCd:E:f:F:h:j:n:N:Op:RsS:t:T:U:vwWxZ:",
437
+ while ((c = getopt_long(argc, argv, "abBcCd:e: E:f:F:h:j:n:N:Op:RsS:t:T:U:vwWxZ:",
430
438
long_options, &optindex)) != -1)
431
439
{
432
440
switch (c)
@@ -455,6 +463,11 @@ main(int argc, char **argv)
455
463
dopt.cparams.dbname = pg_strdup(optarg);
456
464
break;
457
465
466
+ case 'e': /* include extension(s) */
467
+ simple_string_list_append(&extension_include_patterns, optarg);
468
+ dopt.include_everything = false;
469
+ break;
470
+
458
471
case 'E': /* Dump encoding */
459
472
dumpencoding = pg_strdup(optarg);
460
473
break;
@@ -834,6 +847,16 @@ main(int argc, char **argv)
834
847
835
848
/* non-matching exclusion patterns aren't an error */
836
849
850
+ /* Expand extension selection patterns into OID lists */
851
+ if (extension_include_patterns.head != NULL)
852
+ {
853
+ expand_extension_name_patterns(fout, &extension_include_patterns,
854
+ &extension_include_oids,
855
+ strict_names);
856
+ if (extension_include_oids.head == NULL)
857
+ fatal("no matching extensions were found");
858
+ }
859
+
837
860
/*
838
861
* Dumping blobs is the default for dumps where an inclusion switch is not
839
862
* used (an "include everything" dump). -B can be used to exclude blobs
@@ -1025,6 +1048,7 @@ help(const char *progname)
1025
1048
printf(_(" -B, --no-blobs exclude large objects in dump\n"));
1026
1049
printf(_(" -c, --clean clean (drop) database objects before recreating\n"));
1027
1050
printf(_(" -C, --create include commands to create database in dump\n"));
1051
+ printf(_(" -e, --extension=PATTERN dump the specified extension(s) only\n"));
1028
1052
printf(_(" -E, --encoding=ENCODING dump the data in encoding ENCODING\n"));
1029
1053
printf(_(" -n, --schema=PATTERN dump the specified schema(s) only\n"));
1030
1054
printf(_(" -N, --exclude-schema=PATTERN do NOT dump the specified schema(s)\n"));
@@ -1367,6 +1391,53 @@ expand_schema_name_patterns(Archive *fout,
1367
1391
destroyPQExpBuffer(query);
1368
1392
}
1369
1393
1394
+ /*
1395
+ * Find the OIDs of all extensions matching the given list of patterns,
1396
+ * and append them to the given OID list.
1397
+ */
1398
+ static void
1399
+ expand_extension_name_patterns(Archive *fout,
1400
+ SimpleStringList *patterns,
1401
+ SimpleOidList *oids,
1402
+ bool strict_names)
1403
+ {
1404
+ PQExpBuffer query;
1405
+ PGresult *res;
1406
+ SimpleStringListCell *cell;
1407
+ int i;
1408
+
1409
+ if (patterns->head == NULL)
1410
+ return; /* nothing to do */
1411
+
1412
+ query = createPQExpBuffer();
1413
+
1414
+ /*
1415
+ * The loop below runs multiple SELECTs might sometimes result in
1416
+ * duplicate entries in the OID list, but we don't care.
1417
+ */
1418
+ for (cell = patterns->head; cell; cell = cell->next)
1419
+ {
1420
+ appendPQExpBufferStr(query,
1421
+ "SELECT oid FROM pg_catalog.pg_extension e\n");
1422
+ processSQLNamePattern(GetConnection(fout), query, cell->val, false,
1423
+ false, NULL, "e.extname", NULL, NULL);
1424
+
1425
+ res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
1426
+ if (strict_names && PQntuples(res) == 0)
1427
+ fatal("no matching extensions were found for pattern \"%s\"", cell->val);
1428
+
1429
+ for (i = 0; i < PQntuples(res); i++)
1430
+ {
1431
+ simple_oid_list_append(oids, atooid(PQgetvalue(res, i, 0)));
1432
+ }
1433
+
1434
+ PQclear(res);
1435
+ resetPQExpBuffer(query);
1436
+ }
1437
+
1438
+ destroyPQExpBuffer(query);
1439
+ }
1440
+
1370
1441
/*
1371
1442
* Find the OIDs of all foreign servers matching the given list of patterns,
1372
1443
* and append them to the given OID list.
@@ -1793,8 +1864,9 @@ selectDumpableAccessMethod(AccessMethodInfo *method, Archive *fout)
1793
1864
* Built-in extensions should be skipped except for checking ACLs, since we
1794
1865
* assume those will already be installed in the target database. We identify
1795
1866
* such extensions by their having OIDs in the range reserved for initdb.
1796
- * We dump all user-added extensions by default, or none of them if
1797
- * include_everything is false (i.e., a --schema or --table switch was given).
1867
+ * We dump all user-added extensions by default. No extensions are dumped
1868
+ * if include_everything is false (i.e., a --schema or --table switch was
1869
+ * given), except if --extension specifies a list of extensions to dump.
1798
1870
*/
1799
1871
static void
1800
1872
selectDumpableExtension(ExtensionInfo *extinfo, DumpOptions *dopt)
@@ -1807,9 +1879,18 @@ selectDumpableExtension(ExtensionInfo *extinfo, DumpOptions *dopt)
1807
1879
if (extinfo->dobj.catId.oid <= (Oid) g_last_builtin_oid)
1808
1880
extinfo->dobj.dump = extinfo->dobj.dump_contains = DUMP_COMPONENT_ACL;
1809
1881
else
1810
- extinfo->dobj.dump = extinfo->dobj.dump_contains =
1811
- dopt->include_everything ? DUMP_COMPONENT_ALL :
1812
- DUMP_COMPONENT_NONE;
1882
+ {
1883
+ /* check if there is a list of extensions to dump */
1884
+ if (extension_include_oids.head != NULL)
1885
+ extinfo->dobj.dump = extinfo->dobj.dump_contains =
1886
+ simple_oid_list_member(&extension_include_oids,
1887
+ extinfo->dobj.catId.oid) ?
1888
+ DUMP_COMPONENT_ALL : DUMP_COMPONENT_NONE;
1889
+ else
1890
+ extinfo->dobj.dump = extinfo->dobj.dump_contains =
1891
+ dopt->include_everything ?
1892
+ DUMP_COMPONENT_ALL : DUMP_COMPONENT_NONE;
1893
+ }
1813
1894
}
1814
1895
1815
1896
/*
0 commit comments