Re: pg_get__*_ddl consolidation
Jeff Davis <pgsql@j-davis.com>
From: Jeff Davis <pgsql@j-davis.com>
To: Andrew Dunstan <andrew@dunslane.net>, "David G. Johnston" <david.g.johnston@gmail.com>, Japin Li <japinli@hotmail.com>
Cc: Zsolt Parragi <zsolt.parragi@percona.com>, Euler Taveira <euler@eulerto.com>, Álvaro Herrera <alvherre@kurilemu.de>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2026-04-10T20:03:36Z
Lists: pgsql-hackers
On Sun, 2026-04-05 at 11:06 -0400, Andrew Dunstan wrote:
> Pushed. I have moved the remaining get_*_ddl items to PG20-1
The line:
role_settings = DatumGetArrayTypeP(datum);
should be DatumGetArrayTypePCopy(), because it's being pfree()d later.
The existing code will sometimes make a copy and sometimes not, e.g.:
-- settings are contrived to make the datum inline
CREATE USER u1;
ALTER ROLE u1 SET search_path = 'public, pg_catalog, pg_temp';
ALTER ROLE u1 SET work_mem='64MB';
ALTER ROLE u1 SET statement_timeout='30s';
ALTER ROLE u1 SET lock_timeout='10s';
ALTER ROLE u1 SET idle_in_transaction_session_timeout = '60s';
SELECT pg_get_role_ddl('u1');
ERROR: pfree called with invalid pointer 0x7986dd0c7cc8 (header
0x0000400600000000)
Also, it looks like the scan key in pg_get_role_ddl_internal() uses
only the second attribute of the index, which might be worth a comment.
Regards,
Jeff Davis
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Use named boolean parameters for pg_get_*_ddl option arguments
- d6ed87d19890 19 (unreleased) landed
-
Convert ddlutils regression tests to TAP tests.
- c529ee38b9eb 19 (unreleased) landed
-
Fix pfree crash in pg_get_role_ddl() and pg_get_database_ddl().
- 1f108fc02ece 19 (unreleased) landed
-
Fixups for a4f774cf1c7
- 6c7bce28c83f 19 (unreleased) landed
-
Add infrastructure for pg_get_*_ddl functions
- 4881981f9202 19 (unreleased) landed
-
Add pg_get_database_ddl() function
- a4f774cf1c7e 19 (unreleased) landed
-
Add pg_get_role_ddl() function
- 76e514ebb4b5 19 (unreleased) landed
-
Add pg_get_tablespace_ddl() function
- b99fd9fd7f36 19 (unreleased) landed