]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Add pg_get_database_ddl() function
authorAndrew Dunstan <andrew@dunslane.net>
Thu, 19 Mar 2026 13:57:35 +0000 (09:57 -0400)
committerAndrew Dunstan <andrew@dunslane.net>
Sun, 5 Apr 2026 14:54:54 +0000 (10:54 -0400)
commita4f774cf1c7e5c6cf2f3393f611e1df16cdb5a5a
treefc2d012a9646d10f2e2b04cda7b35550da620a62
parentb99fd9fd7f363c6363f4c8a95c699b9134b0357f
Add pg_get_database_ddl() function

Add a new SQL-callable function that returns the DDL statements needed
to recreate a database. It takes a regdatabase argument and an optional
VARIADIC text argument for options that are specified as alternating
name/value pairs. The following options are supported: pretty (boolean)
for formatted output, owner (boolean) to include OWNER and tablespace
(boolean) to include TABLESPACE. The return is one or multiple rows
where the first row is a CREATE DATABASE statement and subsequent rows are
ALTER DATABASE statements to set some database properties.

The caller must have CONNECT privilege on the target database.

Author: Akshay Joshi <akshay.joshi@enterprisedb.com>
Co-authored-by: Andrew Dunstan <andrew@dunslane.net>
Co-authored-by: Euler Taveira <euler@eulerto.com>
Reviewed-by: Japin Li <japinli@hotmail.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Álvaro Herrera <alvherre@kurilemu.de>
Reviewed-by: Quan Zongliang <quanzongliang@yeah.net>
Discussion: https://postgr.es/m/CANxoLDc6FHBYJvcgOnZyS+jF0NUo3Lq_83-rttBuJgs9id_UDg@mail.gmail.com
Discussion: https://postgr.es/m/e247c261-e3fb-4810-81e0-a65893170e94@dunslane.net
doc/src/sgml/func/func-info.sgml
src/backend/utils/adt/ddlutils.c
src/include/catalog/pg_proc.dat
src/test/regress/expected/database_ddl.out [new file with mode: 0644]
src/test/regress/parallel_schedule
src/test/regress/sql/database_ddl.sql [new file with mode: 0644]