pgsql: Add pg_get_database_ddl() function

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Add pg_get_database_ddl() function
Date: 2026-04-05 15:02:21
Message-ID: E1w9OzU-0035rB-1P@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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(dot)joshi(at)enterprisedb(dot)com>
Co-authored-by: Andrew Dunstan <andrew(at)dunslane(dot)net>
Co-authored-by: Euler Taveira <euler(at)eulerto(dot)com>
Reviewed-by: Japin Li <japinli(at)hotmail(dot)com>
Reviewed-by: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Reviewed-by: Álvaro Herrera <alvherre(at)kurilemu(dot)de>
Reviewed-by: Quan Zongliang <quanzongliang(at)yeah(dot)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

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/a4f774cf1c7e5c6cf2f3393f611e1df16cdb5a5a

Modified Files
--------------
doc/src/sgml/func/func-info.sgml | 23 ++
src/backend/utils/adt/ddlutils.c | 330 +++++++++++++++++++++++++++++
src/include/catalog/pg_proc.dat | 8 +
src/test/regress/expected/database_ddl.out | 88 ++++++++
src/test/regress/parallel_schedule | 2 +-
src/test/regress/sql/database_ddl.sql | 66 ++++++
6 files changed, 516 insertions(+), 1 deletion(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Heikki Linnakangas 2026-04-05 18:11:33 pgsql: Check that the tranche name is unique in RequestNamedLWLockTranc
Previous Message Álvaro Herrera 2026-04-05 11:34:38 pgsql: Allow index_create to suppress index_build progress reporting