Skip to content

Add pg_get_subscription_ddl() function#1

Open
vaibhavdalvi93 wants to merge 4 commits intomainfrom
pg156-add_func_get_sub_ddl
Open

Add pg_get_subscription_ddl() function#1
vaibhavdalvi93 wants to merge 4 commits intomainfrom
pg156-add_func_get_sub_ddl

Conversation

@vaibhavdalvi93
Copy link
Owner

This new SQL-callable function returns the CREATE SUBSCRIPTION statement for a given subscription name.

Like pg_dump, the returned DDL explicitly sets connect = false. This is because the original CONNECT option value is not cataloged, and using connect = false ensures the DDL can be successfully executed even if the remote publisher is unreachable.

By default, the function is restricted to superusers. This is a security measure because subscription connection strings often contain sensitive information, such as passwords. EXECUTE permission can be granted to other users as needed.

Author: Vaibhav Dalvi vaibhav.dalvi@enterprisedb.com
Discussion: https://www.postgresql.org/message-id/945db7c5-be75-45bf-b55b-cb1e56f2e3e9@dunslane.net

This new SQL-callable function returns the `CREATE SUBSCRIPTION`
statement for a given subscription name.

Like `pg_dump`, the returned DDL explicitly sets `connect = false`.
This is because the original `CONNECT` option value is not cataloged,
and using `connect = false` ensures the DDL can be successfully executed
even if the remote publisher is unreachable.

By default, the function is restricted to superusers.  This is a security
measure because subscription connection strings often contain sensitive
information, such as passwords.  EXECUTE permission can be granted to other
users as needed.

Author: Vaibhav Dalvi <vaibhav.dalvi@enterprisedb.com>
Discussion: https://www.postgresql.org/message-id/945db7c5-be75-45bf-b55b-cb1e56f2e3e9@dunslane.net
@vaibhavdalvi93 vaibhavdalvi93 self-assigned this Oct 3, 2025
@vaibhavdalvi93
Copy link
Owner Author

@alvherre , Could you please review this PR.

Copy link

@akshay-joshi akshay-joshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are 2 new parameters, retain_dead_tuples and max_retention_duration. I am not sure whether we need to add those to the DDL or not.

- use appendStringInfoString()
- use OID > 8000
- Add missed two options
datum = SysCacheGetAttrNotNull(SUBSCRIPTIONOID, tup,
Anum_pg_subscription_subpublications);
publist = textarray_to_stringlist(DatumGetArrayTypeP(datum));
GetPublicationsStr(publist, pubnames, false);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should pubnames be passed by reference?

- Allow users to access this function those have
  pg_create_subscription and pg_read_all_data permission
- Don't omit default value because it may change in future

Author: Vaibhav Dalvi <vaibhav.dalvi@enterprisedb.com>
Reviewed-by: Nishant Sharma,
Reviewed-by: Ian Barwick
Reviewed-by: Akshay Joshi
Reviewed-by: Phil Alger
Discussion: https://www.postgresql.org/message-id/945db7c5-be75-45bf-b55b-cb1e56f2e3e9@dunslane.net
The error ""wal_level" is insufficient to create the
replication slot required by retain_dead_tuples" was
there due to true "retain_dead_tuples".  Set to false.

Vaibhav Dalvi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

Comments