Thread: PG FDW query fails, works local, same credentials

PG FDW query fails, works local, same credentials

From
"Pete O'Such"
Date:
I've got a view on server A (PG 15.2) that fails when queried via FDW from server B (also PG 15.2).  Querying it as a foreign table from server B yields a message like "ERROR:  function blah(type) does not exist".

Confusingly, I succeed when: I log into server A, set my role to match the role used with the FDW, and query with the exact query text that server B sent to server A (according to the error on server B).

The function that it complains about does exist, and I have made the effort to provide appropriate grants to the role in question.  So it does work as expected from within server A, as the same role. But why would it then fail from server B?

Both cases use the same role/credentials.  Plenty of other foreign tables work in this same setup between these two servers, whether pointing to tables or views.  I hit and resolved similar issues earlier where the role lacked necessary grants.  Having experienced it before, this time I'm pretty sure that the right grants are in place, yet it still fails when used via FDW.

I'm running out of things to try and wondering if this will turn out to be a bug.  What should I be trying before reporting it as a bug?

Thanks,
Pete

Re: PG FDW query fails, works local, same credentials

From
Tom Lane
Date:
"Pete O'Such" <posuch@gmail.com> writes:
> I've got a view on server A (PG 15.2) that fails when queried via FDW from
> server B (also PG 15.2).  Querying it as a foreign table from server B
> yields a message like "ERROR:  function blah(type) does not exist".

Check your search path assumptions.  postgres_fdw runs remote queries
with a very minimal search_path setting, so that unqualified references
to non-built-in objects are likely to fail.

            regards, tom lane



Re: PG FDW query fails, works local, same credentials

From
"Pete O'Such"
Date:
> Check your search path assumptions.  postgres_fdw runs remote
> queries with a very minimal search_path setting,

Indeed it was the search path, combined with references to user-defined functions that weren't schema-qualified.

Thank you for the pointer!

-Pete

On Thu, Aug 31, 2023 at 12:46 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
"Pete O'Such" <posuch@gmail.com> writes:
> I've got a view on server A (PG 15.2) that fails when queried via FDW from
> server B (also PG 15.2).  Querying it as a foreign table from server B
> yields a message like "ERROR:  function blah(type) does not exist".

Check your search path assumptions.  postgres_fdw runs remote queries
with a very minimal search_path setting, so that unqualified references
to non-built-in objects are likely to fail.

                        regards, tom lane