Re: pg_get_*_ddl() needs a redesign

Поиск
Список
Период
Сортировка
Искать

Re: pg_get_*_ddl() needs a redesign

От:
Andrew Dunstan <andrew@dunslane.net>
Дата:

On 2026-09-09 We 11:47 AM, Melanie Plageman wrote:
>
> [RMT hat]
>
> We are concerned that there has been no reply addressing these
> reported issues. We urge the feature authors to reply and determine
> whether or not this feature needs to be fixed (or reverted).


Sorry, my bad. Euler and I have been working on fixes, which I hope to 
publish today. There was a slight delay due to the issue addressed by my 
commit a12600b762c from an hour or so ago.


cheers


andrew


--
Andrew Dunstan
EDB: https://www.enterprisedb.com



Re: pg_get_*_ddl() needs a redesign

От:
Noah Misch <noah@leadboat.com>
Дата:
On Wed, Sep 09, 2026 at 12:24:32PM -0400, Andrew Dunstan wrote:
> On 2026-09-09 We 11:47 AM, Melanie Plageman wrote:
> > [RMT hat]
> > 
> > We are concerned that there has been no reply addressing these
> > reported issues. We urge the feature authors to reply and determine
> > whether or not this feature needs to be fixed (or reverted).
> 
> Sorry, my bad. Euler and I have been working on fixes, which I hope to
> publish today. There was a slight delay due to the issue addressed by my
> commit a12600b762c from an hour or so ago.

I want to clarify one thing before you spend much time on fixes.  I don't see
"fixes" addressing this thread as a whole, unless you plan to dispute the
premise that the feature needs a redesign.  In other words, I think the thread
outcome should be one of these:

- My review erred in determining that the feature needs a redesign.  The
  design is sound and should proceed, possibly with some fixes.

- Revert the feature.


Re: pg_get_*_ddl() needs a redesign

От:
Andrew Dunstan <andrew@dunslane.net>
Дата:
Вложения:


On 2026-09-09 We 1:34 PM, Tom Lane wrote:
Noah Misch <noah@leadboat.com> writes:
I want to clarify one thing before you spend much time on fixes.  I don't see
"fixes" addressing this thread as a whole, unless you plan to dispute the
premise that the feature needs a redesign.  In other words, I think the thread
outcome should be one of these:
- My review erred in determining that the feature needs a redesign.  The  design is sound and should proceed, possibly with some fixes.
- Revert the feature.
FWIW, I agree with Noah's point that having two independent
implementations of SQL reverse compilation is not really a place
we want to be: it will be a major PITA for future development.

Unfortunately, I see no practical way to have pg_dump share code with
the backend for most of this stuff; not least because pg_dump has to
support dumping from old backends that won't have any such feature.
So we either swallow that duplication or decide that we're never
going to support this in the backend.  Neither choice is palatable,
but I don't think I want to be forced into the duplicative approach
when we've not explored other alternatives (such as refactoring
pg_dump to expose its internal logic in some way).
			


I first raised the idea of these functions on the mailing list in July 2025, although the idea was much older. [1] Among other things, you (Tom) said [2]:

Insisting that this feature support pg_dump is a good way
of making sure that nothing useful will emerge at all.
Concrete patches began to appear around October and November 2025. I don't recall anyone coming along and saying "No, we don't want to do that." After they were committed there were various comments on the way they were done, and I addressed them.  Now, months later, we are more or less told that this whole enterprise has been misguided from the start. Is it any wonder that people often find the process of contributing to Postgres discouraging? And that would include people who have been working on more important members of this set for release 20, particularly the one that most people want, namely pg_get_table_ddl() that Akshay has been working on. I don't feel badly for myself, but I do feel badly for the contributors.

I believe reverting now almost certainly means this proposal or anything like it is probably dead for the foreseeable future. 

To me it is beyond stupid that a postgresql server doesn't have enough introspection to be able to produce the DDL for its own objects. Telling people that they have to call pg_dump/pg_dumpall to generate the DDL programmatically is awful. So, do I think this is worth the possible maintenance burden? Yes. I might take a suggestion of "needs redesign" more seriously if there had been a hint of what that might look like. But without that it looks to me like a way of saying "I don't like the feature or think we need it."

cheers

andrew


[1]  https://postgr.es/m/945db7c5-be75-45bf-b55b-cb1e56f2e3e9@dunslane.net

[2]  https://postgr.es/m/758258.1755354170@sss.pgh.pa.us


--
Andrew Dunstan
EDB: https://www.enterprisedb.com

Re: pg_get_*_ddl() needs a redesign

От:
Andrew Dunstan <andrew@dunslane.net>
Дата:

On 2026-09-09 We 6:25 PM, Andrew Dunstan wrote:
>
>
> Thanks for reviewing. I hope to have some proposals tomorrow for 
> addressing these issues as well as those raised by Noah.
>
>
>

I have run out of time, energy and brain cells. I have some working 
patches, but a) they need a little polish and b) I think they are too 
invasive for consideration now. The major difference in actual code (as 
opposed to testing) is in how we deal with permissions. I spent quite a 
lot of time yesterday and today on that, and came to the conclusion that 
it needs to be reworked along these lines: we should allow the user to 
see the information the functions provide if and only if they can see it 
by directly selecting from the catalog. Code changes to implement this 
by directly running ACL checks on  the relevant catalogs are 
straightforward but also substantial. My proposed changes to testing are 
also substantial, being both more efficient and providing better 
coverage, especially w.r.t pg_dump/all compatibility.

I therefore suggest that we revert for release 19, but not in master, 
and I will continue to polish the patches I mentioned and publish them 
in a few days.

I can make the revert happen in the next day or so.


cheers


andrew


--
Andrew Dunstan
EDB: https://www.enterprisedb.com



Re: pg_get_*_ddl() needs a redesign

От:
Robert Haas <robertmhaas@gmail.com>
Дата:
Вложения:
On Fri, Sep 11, 2026 at 1:27 AM Noah Misch  wrote:
> > I think we would do well to confine all of our present conversations,
> > insofar as it is possible to do so, to whether any given feature
> > contains defects incompatible with shipping it.
>
> The defects are the reason not to ship this implementation.  One of those
> defects, the inability to restore in dependency order, cannot be fixed without
> redesigning the current SQL-facing API.  That is the reason not to ship this
> design.  See my original post of this thread for details.

I saw that, but that seems like you're questioning the feature's
choice of scope as much as its actual merits. I suppose the idea was
that this feature is for getting the definition of an individual
object for possible cloning into this database or some other where the
prerequisites are already present. If the feature had the intention of
allowing for full-database restoration and failed to do so, that's a
code defect. Otherwise, it isn't. If the feature could reasonably have
been designed in such a way that it would allow for full-database
restoration but was not actually designed in such a way, that's a
design defect. It's not obvious to me that this is the case, but it
might be. If there's no reasonable way to make a feature of this type
suitable for that use case, this isn't a defect at all, just code that
does something that you may not find entirely worthwhile. Regardless,
I'm not saying that you have to like this feature -- I don't think
it's great either, although it seems I dislike it less than you -- but
I think fairness demands that we not label as code defects issues that
are properly categorized otherwise.

-- 
Robert Haas


Re: pg_get_*_ddl() needs a redesign

От:
Andrew Dunstan <andrew@dunslane.net>
Дата:
Вложения:

On 2026-09-10 Th 7:59 PM, Andrew Dunstan wrote:
>
> On 2026-09-09 We 6:25 PM, Andrew Dunstan wrote:
>>
>>
>> Thanks for reviewing. I hope to have some proposals tomorrow for 
>> addressing these issues as well as those raised by Noah.
>>
>>
>>
>
> I have run out of time, energy and brain cells. I have some working 
> patches, but a) they need a little polish and b) I think they are too 
> invasive for consideration now. The major difference in actual code 
> (as opposed to testing) is in how we deal with permissions. I spent 
> quite a lot of time yesterday and today on that, and came to the 
> conclusion that it needs to be reworked along these lines: we should 
> allow the user to see the information the functions provide if and 
> only if they can see it by directly selecting from the catalog. Code 
> changes to implement this by directly running ACL checks on  the 
> relevant catalogs are straightforward but also substantial. My 
> proposed changes to testing are also substantial, being both more 
> efficient and providing better coverage, especially w.r.t pg_dump/all 
> compatibility.
>
> I therefore suggest that we revert for release 19, but not in master, 
> and I will continue to polish the patches I mentioned and publish them 
> in a few days.
>
> I can make the revert happen in the next day or so.
>
>
>

OK, I have done that revert. Here are the patches Euler and I have in mind.


cheers


andrew



--
Andrew Dunstan
EDB: https://www.enterprisedb.com

Re: pg_get_*_ddl() needs a redesign

От:
Mario González <gonzalemario@gmail.com>
Дата:
Sorry for top-posting but I reckon I'm not replying to each statement
separately but as a whole.


Hello all,

As one of the authors of pg_get_role_ddl(), I've been reading this
thread *carefully*, and I took quite a long time to analise what and
how I'd address the concerns. I noticed that despite the fact that
I've put a lot of effort a) I may not be understanding all of the
objections correctly and b) before anyone (hopefully me) spends more
time on code for v20 or newer, I'd like to check my reading with you,
and ask whether a possible direction makes sense.  Please correct me
wherever I've got it wrong.

sorry.... It's a *very* long email.

How I'm reading the problems
----------------------------

If I understand correctly, the concerns fall into three groups:

1. Plain defects (passwords, "PG_DEFAULT", locking, permissions).  I
reckon Andrew and Euler's v6 patches [1] fix these, apart from two
loose ends: password defaults to true, so a default call still needs
pg_authid access, and permission errors name the target object rather
than the denied catalog. However, am I right in thinking these are not
the main concern? (please keep reading if possible)

2. Ordering.  Each function returns one object's script, but some of
its statements depend on other objects: IN DATABASE settings need the
database, and GRANT ... GRANTED BY g needs g to hold ADMIN OPTION
first, which comes from g's output.  I'm worried the cross-role case
can't be solved one role at a time, which I believe is why
dumpRoleMembership() makes repeated passes. Noah, is this the redesign
issue you meant?

3. Two independent implementations.  pg_dumpall builds the same DDL on
the client side, and nothing would tell us when the two drift apart,
which I understood to be Robert's main concern.

I believe that's a fair summary, so what I hope we could achieve:


* Users can get the definition of an existing object from SQL, for the
'give me something like this object so I can tweak it' case that
Andrew and Marcos described.
* There is one implementation of 'catalog state -> SQL' per object
type, ideally used by pg_dump/pg_dumpall too, so it gets tested all
the time.
* The backend functions describe one object at a time and make no
promise about the order in which their output can be run.  Working out
that order, across all objects, stays with pg_dump/pg_dumpall, which
already does it.

Does this match what others would want, or are some of these goals,
maybe not realistic?

A possible direction, for discussion
------------------------------------

a) Split pg_get_role_ddl() into smaller functions: one for the CREATE
ROLE, one for the role's settings, one for its memberships. None of
them tries to put statements in restore order; the caller decides when
to run each part.
(Meant to address Noah's ordering concern.)

b) pg_dumpall calls these functions instead of building the same SQL
itself, so there is only one copy of the code that turns catalog rows
into SQL.  For servers too old to have the functions, pg_dumpall keeps
its current code, which no longer needs to change because those
servers won't change either.  I reckon this is close to what Tom
sketched [2]. (Meant to address the 'two implementations' concern.)

c) Tests compare the functions' output with pg_dumpall's for the same
objects, as v6 begins to.  They'd need to be broader than v6's,
perhaps driven by pg_dump's own tests, to catch a newly added option.
(Meant to address Robert's silent-drift and Andres's cross-check concerns.)

Questions where I'd need confirmation
-------------------------------------

1. Noah, Tom: if pg_dumpall actually used these functions, would that
address the 'one implementation' concern?  If not, what would?

2. Would it be acceptable to keep the current client-side code for
older source servers, expecting to remove it eventually?

I'd rather not start on a patch until I know whether this direction is
reasonable.  If it is, I'd be happy to start with roles, since
that's the part I know best.

Thank you for your patience, and for the reviews so far.

Regards,
Mario Gonzalez

[1] https://postgr.es/m/88e205f5-f561-4a00-b6e6-ab070ea6400a@dunslane.net
[2] https://postgr.es/m/956966.1789102554@sss.pgh.pa.us




On Fri, 11 Sept 2026 at 13:28, Robert Haas  wrote:
>
> On Fri, Sep 11, 2026 at 11:58 AM Tom Lane  wrote:
> > Maybe --quote-all-identifiers should be the default?  I don't think
> > that we break old syntax "pretty regularly" in any other way.
> > But that's a side point.
>
> It's possible it's been less in recent years, but I feel like that's
> just the most common way, like you know 50% of the total breakage or
> something.
>
> > I'm not quite convinced.  But if that's really the case, I'm voting
> > for "discard the feature".  It's not useful enough to justify doubling
> > the maintenance load associated with DDL reconstruction.
>
> I think what really bothers me here is the chances of silent breakage,
> which appear to be high. If it were somehow the case that adding a new
> feature to some kind of DDL object, like a FLAVOR banana option to
> CREATE TABLE, were likely to produce test failures until the
> corresponding code was updated, I don't think that would be bad. It
> would just be one more small step that everyone extending a DDL
> command would have to do. But as it is, I don't think anything would
> alert you to the oversight. That's likely to lead to a lot of future
> headaches as we discover that things have been broken for years
> without anybody noticing. Or maybe in the LLM era we'll just get a
> flood of post-commit reports pointing out the problem. But that still
> leads to us playing catch-up, which is not a good situation.
>
> --
> Robert Haas



-- 
Mario Gonzalez


Re: pg_get_*_ddl() needs a redesign

От:
Noah Misch <noah@leadboat.com>
Дата:
On Mon, Oct 19, 2026 at 01:03:59PM -0300, Mario González wrote:
> Questions where I'd need confirmation
> -------------------------------------

You've asked me some specific questions, but the larger problem is the email's
summary oversimplifying the upthread points from Tom, Andres, Robert, and me.
I wouldn't recommend proceeding.  A successful project for $SUBJECT needs
someone accountable for auditing each iteration against the feedback to date,
point by point.  I don't have capacity to take that role.


Re: pg_get_*_ddl() needs a redesign

От:
Mario González <gonzalemario@gmail.com>
Дата:
On Tue, 20 Oct 2026 at 14:17, Noah Misch  wrote:
>

Thanks for replying!

> On Mon, Oct 19, 2026 at 01:03:59PM -0300, Mario González wrote:
> > Questions where I'd need confirmation
> > -------------------------------------
>
> You've asked me some specific questions, but the larger problem is the email's
> summary oversimplifying the upthread points from Tom, Andres, Robert, and me.

I'm not sure I agree with that's the larger problem. Of course I
simplified the summary but you picked exactly what I reckon I'm trying
to do, bring someone accountable that lead any of the sub items.
Considering that you Noah were particularly involved with raising the
alarm of the functions would need a re-design, I believed you also
wanted to take part of re-routing any effort towards what could be a
final or an acceptable solution. Complaining sometimes is the easy
part but valuable. I just hoped you could do more helping me or
someone else. I understand if you can't.

> I wouldn't recommend proceeding.  A successful project for $SUBJECT needs
Of course again. I won't proceed, that's why I tried to make my words
as concise as possible and despite that I said I won't proceed in the
previous email, yet it seems I wasn't clear.

> someone accountable for auditing each iteration against the feedback to date,
> point by point.  I don't have capacity to take that role.

fair enough.

-- 
Mario Gonzalez


Re: pg_get_*_ddl() needs a redesign

От:
Robert Haas <robertmhaas@gmail.com>
Дата:
On Mon, Oct 19, 2026 at 12:04 PM Mario González  wrote:
> a) Split pg_get_role_ddl() into smaller functions: one for the CREATE
> ROLE, one for the role's settings, one for its memberships. None of
> them tries to put statements in restore order; the caller decides when
> to run each part.
> (Meant to address Noah's ordering concern.)
>
> b) pg_dumpall calls these functions instead of building the same SQL
> itself, so there is only one copy of the code that turns catalog rows
> into SQL.  For servers too old to have the functions, pg_dumpall keeps
> its current code, which no longer needs to change because those
> servers won't change either.  I reckon this is close to what Tom
> sketched [2]. (Meant to address the 'two implementations' concern.)
>
> c) Tests compare the functions' output with pg_dumpall's for the same
> objects, as v6 begins to.  They'd need to be broader than v6's,
> perhaps driven by pg_dump's own tests, to catch a newly added option.
> (Meant to address Robert's silent-drift and Andres's cross-check concerns.)

I think you're going to find it very difficult to make this work.
There are cases where pg_dump splits things up in different ways
depending on the situation. I'm not sure how many such cases remain
off-hand, but I wouldn't be surprised if it isn't enough to make (a) a
non-viable direction. But also, even if you did that, how would it
help? pg_dump builds DDL on the client side so that the DDL matches
the pg_dump version, not the server version. Tom seems to think that
quote_all_identifiers would solve most of that problem, but I don't
agree. I think if you go down the path you propose here, this is going
to get nowhere.

If I were working on this project, what I'd be thinking about is what
the test framework could look like. I don't think that needs to be
pg_dump or pg_dumpall; but I think it needs to be something. For
example, imagine that you take the regression database -- i.e. the
final state left behind by a run of the 'regress' suite -- which we
already use to test pg_upgrade. For each DDL object in the database,
you use pg_get...ddl(), then drop the object, then put the object back
by running the SQL, and then at the end you compare pg_dump output
before and after you did all that. Well, that's not going to be quite
good enough, because a lot of objects will probably have dependencies
and not be droppable, and some objects might have circular
dependencies which might be really complicated, but you could
experiment with creating a TAP test that can work out the dependency
ordering from pg_(sh)depend and drop objects in reverse dependency
order and then put them all back. Maybe it's not crazy complicated.

Another idea could be to actually run the main regression test suite
and have an event trigger that fires every time an object is created
or dropped and try to do DDL replication using this feature: you run
the get-ddl function and replay it in another database that has no
actual data. This kind of sucks because it's expensive and most of the
objects getting created and dropped are fairly boring, but it would
probably test more cases than the previous idea, so it might be worth
doing at least once just to flush bugs out of your implementation,
even if we don't ever commit the result. Another advantage of this is
that, if properly coded, it cannot fail to go kaboom if a new type of
DDL object is added and there's no matching get-ddl function.

(By the way, why are we talking about adding a separate get-ddl
function for every object type, instead of a single entrypoint that
takes an object type and a function OID as separate arguments? The
latter seems much more natural and more consistent with existing
practice.)

I'm not sure either of the above testing ideas are the right final
answer. Maybe there is no right final answer. But in this era of LLMs,
anybody can churn out an implementation of the functions themselves.
Someone could probably create an entire patch set from scratch in less
than a day, and somebody really good at LLM things could possibly do
the whole thing in a single prompt. So, just producing a bunch of code
isn't really adding a lot of value; anybody could do it. Where you add
value is in figuring out how to solve all the problems that your first
design idea creates. And that's where I would gently push back on your
email here a little bit: you're proposing a design which I'm fairly
sure is not going to actually solve those problems, but you seem to
think it will. So one of us is wrong. If it's me, you can demonstrate
that by making it work. If it's you, you could figure that out by
trying it, seeing what goes wrong, and then thinking about how to deal
with that. I'm not saying you shouldn't ask for advice here, but you
should solicit that advice at the point where you come to a real fork
in the road, and "will the design work" isn't that.

After writing this email, I asked Claude to read the thread using the
pg.ddx.io MCP connector and do a technical assessment of your last
proposal. Here's what it said:

>>>
On the technical merits, I'd still expect it to fail. Splitting
pg_get_role_ddl() into CREATE ROLE, settings and membership functions
is sound: each function describes one thing, and ordering moves to the
caller. That fixes the restore-ordering problem at the API level. The
cost is that the caller has to do the multi-pass grantor ordering
itself, which removes most of the convenience for anyone who isn't
pg_dumpall. The central idea, having pg_dumpall call the source
server's functions so there's only one implementation, doesn't hold
up. The client needs to control its output to deal with version skew:
quoting newly reserved keywords, syntax the target server no longer
accepts, binary-upgrade variants, and bugs in the generator.
Server-side output is frozen at whatever minor release the source
runs, so the client would need its own code for these cases anyway,
and you'd have two implementations again with a more complicated split
between them. The functions would also need dump-specific modes
(target version, binary-upgrade, quote-all, and so on), so they would
grow into a backend copy of pg_dump's option handling. Roles are the
easiest case because there are few objects, the syntax is simple, and
per-object calls don't hurt performance. That makes them a misleading
pilot. Tables, with constraints split out for data loading and
partitioning, plus per-object calls on large schemas, are where this
breaks. The proposed equivalence tests are worth having, but they only
catch drift for options someone has already exercised. A new DDL
option still passes silently unless a test happens to use it.
Something like a catalog-coverage check that fails when a column isn't
handled would be needed to make drift detection reliable. The version
that could work is narrower: standalone "show me this object"
functions that make no promise to replace pg_dump, backed by coverage
tests strong enough to catch new options automatically.
<<<

It took less than a minute to get that answer, and writing this email
has taken me a lot more than a minute, and while I venture to hope
that my email is clearer than Claude's output, it does pretty much
tell you why your idea isn't going to work. I think that for a project
like this, if the level of due diligence that you're going to do
before posting is less than "paste your proposal into an LLM and see
what it says," the project probably won't succeed. Lots of people (me
included) would like this feature to exist, so the fact that it
doesn't exist is evidence that coming up with something good is
difficult. Even before LLMs, writing the code was never the hard part.
The hard part has always been figuring out a design that can answer
the inevitable objections. If someone here already knew how to do
that, this would likely be done already. Until you've thought about
this problem than everyone on this thread and have better ideas than
we do, there's probably no point in proposing anything.

-- 
Robert Haas
Databricks


FAQ