Re: [19] CREATE SUBSCRIPTION ... SERVER

Masahiko Sawada <sawada.mshk@gmail.com>

From: Masahiko Sawada <sawada.mshk@gmail.com>
To: Jeff Davis <pgsql@j-davis.com>
Cc: Shlok Kyal <shlok.kyal.oss@gmail.com>, Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>, Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>, Joe Conway <mail@joeconway.com>, pgsql-hackers@postgresql.org
Date: 2026-02-04T04:53:20Z
Lists: pgsql-hackers
On Sat, Jan 10, 2026 at 8:55 PM Jeff Davis <pgsql@j-davis.com> wrote:
>
> On Fri, 2025-12-26 at 13:52 -0800, Jeff Davis wrote:
> > On Wed, 2025-04-02 at 17:58 +0530, Shlok Kyal wrote:
> > > I reviewed the patch and I have a comment:
> > >
> > > If version is >=18, the query will have 'suboriginremotelsn',
> > > 'subenabled', 'subfailover' twice.
> >
> > Thank you. Fixed and rebased.
>
> Attached new version with significant changes:
>
>   - fixed several issues (including some improper merges in the last
> rebase)
>   - refactored to share code between postgres_fdw_connection() and
> connect_pg_server()
>   - added docs in postgres_fdw
>   - added tests in core
>   - bumped postgres_fdw version to 1.3
>

I've reviewed the latest patch set. I understand the motivation behind
this proposal and find it useful. Here are some comments:

@@ -5580,6 +5580,8 @@ fdw_option:
            | NO HANDLER                        { $$ =
makeDefElem("handler", NULL, @1); }
            | VALIDATOR handler_name            { $$ =
makeDefElem("validator", (Node *) $2, @1); }
            | NO VALIDATOR                      { $$ =
makeDefElem("validator", NULL, @1); }
+           | CONNECTION handler_name           { $$ =
makeDefElem("connection", (Node *) $2, @1); }
+           | NO CONNECTION                     { $$ =
makeDefElem("connection", NULL, @1); }
        ;

The documentation for ALTER FOREIGN DATA WRAPPER needs to be updated.

---
The security section[1] of logical replication chapter would also need
to be updated. Currently we have:

To create a subscription, the user must have the privileges of the
pg_create_subscription role, as well as CREATE privileges on the
database.

IIUC if the user uses the SERVER clause, they must have the USAGE
privilege on the foreign server too.

---
We might want to mention in the documentation of CREATE SERVER[2] that
a foreign server's name can be used to connect publication in CREATE
SUBSCRIPTION as we have a similar description for dblink_connect():

When using the dblink module, a foreign server's name can be used as
an argument of the dblink_connect function to indicate the connection
parameters. It is necessary to have the USAGE privilege on the foreign
server to be able to use it in this way.

---
dblink_connect() function can retrieve the connection string from a
foreign server specified in the second argument, which is a very
similar use case to CREATE SUBSCRIPTION. Should we make dblink use the
new function ForeignServerConnectionString() to get the connection
string (in get_connect_string())?

---
It would be better to enhance psql's \dRs command to show the server
name specified in the subscription.

Regards,

[1] https://www.postgresql.org/docs/devel/logical-replication-security.html
[2] https://www.postgresql.org/docs/devel/sql-createserver.html

--
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com



Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Document new catalog columns, missed in commit 8185bb5347.

  2. Refactor to remove ForeignServerName().

  3. GetSubscription(): use per-object memory context.

  4. Fix dependency on FDW's connection function.

  5. ALTER SUBSCRIPTION ... SERVER test.

  6. Fix pg_dump for CREATE FOREIGN DATA WRAPPER ... CONNECTION.

  7. Clean up postgres_fdw/t/010_subscription.pl.

  8. CREATE SUBSCRIPTION ... SERVER.

  9. Allow upgrades to preserve the full subscription's state.