Re: [PATCH] Add pg_get_database_ddl() function to reconstruct CREATE DATABASE statement

From: Akshay Joshi <akshay(dot)joshi(at)enterprisedb(dot)com>
To: Kirill Reshke <reshkekirill(at)gmail(dot)com>
Cc: Japin Li <japinli(at)hotmail(dot)com>, Rafia Sabih <rafia(dot)pghackers(at)gmail(dot)com>, Álvaro Herrera <alvherre(at)kurilemu(dot)de>, Euler Taveira <euler(at)eulerto(dot)com>, Amul Sul <sulamul(at)gmail(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>, Quan Zongliang <quanzongliang(at)yeah(dot)net>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH] Add pg_get_database_ddl() function to reconstruct CREATE DATABASE statement
Date: 2026-03-10 13:44:20
Message-ID: CANxoLDeP1_mxdEUVwW3o=tjoWwpOVUs0mMh-mdV23hT5FTSqpg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Thanks for the review. I wasn't aware of this change, as I'm still new to
PostgreSQL development.
Attached is the *v14 patch*, now ready for further review.

On Tue, Mar 10, 2026 at 3:46 PM Kirill Reshke <reshkekirill(at)gmail(dot)com>
wrote:

> On Mon, 9 Mar 2026 at 17:08, Akshay Joshi <akshay(dot)joshi(at)enterprisedb(dot)com>
> wrote:
> >
> > I have resolved the review comments. Removed the hardcoded 'utf-8'
> encoding, the logic now retrieves the encoding dynamically. This ensures
> accuracy because the default encoding for CREATE DATABASE is derived from
> the template database (template1) rather than being a static value.
> >
> > Attached is the v13 patch, now ready for further review.
> >
> > On Fri, Mar 6, 2026 at 8:13 PM Japin Li <japinli(at)hotmail(dot)com> wrote:
> >>
> >>
> >> Hi, Akshay
> >>
> >> On Fri, 06 Mar 2026 at 17:21, Akshay Joshi <
> akshay(dot)joshi(at)enterprisedb(dot)com> wrote:
> >> > I have updated the documentation.
> >> > Attached is the v12 patch, now ready for further review.
> >> >
> >>
> >> Thanks for updating the patch.
> >>
> >> I might not have expressed myself clearly in my last email — apologies.
> >> Here's a diff that should make it clearer.
> >>
> >> diff --git a/src/backend/utils/adt/ruleutils.c
> b/src/backend/utils/adt/ruleutils.c
> >> index bbf82c1d6c0..1ed56ee71ab 100644
> >> --- a/src/backend/utils/adt/ruleutils.c
> >> +++ b/src/backend/utils/adt/ruleutils.c
> >> @@ -13859,7 +13859,6 @@ parse_ddl_options(FunctionCallInfo fcinfo, int
> variadic_start)
> >> bool *nulls;
> >> Oid *types;
> >> int nargs;
> >> - bool found = false;
> >>
> >> /* Extract variadic arguments */
> >> nargs = extract_variadic_args(fcinfo, variadic_start, true,
> >> @@ -13887,8 +13886,7 @@ parse_ddl_options(FunctionCallInfo fcinfo, int
> variadic_start)
> >> {
> >> char *name;
> >> bool bval;
> >> -
> >> - found = false;
> >> + bool found = false;
> >>
> >> /* Key must not be null */
> >> if (nulls[i])
> >> @@ -13925,8 +13923,8 @@ parse_ddl_options(FunctionCallInfo fcinfo, int
> variadic_start)
> >> if (!parse_bool(valstr, &bval))
> >> ereport(ERROR,
> >>
> (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
> >> - errmsg("argument %d:
> invalid value \"%s\" for key \"%s\"",
> >> - i + 2,
> valstr, name),
> >> + errmsg("value for
> option \"%s\" at position %d has invalid value \"%s\"",
> >> + name, i
> + 2, valstr),
> >> errhint("Valid values
> are: true, false, yes, no, 1, 0, on, off.")));
> >> pfree(valstr);
> >> }
> >> @@ -13934,8 +13932,8 @@ parse_ddl_options(FunctionCallInfo fcinfo, int
> variadic_start)
> >> {
> >> ereport(ERROR,
> >>
> (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
> >> - errmsg("argument %d: value for
> key \"%s\" must be boolean or text type",
> >> - i + 2, name)));
> >> + errmsg("value for option
> \"%s\" at position %d has type %s, expected type boolean or text",
> >> + name, i + 2,
> format_type_be(types[i + 1]))));
> >> }
> >>
> >> /*
> >> @@ -13983,7 +13981,7 @@ parse_ddl_options(FunctionCallInfo fcinfo, int
> variadic_start)
> >> /*
> >> * pg_get_database_ddl
> >> *
> >> - * Generate a CREATE DATABASE statement for the specified database
> name or oid.
> >> + * Generate a CREATE DATABASE statement for the specified database oid.
> >> *
> >> * db_oid - OID of the database for which to generate the DDL.
> >> * options - Variadic name/value pairs to modify the output.
> >>
> >> --
> >> Regards,
> >> Japin Li
> >> ChengDu WenWu Information Technology Co., Ltd.
>
>
> Hi!
> I noticed this in v13: DDLOptionDef is missing from typedefs.list.
> This results in pgident to incorrectly format sources.
>
>
>
> --
> Best regards,
> Kirill Reshke
>
>
>

Attachment Content-Type Size
v14-0001-Add-pg_get_database_ddl-function-to-reconstruct-ddl.patch application/octet-stream 34.7 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Fujii Masao 2026-03-10 13:57:18 Re: brin: Remove duplicate initialization in initialize_brin_buildstate()
Previous Message Madyshev Egor 2026-03-10 13:41:22 RE: Idea to enhance pgbench by more modes to generate data (multi-TXNs, UNNEST, COPY BINARY)