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 1vujHH-003VLt-0D for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Feb 2026 03:40:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vujHF-00Gl9r-30 for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Feb 2026 03:40:01 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vujHF-00Gl9j-22 for pgsql-hackers@lists.postgresql.org; Tue, 24 Feb 2026 03:40:01 +0000 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vujHC-00000000yGl-2xuN for pgsql-hackers@postgresql.org; Tue, 24 Feb 2026 03:40:01 +0000 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-2aad1dc8856so36580115ad.1 for ; Mon, 23 Feb 2026 19:39:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1771904398; cv=none; d=google.com; s=arc-20240605; b=Ib5CKqhzVPKBxBol+Th7UslpzxpY46SohVipwWXS6qA/uJJqCl40UyQv6SGqIFGYrI 2Yl6FSnIKLC/XfpfTNkkq7UolASDptOJboqHKRVse82AXysp2w+tPsXk3rwiQ4I9NPP7 06/qFL+DHjpE7IjePLwrXItr2vqh6kjnBhKnxrJeJjQ8bmCU23/8+JarM6J4hqECSuS5 fc5vGj8UQmtNAno2Yyjf9p9JA37ZvqcQREp4qwsNJEkqWiKk9kNfeqfYRNzC/+nlUb2x x2zcPj5AHZXyDDDw2y1i1PvK14eA82+yGHSrnYFwChsHOWVo0o4U7+KOBIroWNICURPb ZChQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=yJGqjmwFqse4RKYbR3sxb5ofZmZia4YGQ8K2vOC5E5k=; fh=XbFQX0eET6RaFHcOSAeqDG5DHhlDev4/rv8L0oXtCcY=; b=U89ejYvOPIYYdxH9O/tAXKoyi4fNU0nX0u1EiAUYSKhHqTwnGRuQHYYHNqeh0fdU15 inYj06G23PaNrxfWbzyFiex3QmgNBP45CDMEQ+6kDiGQurZrpmjLSayvOHhmBdOnX0g8 pGFnQBy1E364I6rSaKtA3WY8Y+aCqadQXLvNVoU6fhvKZ/hmYD5t4hNynMcykHwG6GSX G00TygCiCUat9Qol3mwgt4RLJn56P9KwW0wof1QgrZ6NmakGjgIGSey2s7ATwYvlBVXz jqccM9d8rOrwBykPN4euahZKw4X72xjwJycq6X60JMiWNkKmRkRnTI88rd3Cs+rpWAw/ MYmg==; darn=postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771904398; x=1772509198; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=yJGqjmwFqse4RKYbR3sxb5ofZmZia4YGQ8K2vOC5E5k=; b=ahPlrM6GNq1yLKGcTYKWGnTunYHRpv0PAuBanky+WAtJufMEL3sKqpl/MrVbrk9NZF +n6Kv0ruQ3+uxGboftNFIH+LktKrfYuD9s/mt9Yz7ZUCwoOJEbqxZYgCvQXbgFtEy5VU z1VSfPJ4YiLD/Zzzybh8/TTdkFGBz0+vkuLrxyhW9CEOuQYkSkma8NS3TVgGoSGJi5j1 hq6AANkWzi0zU4xBRC93G3xB6+4xWgVDHYuQ1PduaaC50A5tn92y4GpuUEF0XWW+aHhH T5oy5eQEytoat4ALrjJavX/yaOUhkwkMddKgqwPqIhpJm5P47ZRkSZNUUyiOzelZc6Yv flXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771904398; x=1772509198; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=yJGqjmwFqse4RKYbR3sxb5ofZmZia4YGQ8K2vOC5E5k=; b=lRA72H2Wu/yD4xdYzNITsHnLf16tRXvmTZMxxBW6ACxc2mL9BGr8kd2sYsDIJ9afER XG9VZDSlGCs5t5lZ+k2ln+HJA5zbUct3ugxk4u90BIZBnS8/WKNeeqO+KaL/YtYp3ZXx TwRUCH69haO0hF5ZBoFCB3l7orjL2yScsY5XlQnCXDLgJYqmGgf1B659dG+PN93/JDTr 2bLnTcC2+XIig6Vvuvc0Ax/dQtDh+fn7tTD4pN7IjBSAOeIxQhwSYE39dXb1prFioWNQ +g55Uxhfk6tiaggPYxflpfUW+E//1uzjvHXJvnWC0C4nMlDiQSou0PNq9xS5buZxUeBt cVGw== X-Forwarded-Encrypted: i=1; AJvYcCXDKCH1Hmfins5l1vGLQMGwQQlSc1uVLVQiBlotIOyT0RAmcBK0VagVBSBt3EVEGah9tDejoM+3t2IICEgH@postgresql.org X-Gm-Message-State: AOJu0YxRz/i2yiPd5T5he/QAGiXWPhW5QGU6FkW6QvpXMjnjh3C0t4GV Pr/kjGJiKY9hCCZnLoPgHVFMWmLoHFy3Vk3BbhYKGxieqYtisf8OlR7a3aDh6ofSgW3+aKRC6+R YLk/7aafx68bEKHrk1TH+UlW5RADnOeU= X-Gm-Gg: ATEYQzzCxdd/gc1nl+9r2Vbg73MKHDafEQAWDeFqiPKNvklOJtuFVjtpXK4dI/3WheW Ce1z+1akzt/NK0PsQPr76/k+UqbnhcInUn/2yA4LRKlNCmW4PZrBqzyX40ksIywrwgIrL3qaVrv iXYMeQ94W30k3L/KgpC217DOgkcAJwcyQGgguoE9TBas2NG6TMUfBd/tWBYCWTcWEld8OIFt4G5 fLNUE5z95lcFvchewgxTj3oCZb6nRkthe1soFMsepyx5aXbkLFgpFjLZuAJSEFDiBPWvSHcgUGC luomQWJFFg== X-Received: by 2002:a17:902:da86:b0:2aa:e570:6e6d with SMTP id d9443c01a7336-2ad7453fb7emr103164635ad.40.1771904397566; Mon, 23 Feb 2026 19:39:57 -0800 (PST) MIME-Version: 1.0 References: <202511191045.tckydhpoxumx@alvherre.pgsql> <4e60bcae-8222-4e1f-8e5b-d73b59c93304@app.fastmail.com> <4c695e76-5ab7-449f-8060-76518dd41468@app.fastmail.com> In-Reply-To: From: Amul Sul Date: Tue, 24 Feb 2026 09:09:18 +0530 X-Gm-Features: AaiRm50_rEyw5YS1QdwGu_7YmH0gcbAiTD8WyTfOcRRSzDlM2TmpZ0B6liWdp14 Message-ID: Subject: Re: [PATCH] Add pg_get_database_ddl() function to reconstruct CREATE DATABASE statement To: Akshay Joshi Cc: Andrew Dunstan , Euler Taveira , =?UTF-8?Q?=C3=81lvaro_Herrera?= , Chao Li , japin , Quan Zongliang , pgsql-hackers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, Feb 23, 2026 at 7:27=E2=80=AFPM Akshay Joshi wrote: > > On Mon, Feb 23, 2026 at 6:50=E2=80=AFPM Amul Sul wrot= e: > > [....] > > /* Standard conversion of a "bool pretty" option to detailed flags */ > > #define GET_PRETTY_FLAGS(pretty) \ > > ((pretty) ? (PRETTYFLAG_PAREN | PRETTYFLAG_INDENT | PRETTYFLAG_SCHE= MA) \ > > : PRETTYFLAG_INDENT) > > > > +#define GET_DDL_PRETTY_FLAGS(pretty) \ > > + ((pretty) ? (PRETTYFLAG_PAREN | PRETTYFLAG_INDENT | PRETTYFLAG_SCHE= MA) \ > > + : 0) > > + > > > > I am a bit confused -- why do we need a separate > > GET_DDL_PRETTY_FLAGS() function? > > -- > > If we use the existing GET_PRETTY_FLAGS, it returns PRETTYFLAG_INDENT > even when pretty is false. However, for Reconstruction DDL, do not > apply indentation if pretty is false. > However, in the patch, you're calling it conditionally; specifically, when the pretty argument is true, it gets called with a value of 1. Also, instead of 1 it should be 'true'. > > > > +CREATE OR REPLACE FUNCTION > > + pg_get_database_ddl(database_id regdatabase, VARIADIC ddl_options > > text[] DEFAULT '{}') > > +RETURNS text > > +LANGUAGE internal > > +AS 'pg_get_database_ddl'; > > + > > > > I don't see any REVOKE EXECUTE ON FUNCTION for this function. > > -- > > Other pg_get_*def functions don't have REVOKE: Functions like > pg_get_viewdef, pg_get_indexdef, pg_get_functiondef, > pg_get_triggerdef, and / are all publicly > accessible none have it. pg_get_database_ddl is purely informational; > it reconstructs CREATE DATABASE DDL from data already visible in the > pg_database system catalog. Any user who can query pg_database already > has access to this information. > > I can add, if the above explanation is wrong. Just let me know. > I think you are correct -- not needed. > > > > +/** > > + * parse_ddl_options - Generic helper to parse variadic text options > > + * ddl_options: The ArrayType from PG_GETARG_ARRAYTYPE_P > > + * flags: Bitmask to set options while parsing DDL options. > > + */ > > +static uint64 > > +parse_ddl_options(ArrayType *ddl_options) > > > > I believe this should be in a separate patch so that it can be reused > > by others working on similar projects. It shouldn't be specific to > > this patch. > > -- > > I have added two generic functions, parse_ddl_options and > get_formatted_string, which will be required by future > pg_get__ddl patches. Is it acceptable to submit a patch > containing only these generic functions before they are actively used? > Yes, that should be a completely separate patch. You can submit it in this thread as part of the same series. > > > > + /* If it's with defaults, we skip default encoding check */ > > + if (is_with_defaults || > > + (pg_strcasecmp(pg_encoding_to_char(dbform->encoding), > > + DDL_DEFAULTS.DATABASE.ENCODING) !=3D 0)) > > > > > > Comment doesn't quite match the logic in the condition. > > Will update this in my next patch. When we decide which approach to follo= w: > 1) Double Dash: > v8-0001-Add-pg_get_database_ddl-function-to-reconstruct-double-dash.patch > 2) DefElem (Key-Value): > v8-0002-Add-pg_get_database_ddl-function-to-reconstruct-DefElem.patch > That=E2=80=99s a bit subjective, as different people will likely have different opinions. I prefer the first version without the -- prefix, since the counterpart would be the default behavior. For example, if "no-tablespace" is not specified, the tablespace would be included in the DDL dump by default. Regards, Amul