Re: [17] CREATE SUBSCRIPTION ... SERVER

2024-03-08 Thread Jeff Davis
On Wed, 2024-01-31 at 11:10 +0530, Ashutosh Bapat wrote: > > I like the idea -- it further decouples the logic from the core > > server. > > I suspect it will make postgres_fdw the primary way (though not the > > only possible way) to use this feature. There would be little need > > to > > create

Re: [17] CREATE SUBSCRIPTION ... SERVER

2024-01-30 Thread Ashutosh Bapat
On Wed, Jan 31, 2024 at 2:16 AM Jeff Davis wrote: > > On Tue, 2024-01-30 at 16:17 +0530, Ashutosh Bapat wrote: > > Converting a server and user mapping to > > conninfo should be delegated to the FDW being used since that FDW > > knows best how to use those options. > > If I understand you

Re: [17] CREATE SUBSCRIPTION ... SERVER

2024-01-30 Thread Jeff Davis
On Tue, 2024-01-30 at 16:17 +0530, Ashutosh Bapat wrote: > Converting a server and user mapping to > conninfo should be delegated to the FDW being used since that FDW > knows best how to use those options. If I understand you correctly, you mean that there would be a new optional function

Re: [17] CREATE SUBSCRIPTION ... SERVER

2024-01-30 Thread Ashutosh Bapat
On Wed, Jan 24, 2024 at 7:15 AM Jeff Davis wrote: > > On Tue, 2024-01-23 at 15:21 +0530, Ashutosh Bapat wrote: > > I am with the prefix. The changes it causes make review difficult. If > > you can separate those changes into a patch that will help. > > I ended up just removing the dummy FDW. Real

Re: [17] CREATE SUBSCRIPTION ... SERVER

2024-01-29 Thread Bharath Rupireddy
On Mon, Jan 29, 2024 at 11:11 PM Bharath Rupireddy wrote: > > On Wed, Jan 24, 2024 at 7:15 AM Jeff Davis wrote: > > > > On Tue, 2024-01-23 at 15:21 +0530, Ashutosh Bapat wrote: > > > I am with the prefix. The changes it causes make review difficult. If > > > you can separate those changes into a

Re: [17] CREATE SUBSCRIPTION ... SERVER

2024-01-29 Thread Bharath Rupireddy
On Wed, Jan 24, 2024 at 7:15 AM Jeff Davis wrote: > > On Tue, 2024-01-23 at 15:21 +0530, Ashutosh Bapat wrote: > > I am with the prefix. The changes it causes make review difficult. If > > you can separate those changes into a patch that will help. > > I ended up just removing the dummy FDW. Real

Re: [17] CREATE SUBSCRIPTION ... SERVER

2024-01-23 Thread Ashutosh Bapat
On Tue, Jan 23, 2024 at 12:33 AM Jeff Davis wrote: > > On Mon, 2024-01-22 at 18:41 +0530, Ashutosh Bapat wrote: > > 0002 adds a prefix "regress_" to almost every object that is created > > in foreign_data.sql. > > psql \dew outputs the owner, which in the case of a built-in FDW is the > bootstrap

Re: [17] CREATE SUBSCRIPTION ... SERVER

2024-01-22 Thread Jeff Davis
On Mon, 2024-01-22 at 18:41 +0530, Ashutosh Bapat wrote: > 0002 adds a prefix "regress_" to almost every object that is created > in foreign_data.sql. psql \dew outputs the owner, which in the case of a built-in FDW is the bootstrap superuser, which is not a stable name. I used the prefix to

Re: [17] CREATE SUBSCRIPTION ... SERVER

2024-01-22 Thread Ashutosh Bapat
Hi Jeff, On Tue, Jan 16, 2024 at 7:25 AM Jeff Davis wrote: > > On Fri, 2024-01-12 at 17:17 -0800, Jeff Davis wrote: > > I think 0004 needs a bit more work, so I'm leaving it off for now, > > but > > I'll bring it back in the next patch set. > > Here's the next patch set. 0001 - 0003 are mostly

Re: [17] CREATE SUBSCRIPTION ... SERVER

2024-01-17 Thread Jeff Davis
On Tue, 2024-01-16 at 09:23 +0530, Bharath Rupireddy wrote: > 1. > May be a more descriptive note is > worth here instead of just saying "Load the library providing us > libpq calls."? OK, will be in the next patch set. > 2. Why not typedef keyword before the ConnectionOption structure?

Re: [17] CREATE SUBSCRIPTION ... SERVER

2024-01-15 Thread Bharath Rupireddy
On Tue, Jan 16, 2024 at 7:25 AM Jeff Davis wrote: > > On Fri, 2024-01-12 at 17:17 -0800, Jeff Davis wrote: > > I think 0004 needs a bit more work, so I'm leaving it off for now, > > but > > I'll bring it back in the next patch set. > > Here's the next patch set. 0001 - 0003 are mostly the same

Re: [17] CREATE SUBSCRIPTION ... SERVER

2024-01-15 Thread Jeff Davis
On Mon, 2024-01-15 at 15:53 -0500, Joe Conway wrote: > I took a quick scan through the patch. The only thing that jumped out > at > me was that it seems like it might make sense to use > quote_literal_cstr() rather than defining your own > appendEscapedValue() > function? The rules are

Re: [17] CREATE SUBSCRIPTION ... SERVER

2024-01-15 Thread Joe Conway
On 1/12/24 20:17, Jeff Davis wrote: On Fri, 2024-01-05 at 16:11 +0530, Ashutosh Bapat wrote: I don't think we need to add a test for every FDW. E.g. adding a test in file_fdw would be pointless. But postgres_fdw is special. The test could further create a foreign table ftab_foo on subscriber

Re: [17] CREATE SUBSCRIPTION ... SERVER

2024-01-05 Thread Ashutosh Bapat
On Fri, Jan 5, 2024 at 1:34 PM Jeff Davis wrote: > > On Fri, 2024-01-05 at 12:49 +0530, Ashutosh Bapat wrote: > > Can you please provide an example using postgres_fdw to create a > > subscription using this patch. I think we should document it in > > postgres_fdw and add a test for the same. > >

Re: [17] CREATE SUBSCRIPTION ... SERVER

2024-01-05 Thread Jeff Davis
On Fri, 2024-01-05 at 12:49 +0530, Ashutosh Bapat wrote: > Can you please provide an example using postgres_fdw to create a > subscription using this patch. I think we should document it in > postgres_fdw and add a test for the same. There's a basic test for postgres_fdw in patch 0003, just

Re: [17] CREATE SUBSCRIPTION ... SERVER

2024-01-04 Thread Ashutosh Bapat
On Fri, Jan 5, 2024 at 6:26 AM Jeff Davis wrote: > > > 2. Can one use {FDW, user_mapping, foreign_server} combo other than > > the built-in pg_connection_fdw? > > Yes, you can use any FDW for which you have USAGE privileges, passes > the validations, and provides enough of the expected fields to

Re: [17] CREATE SUBSCRIPTION ... SERVER

2024-01-02 Thread Bharath Rupireddy
On Mon, Jan 1, 2024 at 12:29 AM Jeff Davis wrote: > > On Fri, 2023-12-29 at 15:22 -0800, Jeff Davis wrote: > > On Tue, 2023-09-05 at 12:08 -0700, Jeff Davis wrote: > > > OK, so we could have a built-in FDW called pg_connection that would > > > do > > > the right kinds of validation; and then also

Re: [17] CREATE SUBSCRIPTION ... SERVER

2023-12-31 Thread Jeff Davis
On Fri, 2023-12-29 at 15:22 -0800, Jeff Davis wrote: > On Tue, 2023-09-05 at 12:08 -0700, Jeff Davis wrote: > > OK, so we could have a built-in FDW called pg_connection that would > > do > > the right kinds of validation; and then also allow other FDWs but > > the > > subscription would have to do

Re: [17] CREATE SUBSCRIPTION ... SERVER

2023-12-29 Thread Jeff Davis
On Tue, 2023-09-05 at 12:08 -0700, Jeff Davis wrote: > OK, so we could have a built-in FDW called pg_connection that would > do > the right kinds of validation; and then also allow other FDWs but the > subscription would have to do its own validation. Attached a rough rebased version implementing

Re: [17] CREATE SUBSCRIPTION ... SERVER

2023-09-12 Thread Jeff Davis
On Tue, 2023-09-05 at 12:08 -0700, Jeff Davis wrote: > OK, so we could have a built-in FDW called pg_connection that would > do > the right kinds of validation; and then also allow other FDWs but the > subscription would have to do its own validation. While working on this, I found a minor bug

Re: [17] CREATE SUBSCRIPTION ... SERVER

2023-09-05 Thread Jeff Davis
On Mon, 2023-09-04 at 18:01 +0530, Ashutosh Bapat wrote: > Why do we need to re-check parameters constantly? We will need to > restart subscriptions which are using the user mapping of FDW when > user mapping or server options change. "Constantly" was an exaggeration, but the point is that it's a

Re: [17] CREATE SUBSCRIPTION ... SERVER

2023-09-04 Thread Ashutosh Bapat
On Sat, Sep 2, 2023 at 1:41 AM Robert Haas wrote: > > On Fri, Sep 1, 2023 at 4:04 PM Jeff Davis wrote: > > On Thu, 2023-08-31 at 17:17 -0400, Joe Conway wrote: > > > Maybe move postgres_fdw to be a first class built in feature instead > > > of > > > an extension? > > > > That could make sense,

Re: [17] CREATE SUBSCRIPTION ... SERVER

2023-09-04 Thread Ashutosh Bapat
On Sat, Sep 2, 2023 at 12:24 AM Jeff Davis wrote: > > On Fri, 2023-09-01 at 12:28 +0530, Ashutosh Bapat wrote: > > Thinking larger, how about we allow any FDW to be used here. > > That's a possibility, but I think that means the subscription would > need to constantly re-check the parameters

Re: [17] CREATE SUBSCRIPTION ... SERVER

2023-09-01 Thread Robert Haas
On Fri, Sep 1, 2023 at 4:04 PM Jeff Davis wrote: > On Thu, 2023-08-31 at 17:17 -0400, Joe Conway wrote: > > Maybe move postgres_fdw to be a first class built in feature instead > > of > > an extension? > > That could make sense, but we still have to solve the problem of how to > present a

Re: [17] CREATE SUBSCRIPTION ... SERVER

2023-09-01 Thread Jeff Davis
On Thu, 2023-08-31 at 17:17 -0400, Joe Conway wrote: > Maybe move postgres_fdw to be a first class built in feature instead > of > an extension? That could make sense, but we still have to solve the problem of how to present a built-in FDW. FDWs don't have a schema, so it can't be inside

Re: [17] CREATE SUBSCRIPTION ... SERVER

2023-09-01 Thread Jeff Davis
On Fri, 2023-09-01 at 12:28 +0530, Ashutosh Bapat wrote: > Thinking larger, how about we allow any FDW to be used here. That's a possibility, but I think that means the subscription would need to constantly re-check the parameters rather than relying on the FDW's validator. Otherwise it might be

Re: [17] CREATE SUBSCRIPTION ... SERVER

2023-09-01 Thread Ashutosh Bapat
On Fri, Sep 1, 2023 at 2:47 AM Joe Conway wrote: > > On 8/31/23 12:52, Jeff Davis wrote: > > On Thu, 2023-08-31 at 10:59 +0530, Ashutosh Bapat wrote: > >> The server's FDW has to be postgres_fdw. So we have to handle the > >> awkward dependency between core and postgres_fdw (an extension). > > >

Re: [17] CREATE SUBSCRIPTION ... SERVER

2023-08-31 Thread Joe Conway
On 8/31/23 12:52, Jeff Davis wrote: On Thu, 2023-08-31 at 10:59 +0530, Ashutosh Bapat wrote: The server's FDW has to be postgres_fdw. So we have to handle the awkward dependency between core and postgres_fdw (an extension). That sounds more than just "awkward". I can't think of any precedent

Re: [17] CREATE SUBSCRIPTION ... SERVER

2023-08-31 Thread Jeff Davis
On Thu, 2023-08-31 at 08:37 -0400, Robert Haas wrote: > What I feel is kind of weird about this syntax is that it seems like > it's entangled with the FDW mechanism but doesn't really overlap with > it. I like the fact that it works with user mappings and benefits from the other thinking that's

Re: [17] CREATE SUBSCRIPTION ... SERVER

2023-08-31 Thread Jeff Davis
On Thu, 2023-08-31 at 10:59 +0530, Ashutosh Bapat wrote: > The server's FDW has to be postgres_fdw. So we have to handle the > awkward dependency between core and postgres_fdw (an extension). That sounds more than just "awkward". I can't think of any precedent for that and it seems to violate the

Re: [17] CREATE SUBSCRIPTION ... SERVER

2023-08-31 Thread Jeff Davis
On Wed, 2023-08-30 at 09:09 -0700, Jeff Davis wrote: > Admittedly, I didn't complete the dummy-FDW approach, so perhaps it > works out better overall. I can give it a try. We need to hide the dummy FDW from pg_dump. And we need to hide it from psql's \dew, because that's used in tests and prints

Re: [17] CREATE SUBSCRIPTION ... SERVER

2023-08-31 Thread Robert Haas
On Wed, Aug 30, 2023 at 1:19 PM Jeff Davis wrote: > On Wed, 2023-08-30 at 09:49 -0400, Tom Lane wrote: > > This seems like it requires a whole lot of new mechanism (parser > > and catalog infrastructure) that could be done far more easily > > in other ways. In particular, how about inventing a

Re: [17] CREATE SUBSCRIPTION ... SERVER

2023-08-30 Thread Ashutosh Bapat
On Wed, Aug 30, 2023 at 9:00 PM Jeff Davis wrote: > > On Wed, 2023-08-30 at 19:11 +0530, Ashutosh Bapat wrote: > > Are you suggesting that SERVERs created with FDW can not be used as > > publishers? > > Correct. Without that, how would the subscription know that the FDW > contains valid postgres

Re: [17] CREATE SUBSCRIPTION ... SERVER

2023-08-30 Thread Jeff Davis
On Wed, 2023-08-30 at 09:49 -0400, Tom Lane wrote: > This seems like it requires a whole lot of new mechanism (parser > and catalog infrastructure) that could be done far more easily > in other ways.  In particular, how about inventing a built-in > dummy FDW to serve the purpose? That was my

Re: [17] CREATE SUBSCRIPTION ... SERVER

2023-08-30 Thread Jeff Davis
On Wed, 2023-08-30 at 19:11 +0530, Ashutosh Bapat wrote: > Are you suggesting that SERVERs created with FDW can not be used as > publishers? Correct. Without that, how would the subscription know that the FDW contains valid postgres connection information? I suppose it could create a connection

Re: [17] CREATE SUBSCRIPTION ... SERVER

2023-08-30 Thread Tom Lane
Jeff Davis writes: > The server "myserver" must have been created with the new syntax: >CREATE SERVER myserver FOR CONNECTION ONLY > instead of specifying FOREIGN DATA WRAPPER. In other words, a server > FOR CONNECTION ONLY doesn't have a real FDW, it's a special server just > used for the

Re: [17] CREATE SUBSCRIPTION ... SERVER

2023-08-30 Thread Ashutosh Bapat
Hi Jeff, On Wed, Aug 30, 2023 at 2:12 PM Jeff Davis wrote: > > The server "myserver" must have been created with the new syntax: > >CREATE SERVER myserver FOR CONNECTION ONLY > > instead of specifying FOREIGN DATA WRAPPER. In other words, a server > FOR CONNECTION ONLY doesn't have a real

[17] CREATE SUBSCRIPTION ... SERVER

2023-08-30 Thread Jeff Davis
Synopsis: Publisher: CREATE TABLE x(i INT); CREATE TABLE y(i INT); INSERT INTO x VALUES(1); INSERT INTO y VALUES(-1); CREATE PUBLICATION pub1 FOR TABLE x; CREATE PUBLICATION pub2 FOR TABLE y; Subscriber: CREATE SERVER myserver FOR CONNECTION ONLY OPTIONS (