Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vxhlJ-00H3Rz-0G for pgsql-hackers@arkaria.postgresql.org; Wed, 04 Mar 2026 08:39:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vxhlH-00Bf2f-0e for pgsql-hackers@arkaria.postgresql.org; Wed, 04 Mar 2026 08:39:19 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vxhlG-00Bf2W-2B for pgsql-hackers@lists.postgresql.org; Wed, 04 Mar 2026 08:39:19 +0000 Received: from mail-australiaeastazolkn190100000.outbound.protection.outlook.com ([2a01:111:f403:d40d::] helo=SY8PR01CU002.outbound.protection.outlook.com) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vxhlE-00000000LK5-4AVZ for pgsql-hackers@postgresql.org; Wed, 04 Mar 2026 08:39:18 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=KJe8pT3DWjiJbTO1upbFbS4Wu8MkLotaaaD6ormSaOjUC+8FpmbV1qq+1GOBMuUx9jqH9PRWS6T5TQ/E4+8v1mMnnrKESMvvULq8Iepdl8KwP+9upFjo7sl4fcOwUJcc6KvUA1ZMaR5x+Cag2pbaHUA3qVP7P8zJmKaEoLBZu8PaQ7Y7GlWfaYa9fzToCaTZBBqzgpitntIbLXX59LHrihzuTNndmZKdgXRwZIA3PxByT+bSi2lBoiIvA4HOBl8SBgYw4YMCC7pwQyknd0m2PrqXWja9Mo4MdxRdP4NuZYyPl7VoHFyYZ98ZoCvMJc3nxtRLOpuOPNGIgpik9e7zJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=kPS/5oCHqB3y4HzsoGOQYZaYsOw0nAAWSbIVfq+Bamo=; b=vj32C9GsSKTjHcOJQBBvC3yC4JTjuR0z9uHkDWNtW3chtdoW9hrhMzHgZheXMhEzerZL/85oKbwcfEYmiR063/DmT+eUaD9Iz5LR7v+s/ogl0axEYRhZY1/BGTplfbe/60Zs8uLuzzAa3fV2ClRgu1dn4eIFnHA+K5JCAt+dG59vrKHG7RMDajsv6fcGm58CbmISsV6LvSPQUgUVEC0OuTaDlv2QWXoJ/t2w6VcYqPfK/Q+VGYO4LlEUcvUvKwZAsTSh0vZb3AJf2w03vaLA+NtYJIGcpgQKkuVNy9JX54VchfnjvVqloAoVQa8tZH60mk9jFoUBlYSMG96GGSWqKA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kPS/5oCHqB3y4HzsoGOQYZaYsOw0nAAWSbIVfq+Bamo=; b=O7Tf5DcmnVjN/BFIsHvgq14U4tuvysRDtQK6iiUHf2xuD0rTaPQWXqvS2tSHf5W3Y3CbBAvkmpPQwqElAcljPx+bYjVf+w2VQ2pvjXFfjO6nkK9xpxFypQVfouJLBukLM9TamEdyUWcqAxC47RC2CM5Om7Uoq/AhAP6YokQCA0E6hJ46YQ8LeAp0CbcIJHd5EE9tgnZZX+X673S9Hx4T+5+Opr3rJ3PJrGrRIhfQks6vO5bLp+18D/eKpSlxJwJ8/9uTRBrIER7+37lmlhVeq0R5taXMMszCk+iJ376aNM6DXgXkh3xBS1MkCukENgiU1GIdqWkkrz7nuQ+lkI8HBg== Received: from SY7PR01MB10921.ausprd01.prod.outlook.com (2603:10c6:10:334::16) by SY7PR01MB10570.ausprd01.prod.outlook.com (2603:10c6:10:332::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9678.17; Wed, 4 Mar 2026 08:39:11 +0000 Received: from SY7PR01MB10921.ausprd01.prod.outlook.com ([fe80::7908:e00:4ab1:d120]) by SY7PR01MB10921.ausprd01.prod.outlook.com ([fe80::7908:e00:4ab1:d120%5]) with mapi id 15.20.9654.022; Wed, 4 Mar 2026 08:39:11 +0000 From: Japin Li To: Akshay Joshi Cc: Euler Taveira , =?utf-8?Q?=C3=81lvaro?= Herrera , Amul Sul , Andrew Dunstan , Chao Li , Quan Zongliang , pgsql-hackers Subject: Re: [PATCH] Add pg_get_database_ddl() function to reconstruct CREATE DATABASE statement In-Reply-To: (Akshay Joshi's message of "Fri, 27 Feb 2026 17:52:36 +0530") References: <202602251144.gu4luvkj6e2c@alvherre.pgsql> <0fbd1982-4bc3-4c10-aa66-9446af7dc48a@app.fastmail.com> User-Agent: mu4e 1.12.12; emacs 29.3 Date: Wed, 04 Mar 2026 16:39:06 +0800 Message-ID: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SEWP216CA0069.KORP216.PROD.OUTLOOK.COM (2603:1096:101:2ba::15) To SY7PR01MB10921.ausprd01.prod.outlook.com (2603:10c6:10:334::16) X-Microsoft-Original-Message-ID: <875x7cm1jp.fsf@hotmail.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SY7PR01MB10921:EE_|SY7PR01MB10570:EE_ X-MS-Office365-Filtering-Correlation-Id: 127c0ab2-7f14-4ce0-4d89-08de79c9821c X-Microsoft-Antispam: BCL:0;ARA:14566002|8060799015|19110799012|23021999003|12121999013|15080799012|461199028|11091999009|41001999006|6090799003|5072599009|40105399003|53005399003|440099028|3412199025; X-Microsoft-Antispam-Message-Info: =?utf-8?B?ZDRZMmdwbXRMTksvS2FwMWhCUTRjUlliVXpXUDhQTmVwNnZ2akYrUnVZSEp2?= =?utf-8?B?ZEJBTnphOHZGaGRSUko4ZFFDQnhTZWJqbUZhRmlUWnBKdVV1bGU3Nm4zelp6?= =?utf-8?B?YUwzRGJxbHhaNkgrS0pteVVEc09jZUFWQmE3TDVnUnh5M3QrREhtczNZTThW?= =?utf-8?B?aEFEZHg3TzVBdHB2ZkZWdHhtakQxRCtsNFBlTk1vQndsbFpSbFlFZVVhS2o5?= =?utf-8?B?ZWh0L04zODg2am1HUXp2bXRjVG1HUXZkcnhJeER3OWZhZmRnVnNPQ3ZIbU1x?= =?utf-8?B?eVQ5MDdlQVZtZkNMM2owVWVsY202UVNaZitOYXRSQmhyVjFNRHNvUUkrYVVy?= =?utf-8?B?dDF5OGp5cFU5dU9hTCtBNGhPQ0Qzak50ak94MWw1YXZUcnFjcG1tSUI5ak9P?= =?utf-8?B?UmhudXpVaWxYeFZHWHNsdHYrelFaa2FIUkVDSUlyM2hwWlQ5LzUwZ2FyL051?= =?utf-8?B?K0pEdStSb1FHUUJGeFI1K1ordEpkaE5GSzNGb0pDeXB4bFpnUjdOSk1DblZp?= =?utf-8?B?ejBQZ2ZLWkpEYnpzSXBSTjlvNmI4WUd5aTZEcTAvRVhkSW9Ca1lsNWdBZGIw?= =?utf-8?B?Rzg2c09VVHlPODh4T1JJL0tjcU1sZnJuSmJPQVBBKzBVSHQ4NVdUQmRsZXdH?= =?utf-8?B?RjZCSzU4ZWFjcXEwazNhbDFDek1hVk9TNTl2SjFnOEdNUW85eUltRVV5SG9y?= =?utf-8?B?dXRvNzhjdDNEZncvaXMrREV0UWFoR0RQRjJJUWwwdDMrZTl4bDZmZTcyYUph?= =?utf-8?B?dVl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QzYvTlU5Y2lZMTFMQ2VIVHZoMlFTcmZpdTdKMlRpWGVK?= =?utf-8?B?dEZ3dllHd3FiNjhObW0zVkF0djN4aTRINExtd1VDZTBtRnJjcmtSZXF6YUx1?= =?utf-8?B?YzVETXpiQzJIYU9DRlhzTG5xZTJnaWlmQnQ5aG1jcWN4WFVHT2lNcUNGUmhk?= =?utf-8?B?Q05yU0tuUkIxSGIyZjdqdDhaUm1DSW84RFpFL2k5MGlqYmFmVEpoM0xqNFY3?= =?utf-8?B?MGx4ZThBcXU1RXc3TFlOTHRUMXh6bDRzZVR5T2lENitUVHB2WHRRQlR0QWhB?= =?utf-8?B?Q0ZET29mYzcwYzJVUTlxVnNNZ29mNjc4MXZRdXFZS3dyTDZ0ejVMREVJWkRk?= =?utf-8?B?eTRncjhRVHpGRk0xRGJIdmdyNUZZVEZkMXl0NzNFNkxCa2sybUZ0UGlPVE41?= =?utf-8?B?OFpGb3c4YUxMcWxBdGtMakVBMkoybzZCSDU1RGc5eTJ3NmRsZjc1cExjdm0w?= =?utf-8?B?WlI3QkxGWUdoUGhXRmFxaDJtclE4cko5SGhWckpIT3BNVDZ0T2paUmNORHZj?= =?utf-8?B?QW84MjBlZnE4Z2toRkZ4WlIvakZ5UXJFWFdzUHNiUk9tKzJCRk81L0Y0TXAr?= =?utf-8?B?UlpoTllYa1llcE1wZ0NyOGxxZ1ZlbWhjVHNIV0J6WFVvZmxBc1lxaWR3R0Uv?= =?utf-8?B?VzJxemRMNUNkSHZhTGRyV3pOeStDd1VBZUpiWGRCRWIxenZRN012QWE1NkpL?= =?utf-8?B?L2xvWWxEbys5YkRIYlFEQVJqbFZ2ZmZaUUFPa01CMERYb2ZzZ05HakkvOHpD?= =?utf-8?Q?VGmS46c75EEmM?= X-OriginatorOrg: sct-15-20-9412-4-msonline-outlook-feddd.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: 127c0ab2-7f14-4ce0-4d89-08de79c9821c X-MS-Exchange-CrossTenant-AuthSource: SY7PR01MB10921.ausprd01.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Mar 2026 08:39:11.4043 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SY7PR01MB10570 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, 27 Feb 2026 at 17:52, Akshay Joshi = wrote: > Following suggestions from Alvaro and Mark, I have re-implemented this fe= ature using variadic > function argument pairs. > This patch incorporates Mark Wong=E2=80=99s documentation updates, Amul= =E2=80=99s one review comment, and the > majority of Euler=E2=80=99s comments. > > New changes: > - Supports flexible DDL options as key-value pairs: > - pretty - Format output for readability > - owner - Include OWNER clause > - tablespace - Include TABLESPACE clause > - defaults - Include parameters even if it is set to default value. > - Option values accept: 'yes'/'on'/true/'1' (or their negatives) > > Usage Examples: > -- Basic usage with options > SELECT pg_get_database_ddl('mydb', 'owner', 'yes', 'defaults', 'yes'); > -- Pretty-printed output without owner and tablespace > SELECT pg_get_database_ddl('mydb', 'owner', 'no', 'tablespace', 'no', '= pretty', 'on'); > -- Using boolean values > SELECT pg_get_database_ddl('mydb', 'owner', false, 'defaults', true); > -- Using OID > SELECT pg_get_database_ddl(16384, 'pretty', 'yes'); > > Note: To keep things clean, I=E2=80=99ve moved the logic into two generic= functions (get_formatted_string > and parse_ddl_options) and a common DDLOptionDef struct. This should simp= lify the work for the > rest of the pg_get__ddl patches. > > Attached is the v9 patch which is ready for review. > > On Thu, Feb 26, 2026 at 2:49=E2=80=AFAM Euler Taveira = wrote: > > On Wed, Feb 25, 2026, at 8:53 AM, =C3=81lvaro Herrera wrote: > > > > I'm surprised to not have seen an update on this topic following the > > discovery by Mark Wong that commit d32d1463995c (in branch 18) already > > established a convention for passing arguments to functions: use argum= ent > > pairs to variadic functions, the way pg_restore_relation_stats() and > > pg_restore_attribute_stats() work. While I like my previous suggestio= n > > of using DefElems better, I think it's more sensible to follow this > > established precedent and not innovate on this. > > > > This convention is much older than the referred commit. It predates from= the > logical decoding (commit b89e151054a0). See pg_logical_slot_get_changes_= guts() > that is an internal function for pg_logical_slot_FOO_changes(). It seem= s a > good idea to have a central function to validate the variadic parameter = for all > of these functions. > Thanks for updating the patch, here are some comments on v9. 1. + uint64 flag; /* Flag to set */ Do we actually need 64 bits for this flag field? 2. + /* Indent with spaces */ + for (int i =3D 0; i < nSpaces; i++) + { + appendStringInfoChar(buf, ' '); + } How about using appendStringInfoSpaces(buf, nSpaces) instead? 3. + /* If no options provided (VARIADIC NULL), return the empty bitmask */ + if (nargs < 0) + return flags; + + ... + + /* No arguments provided */ + if (nargs =3D=3D 0) + return flags; These two conditions are identical =E2=80=94 how about just `if (nargs <=3D= 0)`? 4. + /* Arguments must come in name/value pairs */ + if (nargs % 2 !=3D 0) + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("argument list must have even number of elements"), + errhint("The arguments of %s must consist of alternating keys and val= ues.", + "pg_get_database_ddl()"))); Should we align this with stats_fill_fcinfo_from_arg_pairs()? Suggested wording: errmsg("variadic arguments must be name/value pairs") =20 5. + /* Key must not be null */ + if (nulls[i]) + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("argument %d: key must not be null", i + 1))); + Suggested wording: errmsg("name at variadic position %d is null") 6. + /* Key must be text type */ + if (types[i] !=3D TEXTOID) + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("argument %d: key must be text type", i + 1))); Suggested wording: errmsg("name at variadic position %d has type %s, expected type %s") 7. + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("argument %d: value for key \"%s\" must be boolean or text ty= pe", + i + 2, name))); Suggested wording: errmsg("argument \"%s\" has type %s, execpted type boolean or text") See stats_check_arg_type(). 8. + for (i =3D 0; i < nargs; i +=3D 2) + { We can narrow the scope of `i` by declaring it in the for initializer. 9. + { + bool found =3D false; + int j; + + for (j =3D 0; j < lengthof(ddl_option_defs); j++) + { Minor style improvements: - We can (and should) declare `j` inside its for-loop initializer, just lik= e `i`. - Move the declaration of `found` up to the top of the outer for-loop scope= . =20 This allows us to remove the unnecessary braces around the loop body. --=20 Regards, Japin Li ChengDu WenWu Information Technology Co., Ltd.