Re: pg_get_*_ddl() needs a redesign

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Noah Misch <noah(at)leadboat(dot)com>, Melanie Plageman <melanieplageman(at)gmail(dot)com>, gonzalemario(at)gmail(dot)com, dbryan(dot)green(at)gmail(dot)com, euler(at)eulerto(dot)com, pgsql-hackers(at)postgresql(dot)org
Subject: Re: pg_get_*_ddl() needs a redesign
Date: 2026-09-12 14:02:59
Message-ID: c51c8535-5f75-46fd-b4ef-eaa304f9311a@dunslane.net
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


On 2026-09-11 Fr 12:55 AM, Tom Lane wrote:
> The hard parts as I see it are
>
> (A) pg_dump is optimized to gather data across the entire database
> at once. Converting it to call functions that produce info about
> a single object at a time would almost certainly be catastrophic
> for performance on large databases.
>
> (B) pg_dump slices and dices the data in ways that don't necessarily
> make sense for standalone usage. For example it doesn't want to
> mention a primary key when creating a table, rather it wants to add
> that constraint (and build the index) after loading data.
>
> I do not feel that these problems are necessarily insoluble, but
> they do require some hard work to define the server-side functionality
> properly.
>
>

I think you've put your finger on some of the main issues. The main use
case in my mind from the get go was not "How do we make this work for
pg_dump?" but "I want to create an object that's like this thing but a
bit different. Give me the DDL for this thing so I can tinker with it."
That's the use case that people just about always give me when I've
talked to them about this.

Maybe point A is not insoluble, but I've thought all along that it was a
pretty significant barrier, and I don't have a good solution for it.
Making this feature contingent on solving that problem would sacrifice
the originally intended use case, which would be very sad.

Your point B is also well taken. pg_dump formats and arranges the SQL to
suit its purposes, but that should not be taken as the canonical
arrangement for other uses. Perhaps these functions should have a "dump"
flavor that produces output like pg_dump/all.

cheers

andrew

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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Chee Wooson 2026-09-12 14:16:49 Re: Recovery conflict resolution misses backends that import snapshots
Previous Message Alexander Korotkov 2026-09-12 14:01:57 Re: Should the WAIT FOR command tag be "WAIT" or "WAIT FOR"?