Re: [PATCH] Add pg_get_role_ddl() functions for role recreation

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Mario González Troncoso <gonzalemario(at)gmail(dot)com>
Cc: Japin Li <japinli(at)hotmail(dot)com>, li carol <carol(dot)li2025(at)outlook(dot)com>, Bryan Green <dbryan(dot)green(at)gmail(dot)com>, Quan Zongliang <quanzongliang(at)yeah(dot)net>, "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [PATCH] Add pg_get_role_ddl() functions for role recreation
Date: 2026-01-16 14:24:34
Message-ID: CACJufxEY_2usz5iOixwyk2CmCUNf-Q=PoCT-xFH3x_D7Hn+=jQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Jan 8, 2026 at 8:20 PM Mario González Troncoso
<gonzalemario(at)gmail(dot)com> wrote:
>
> Cool. I rebased this morning and it passed just fine.
>

hi.

+ /*
+ * We don't support generating DDL for system roles. The primary reason
+ * for this is that users shouldn't be recreating them.
+ */
+ if (strncmp(rolname, "pg_", 3) == 0)
+ ereport(ERROR,
+ (errcode(ERRCODE_RESERVED_NAME),
+ errmsg("role name \"%s\" is reserved", rolname),
+ errdetail("Role names starting with \"pg_\" are reserved for system
roles.")));

There is a specific function for it, IsReservedName,
we should use it instead of strncmp, i think.

+ /*
+ * We intentionally omit PASSWORD. There's no way to retrieve the
+ * original password text from the stored hash, and even if we could,
+ * exposing passwords through a SQL function would be a security issue.
+ * Users must set passwords separately after recreating roles.
+ */
+
+ appendStringInfoChar(&buf, ';');

What about the PASSWORD NULL scarenio?

per Synopsis:
CREATE ROLE name [ [ WITH ] option [ ... ] ]

Do we need to include the optional keyword, WITH?

--
jian
https://www.enterprisedb.com/

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message zengman 2026-01-16 14:24:56 [PATCH] Remove redundant Assert() calls in report_namespace_conflict()
Previous Message Anders Åstrand 2026-01-16 14:22:11 [patch] Add support for connection strings to createuser and dropuser