diff --git a/doc/src/sgml/ref/pg_dump.sgml b/doc/src/sgml/ref/pg_dump.sgml
index 989b8e2381..719dfed951 100644
--- a/doc/src/sgml/ref/pg_dump.sgml
+++ b/doc/src/sgml/ref/pg_dump.sgml
@@ -123,6 +123,11 @@ PostgreSQL documentation
Table data, large objects, and sequence values are dumped.
+
+ This option cannot be used together with the ,
+ or option.
+
+
This option is similar to, but for historical reasons not identical
to, specifying .
@@ -136,13 +141,14 @@ PostgreSQL documentation
Include large objects in the dump. This is the default behavior
- except when , , or
- is specified. The
+ except when , ,
+ , or
+ is specified. The
switch is therefore only useful to add large objects to dumps
where a specific schema or table has been requested. Note that
blobs are considered data and therefore will be included when
is used, but not
- when is.
+ when or are.
@@ -544,6 +550,11 @@ PostgreSQL documentation
be dumped.
+
+ This option cannot be used together with the
+ option.
+
+
When is specified, pg_dump
@@ -752,7 +763,22 @@ PostgreSQL documentation
-
+
+
+
+ Dmup only the stored functions and stored procedure definitions, not data, not
+ other objects definition.
+
+
+
+ This option is the same than but restricted
+ to stored functions and stored procedures.
+
+
+
+
+
+
Use conditional commands (i.e., add an IF EXISTS
@@ -781,6 +807,11 @@ PostgreSQL documentation
The only exception is that an empty pattern is disallowed.
+
+ This option cannot be used together with the ,
+ or option.
+
+
When is specified,
diff --git a/src/bin/pg_dump/pg_backup.h b/src/bin/pg_dump/pg_backup.h
index 3bc86635f7..a9eea710ff 100644
--- a/src/bin/pg_dump/pg_backup.h
+++ b/src/bin/pg_dump/pg_backup.h
@@ -153,6 +153,7 @@ typedef struct _dumpOptions
/* flags for various command-line long options */
int disable_dollar_quoting;
int column_inserts;
+ int functions_only;
int if_exists;
int no_comments;
int no_security_labels;
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index da6cc054b0..0c2ba1d100 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -370,6 +370,7 @@ main(int argc, char **argv)
{"enable-row-security", no_argument, &dopt.enable_row_security, 1},
{"exclude-table-data", required_argument, NULL, 4},
{"extra-float-digits", required_argument, NULL, 8},
+ {"functions-only", no_argument, &dopt.functions_only, 1},
{"if-exists", no_argument, &dopt.if_exists, 1},
{"inserts", no_argument, NULL, 9},
{"lock-wait-timeout", required_argument, NULL, 2},
@@ -652,9 +653,24 @@ main(int argc, char **argv)
exit_nicely(1);
}
+ if (dopt.dataOnly && dopt.functions_only)
+ {
+ pg_log_error("options --functions-only and -a/--data-only cannot be used together");
+ exit_nicely(1);
+ }
+
+ if (table_include_patterns.head != NULL && dopt.functions_only)
+ {
+ pg_log_error("options --functions-only and -t/--table cannot be used together");
+ exit_nicely(1);
+ }
+
if (dopt.schemaOnly && foreign_servers_include_patterns.head != NULL)
fatal("options -s/--schema-only and --include-foreign-data cannot be used together");
+ if (dopt.functions_only && foreign_servers_include_patterns.head != NULL)
+ fatal("options --functions-only and --include-foreign-data cannot be used together");
+
if (numWorkers > 1 && foreign_servers_include_patterns.head != NULL)
fatal("option --include-foreign-data is not supported with parallel backup");
@@ -842,8 +858,12 @@ main(int argc, char **argv)
*
* -s means "schema only" and blobs are data, not schema, so we never
* include blobs when -s is used.
+ *
+ * --functions-only means no data and blobs are data, so we never include
+ * blobs when --functions-only is used.
+ *
*/
- if (dopt.include_everything && !dopt.schemaOnly && !dopt.dontOutputBlobs)
+ if (dopt.include_everything && !dopt.schemaOnly && !dopt.functions_only && !dopt.dontOutputBlobs)
dopt.outputBlobs = true;
/*
@@ -923,9 +943,26 @@ main(int argc, char **argv)
if (dopt.outputCreateDB)
dumpDatabase(fout);
- /* Now the rearrangeable objects. */
- for (i = 0; i < numObjs; i++)
- dumpDumpableObject(fout, dobjs[i]);
+ /* If we have to export only the functions, we won't need to export
+ * everything
+ */
+ if (!dopt.functions_only)
+ {
+ /* Now the rearrangeable objects. */
+ for (i = 0; i < numObjs; i++)
+ dumpDumpableObject(fout, dobjs[i]);
+ }
+ else
+ {
+ /* We'd like to dump functions only, in that case */
+ for (i = 0; i < numObjs; i++)
+ {
+ if (dobjs[i]->objType == DO_FUNC)
+ {
+ dumpFunc(fout, (const FuncInfo *) dobjs[i]);
+ }
+ }
+ }
/*
* Set up options info to ensure we dump what we want.
diff --git a/src/test/modules/test_pg_dump/t/001_base.pl b/src/test/modules/test_pg_dump/t/001_base.pl
index 501aff0920..e7cdf28002 100644
--- a/src/test/modules/test_pg_dump/t/001_base.pl
+++ b/src/test/modules/test_pg_dump/t/001_base.pl
@@ -149,6 +149,12 @@ my %pgdump_runs = (
"--file=$tempdir/extension_schema.sql", 'postgres',
],
},
+ functions_only => {
+ dump_cmd => [
+ 'pg_dump', '--no-sync', "--file=$tempdir/functions_only.sql",
+ '--functions-only', 'postgres',
+ ],
+ },
pg_dumpall_globals => {
dump_cmd => [
'pg_dumpall', '--no-sync',
@@ -364,6 +370,7 @@ my %tests = (
/xm,
like => {
%full_runs,
+ functions_only => 1,
schema_only => 1,
section_pre_data => 1,
},
@@ -613,6 +620,7 @@ my %tests = (
pg_dumpall_globals => 1,
section_data => 1,
section_pre_data => 1,
+ functions_only => 1,
},
},
@@ -627,6 +635,7 @@ my %tests = (
pg_dumpall_globals => 1,
section_data => 1,
section_pre_data => 1,
+ functions_only => 1,
},
},