pgsql: Add pg_get_role_ddl() function

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

Add pg_get_role_ddl() function

Add a new SQL-callable function that returns the DDL statements needed
to recreate a role. It takes a regrole 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 and memberships (boolean) to include GRANT statements
for role memberships and membership options. The return is one or
multiple rows where the first row is a CREATE ROLE statement and
subsequent rows are ALTER ROLE statements to set some role properties.
Password information is never included in the output.

The caller must have SELECT privilege on pg_authid.

Author: Mario Gonzalez <gonzalemario(at)gmail(dot)com>
Author: Bryan Green <dbryan(dot)green(at)gmail(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: Quan Zongliang <quanzongliang(at)yeah(dot)net>
Reviewed-by: jian he <jian(dot)universality(at)gmail(dot)com>
Discussion: https://postgr.es/m/4c5f895e-3281-48f8-b943-9228b7da6471@gmail.com
Discussion: https://postgr.es/m/e247c261-e3fb-4810-81e0-a65893170e94@dunslane.net

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/76e514ebb4b55f95b844e3e94e61fa64ab16fd0b

Modified Files
--------------
doc/src/sgml/func/func-info.sgml | 56 +++++
src/backend/utils/adt/ddlutils.c | 361 +++++++++++++++++++++++++++++++++
src/include/catalog/pg_proc.dat | 8 +
src/test/regress/expected/role_ddl.out | 143 +++++++++++++
src/test/regress/parallel_schedule | 2 +
src/test/regress/sql/role_ddl.sql | 96 +++++++++
6 files changed, 666 insertions(+)

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