]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Add pg_get_role_ddl() function
authorAndrew Dunstan <andrew@dunslane.net>
Thu, 19 Mar 2026 13:52:25 +0000 (09:52 -0400)
committerAndrew Dunstan <andrew@dunslane.net>
Sun, 5 Apr 2026 14:54:54 +0000 (10:54 -0400)
commit76e514ebb4b55f95b844e3e94e61fa64ab16fd0b
treec1ad3ecd165998af5c6ed1c843e3650e17256e54
parent4881981f92024e4db6249bd3dc96a3859638a665
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@gmail.com>
Author: Bryan Green <dbryan.green@gmail.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: Quan Zongliang <quanzongliang@yeah.net>
Reviewed-by: jian he <jian.universality@gmail.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
doc/src/sgml/func/func-info.sgml
src/backend/utils/adt/ddlutils.c
src/include/catalog/pg_proc.dat
src/test/regress/expected/role_ddl.out [new file with mode: 0644]
src/test/regress/parallel_schedule
src/test/regress/sql/role_ddl.sql [new file with mode: 0644]