Thread: dblink_connect fails

dblink_connect fails

From
James Sewell
Date:
Hey all,

I have a Windows PostgreSQL server where dblink_connect fails to pick up the current user as follows:

#psql -h localhost -U postgres ffm

ffm=# select version();
                           version
-------------------------------------------------------------
 PostgreSQL 9.4.5, compiled by Visual C++ build 1800, 64-bit
(1 row)

ffm=#
ffm=# SELECT dblink_connect('master', 'dbname=ffm');
ERROR:  could not establish connection
DETAIL:  FATAL:  role "PRDSWIDEGRID01$" does not exist

ffm=#
ffm=# select user;
 current_user
--------------
 phxowner
(1 row)

ffm=# select session_user;
 session_user
--------------
 postgres
(1 row)

ffm=# SELECT dblink_connect('master', 'dbname=ffm user=postgres');
 dblink_connect
----------------
 OK
(1 row)

Has anyone seen this before? It seems very odd to me, I have another identical machine (except for being on 9.4.0) which this works on.

Cheers,

James Sewell,
Solutions Architect
______________________________________
 

Level 2, 50 Queen St, Melbourne VIC 3000

(+61) 3 8370 8000  W www.lisasoft.com  (+61) 3 8370 8099
 


The contents of this email are confidential and may be subject to legal or professional privilege and copyright. No representation is made that this email is free of viruses or other defects. If you have received this communication in error, you may not copy or distribute any part of it or otherwise disclose its contents to anyone. Please advise the sender of your incorrect receipt of this correspondence.

Re: dblink_connect fails

From
Joe Conway
Date:
On 12/15/2015 06:24 PM, James Sewell wrote:
> I have a Windows PostgreSQL server where dblink_connect fails to pick up
> the current user as follows:

>     ffm=# SELECT dblink_connect('master', 'dbname=ffm');
>     ERROR:  could not establish connection
>     DETAIL:  FATAL:  role "PRDSWIDEGRID01$" does not exist

> Has anyone seen this before? It seems very odd to me, I have another
> identical machine (except for being on 9.4.0) which this works on.


Do you happen to have a PGUSER variable defined in your environment
(that is, in the environment as seen by the OS user the postmaster runs
under)?

See: http://www.postgresql.org/docs/9.4/static/libpq-envars.html

Joe

--
Crunchy Data - http://crunchydata.com
PostgreSQL Support for Secure Enterprises
Consulting, Training, & Open Source Development


Attachment

Re: dblink_connect fails

From
James Sewell
Date:
No it is not.

Just in case I tried setting it to 'postgres', logged in without -U (doesn't work without PGUSER set) and tried the operation again.

Same result.

Cheers,


James Sewell,
PostgreSQL Team Lead / Solutions Architect
______________________________________
 

Level 2, 50 Queen St, Melbourne VIC 3000

(+61) 3 8370 8000  W www.lisasoft.com  (+61) 3 8370 8099
 

On Wed, Dec 16, 2015 at 3:26 PM, Joe Conway <mail@joeconway.com> wrote:
On 12/15/2015 06:24 PM, James Sewell wrote:
> I have a Windows PostgreSQL server where dblink_connect fails to pick up
> the current user as follows:

>     ffm=# SELECT dblink_connect('master', 'dbname=ffm');
>     ERROR:  could not establish connection
>     DETAIL:  FATAL:  role "PRDSWIDEGRID01$" does not exist

> Has anyone seen this before? It seems very odd to me, I have another
> identical machine (except for being on 9.4.0) which this works on.


Do you happen to have a PGUSER variable defined in your environment
(that is, in the environment as seen by the OS user the postmaster runs
under)?

See: http://www.postgresql.org/docs/9.4/static/libpq-envars.html

Joe

--
Crunchy Data - http://crunchydata.com
PostgreSQL Support for Secure Enterprises
Consulting, Training, & Open Source Development




The contents of this email are confidential and may be subject to legal or professional privilege and copyright. No representation is made that this email is free of viruses or other defects. If you have received this communication in error, you may not copy or distribute any part of it or otherwise disclose its contents to anyone. Please advise the sender of your incorrect receipt of this correspondence.

Re: dblink_connect fails

From
Adrian Klaver
Date:
On 12/16/2015 04:53 PM, James Sewell wrote:
> No it is not.
>
> Just in case I tried setting it to 'postgres', logged in without -U
> (doesn't work without PGUSER set) and tried the operation again.

Do you mean this:

DETAIL:  FATAL:  role "PRDSWIDEGRID01$" does not exist

or that you could not connect for another reason?

If for the original reason, does the role PRDSWIDEGRID01$ actually exist
somewhere?


>
> Same result.
>
> Cheers,
>
>
> James Sewell,
> PostgreSQL Team Lead / Solutions Architect
> ______________________________________
>
> Level 2, 50 Queen St, Melbourne VIC 3000
>
> *P *(+61) 3 8370 8000***W* www.lisasoft.com *F *(+61) 3 8370 8099
>
> On Wed, Dec 16, 2015 at 3:26 PM, Joe Conway <mail@joeconway.com
> <mailto:mail@joeconway.com>> wrote:
>
>     On 12/15/2015 06:24 PM, James Sewell wrote:
>     > I have a Windows PostgreSQL server where dblink_connect fails to pick up
>     > the current user as follows:
>
>     >     ffm=# SELECT dblink_connect('master', 'dbname=ffm');
>     >     ERROR:  could not establish connection
>     >     DETAIL:  FATAL:  role "PRDSWIDEGRID01$" does not exist
>
>     > Has anyone seen this before? It seems very odd to me, I have another
>     > identical machine (except for being on 9.4.0) which this works on.
>
>
>     Do you happen to have a PGUSER variable defined in your environment
>     (that is, in the environment as seen by the OS user the postmaster runs
>     under)?
>
>     See: http://www.postgresql.org/docs/9.4/static/libpq-envars.html
>
>     Joe
>
>     --
>     Crunchy Data - http://crunchydata.com
>     PostgreSQL Support for Secure Enterprises
>     Consulting, Training, & Open Source Development
>
>
>
> ------------------------------------------------------------------------
> The contents of this email are confidential and may be subject to legal
> or professional privilege and copyright. No representation is made that
> this email is free of viruses or other defects. If you have received
> this communication in error, you may not copy or distribute any part of
> it or otherwise disclose its contents to anyone. Please advise the
> sender of your incorrect receipt of this correspondence.
>


--
Adrian Klaver
adrian.klaver@aklaver.com


Re: dblink_connect fails

From
Joe Conway
Date:
On 12/16/2015 04:53 PM, James Sewell wrote:
> No it is not.
>
> Just in case I tried setting it to 'postgres', logged in without -U
> (doesn't work without PGUSER set) and tried the operation again.

>     >     DETAIL:  FATAL:  role "PRDSWIDEGRID01$" does not exist

That "PRDSWIDEGRID01$" is coming from somewhere in your environment.
Looks like it is supposed to be a variable of some sort which is
supposed to resolve to an actual postgres user but for some reason doesn't.

What about FDWs?


--
Crunchy Data - http://crunchydata.com
PostgreSQL Support for Secure Enterprises
Consulting, Training, & Open Source Development


Attachment

Re: dblink_connect fails

From
Melvin Davidson
Date:
Perhaps the attached will help. It's a sample function that I wrote and tested a few years ago on PG v8.3
It worked then, so it should be a good model for you.

On Wed, Dec 16, 2015 at 8:00 PM, Adrian Klaver <adrian.klaver@aklaver.com> wrote:
On 12/16/2015 04:53 PM, James Sewell wrote:
No it is not.

Just in case I tried setting it to 'postgres', logged in without -U
(doesn't work without PGUSER set) and tried the operation again.

Do you mean this:

DETAIL:  FATAL:  role "PRDSWIDEGRID01$" does not exist

or that you could not connect for another reason?

If for the original reason, does the role PRDSWIDEGRID01$ actually exist somewhere?



Same result.

Cheers,


James Sewell,
PostgreSQL Team Lead / Solutions Architect
______________________________________

Level 2, 50 Queen St, Melbourne VIC 3000

*P *(+61) 3 8370 8000***W* www.lisasoft.com *F *(+61) 3 8370 8099

On Wed, Dec 16, 2015 at 3:26 PM, Joe Conway <mail@joeconway.com
<mailto:mail@joeconway.com>> wrote:

    On 12/15/2015 06:24 PM, James Sewell wrote:
    > I have a Windows PostgreSQL server where dblink_connect fails to pick up
    > the current user as follows:

    >     ffm=# SELECT dblink_connect('master', 'dbname=ffm');
    >     ERROR:  could not establish connection
    >     DETAIL:  FATAL:  role "PRDSWIDEGRID01$" does not exist

    > Has anyone seen this before? It seems very odd to me, I have another
    > identical machine (except for being on 9.4.0) which this works on.


    Do you happen to have a PGUSER variable defined in your environment
    (that is, in the environment as seen by the OS user the postmaster runs
    under)?

    See: http://www.postgresql.org/docs/9.4/static/libpq-envars.html

    Joe

    --
    Crunchy Data - http://crunchydata.com
    PostgreSQL Support for Secure Enterprises
    Consulting, Training, & Open Source Development



------------------------------------------------------------------------
The contents of this email are confidential and may be subject to legal
or professional privilege and copyright. No representation is made that
this email is free of viruses or other defects. If you have received
this communication in error, you may not copy or distribute any part of
it or otherwise disclose its contents to anyone. Please advise the
sender of your incorrect receipt of this correspondence.



--
Adrian Klaver
adrian.klaver@aklaver.com


--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



--
Melvin Davidson
I reserve the right to fantasize.  Whether or not you
wish to share my fantasy is entirely up to you.

Attachment

Fwd: dblink_connect fails

From
James Sewell
Date:
Oops left off the list.

---------- Forwarded message ----------
From: James Sewell <james.sewell@lisasoft.com>
Date: Thursday, 17 December 2015
Subject: dblink_connect fails
To: Joe Conway <mail@joeconway.com>


On Thu, Dec 17, 2015 at 12:11 PM, Joe Conway <mail@joeconway.com> wrote:
On 12/16/2015 04:53 PM, James Sewell wrote:
> No it is not.
>
> Just in case I tried setting it to 'postgres', logged in without -U
> (doesn't work without PGUSER set) and tried the operation again.

>     >     DETAIL:  FATAL:  role "PRDSWIDEGRID01$" does not exist

That "PRDSWIDEGRID01$" is coming from somewhere in your environment.
Looks like it is supposed to be a variable of some sort which is
supposed to resolve to an actual postgres user but for some reason doesn't.

What about FDWs?

This is a new database with some tables and dblink loaded.

The  PRDSWIDEGRID01 is actually the hostname - but I just can't see how it's getting injected.

My understanding was that psql -U should override? And also that any user variable just sets the user PostgreSQL variable - which is postgres.

Strange stuff. I've just tried from cygwin, from Windows psql and from PGAdmin - all the same result.


--
Crunchy Data - http://crunchydata.com
PostgreSQL Support for Secure Enterprises
Consulting, Training, & Open Source Development





--

James Sewell,
PostgreSQL Team Lead / Solutions Architect
______________________________________
 

Level 2, 50 Queen St, Melbourne VIC 3000

(+61) 3 8370 8000  W www.lisasoft.com  (+61) 3 8370 8099
 



The contents of this email are confidential and may be subject to legal or professional privilege and copyright. No representation is made that this email is free of viruses or other defects. If you have received this communication in error, you may not copy or distribute any part of it or otherwise disclose its contents to anyone. Please advise the sender of your incorrect receipt of this correspondence.

Re: Fwd: dblink_connect fails

From
Joe Conway
Date:
On 12/16/2015 06:10 PM, James Sewell wrote:
> Oops left off the list.

Me too -- response repeated below...

> ---------- Forwarded message ----------
> From: *James Sewell* <james.sewell@lisasoft.com
> <mailto:james.sewell@lisasoft.com>>
> Date: Thursday, 17 December 2015
> Subject: dblink_connect fails
> To: Joe Conway <mail@joeconway.com <mailto:mail@joeconway.com>>
>
>
> On Thu, Dec 17, 2015 at 12:11 PM, Joe Conway <mail@joeconway.com
> <javascript:_e(%7B%7D,'cvml','mail@joeconway.com');>> wrote:
>
>     On 12/16/2015 04:53 PM, James Sewell wrote:
>     > No it is not.
>     >
>     > Just in case I tried setting it to 'postgres', logged in without -U
>     > (doesn't work without PGUSER set) and tried the operation again.
>
>     >     >     DETAIL:  FATAL:  role "PRDSWIDEGRID01$" does not exist

> This is a new database with some tables and dblink loaded.
>
> The  PRDSWIDEGRID01 is actually the hostname - but I just can't see how
> it's getting injected.
>
> My understanding was that psql -U should override? And also that any
> user variable just sets the user PostgreSQL variable - which is postgres.

Hmmm, well the way you start up psql should be irrelevant here.

What goes on with dblink_connect() is more-or-less completely controlled
by libpq's PQconnectdb(). When you do not provide a user explicitly in
your libpq connect string it defaults to the user that the current
process is running under unless the PGUSER environment variable has been
defined. See:

http://www.postgresql.org/docs/9.4/interactive/libpq-envars.html

    "The following environment variables can be used to select default
     connection parameter values, which will be used by PQconnectdb,
     PQsetdbLogin and PQsetdb if no value is directly specified by the
     calling code.

     PGUSER behaves the same as the user connection parameter."

-and-

http://www.postgresql.org/docs/9.4/interactive/libpq-connect.html#LIBPQ-PARAMKEYWORDS

    "user

        PostgreSQL user name to connect as. Defaults to be the same as
        the operating system name of the user running the application."

So in your case, does your postgres server run as an OS user called
PRDSWIDEGRID01$ for some reason?

Joe



--
Crunchy Data - http://crunchydata.com
PostgreSQL Support for Secure Enterprises
Consulting, Training, & Open Source Development


Attachment

Re: Fwd: dblink_connect fails

From
Adrian Klaver
Date:
On 12/16/2015 06:10 PM, James Sewell wrote:
> Oops left off the list.
>
> ---------- Forwarded message ----------
> From: *James Sewell* <james.sewell@lisasoft.com
> <mailto:james.sewell@lisasoft.com>>
> Date: Thursday, 17 December 2015
> Subject: dblink_connect fails
> To: Joe Conway <mail@joeconway.com <mailto:mail@joeconway.com>>
>
>
> On Thu, Dec 17, 2015 at 12:11 PM, Joe Conway <mail@joeconway.com
> <javascript:_e(%7B%7D,'cvml','mail@joeconway.com');>> wrote:
>
>     On 12/16/2015 04:53 PM, James Sewell wrote:
>     > No it is not.
>     >
>     > Just in case I tried setting it to 'postgres', logged in without -U
>     > (doesn't work without PGUSER set) and tried the operation again.
>
>     >     >     DETAIL:  FATAL:  role "PRDSWIDEGRID01$" does not exist
>
>     That "PRDSWIDEGRID01$" is coming from somewhere in your environment.
>     Looks like it is supposed to be a variable of some sort which is
>     supposed to resolve to an actual postgres user but for some reason
>     doesn't.
>
>     What about FDWs?
>
>
> This is a new database with some tables and dblink loaded.
>
> The  PRDSWIDEGRID01 is actually the hostname - but I just can't see how
> it's getting injected.
>
> My understanding was that psql -U should override? And also that any
> user variable just sets the user PostgreSQL variable - which is postgres.
>
> Strange stuff. I've just tried from cygwin, from Windows psql and from
> PGAdmin - all the same result.

That is all from the client point of view. As Joe Conway has mentioned
you need to be looking from the server point of view. In other words
what is the environment for the Postgres server you are running
dblink_connect in?

>
>
>
>     --
>     Crunchy Data - http://crunchydata.com
>     PostgreSQL Support for Secure Enterprises
>     Consulting, Training, & Open Source Development
>
>
>
>
>
> --
>
> James Sewell,
> PostgreSQL Team Lead / Solutions Architect
> ______________________________________
>
> Level 2, 50 Queen St, Melbourne VIC 3000
>
> *P *(+61) 3 8370 8000***W* www.lisasoft.com *F *(+61) 3 8370 8099
>
>
> ------------------------------------------------------------------------
> The contents of this email are confidential and may be subject to legal
> or professional privilege and copyright. No representation is made that
> this email is free of viruses or other defects. If you have received
> this communication in error, you may not copy or distribute any part of
> it or otherwise disclose its contents to anyone. Please advise the
> sender of your incorrect receipt of this correspondence.
>


--
Adrian Klaver
adrian.klaver@aklaver.com


Re: Fwd: dblink_connect fails

From
James Sewell
Date:
Oops forgot to reply back to this one in the Christmas shutdown.

It turned out in this (new) install on Windows Postgres was running as the Network Service user (??).

This was causing the issue, changed to Postgres and I was all good.

Cheers,


James Sewell,
Solutions Architect
______________________________________
 

Level 2, 50 Queen St, Melbourne VIC 3000

(+61) 3 8370 8000  W www.lisasoft.com  (+61) 3 8370 8099
 

On Thu, Dec 17, 2015 at 4:04 PM, Adrian Klaver <adrian.klaver@aklaver.com> wrote:
On 12/16/2015 06:10 PM, James Sewell wrote:
Oops left off the list.

---------- Forwarded message ----------
From: *James Sewell* <james.sewell@lisasoft.com
<mailto:james.sewell@lisasoft.com>>
Date: Thursday, 17 December 2015
Subject: dblink_connect fails
To: Joe Conway <mail@joeconway.com <mailto:mail@joeconway.com>>


On Thu, Dec 17, 2015 at 12:11 PM, Joe Conway <mail@joeconway.com
<javascript:_e(%7B%7D,'cvml','mail@joeconway.com');>> wrote:

    On 12/16/2015 04:53 PM, James Sewell wrote:
    > No it is not.
    >
    > Just in case I tried setting it to 'postgres', logged in without -U
    > (doesn't work without PGUSER set) and tried the operation again.

    >     >     DETAIL:  FATAL:  role "PRDSWIDEGRID01$" does not exist

    That "PRDSWIDEGRID01$" is coming from somewhere in your environment.
    Looks like it is supposed to be a variable of some sort which is
    supposed to resolve to an actual postgres user but for some reason
    doesn't.

    What about FDWs?


This is a new database with some tables and dblink loaded.

The  PRDSWIDEGRID01 is actually the hostname - but I just can't see how
it's getting injected.

My understanding was that psql -U should override? And also that any
user variable just sets the user PostgreSQL variable - which is postgres.

Strange stuff. I've just tried from cygwin, from Windows psql and from
PGAdmin - all the same result.

That is all from the client point of view. As Joe Conway has mentioned you need to be looking from the server point of view. In other words what is the environment for the Postgres server you are running dblink_connect in?




    --
    Crunchy Data - http://crunchydata.com
    PostgreSQL Support for Secure Enterprises
    Consulting, Training, & Open Source Development





--

James Sewell,
PostgreSQL Team Lead / Solutions Architect
______________________________________

Level 2, 50 Queen St, Melbourne VIC 3000

*P *(+61) 3 8370 8000***W* www.lisasoft.com *F *(+61) 3 8370 8099


------------------------------------------------------------------------
The contents of this email are confidential and may be subject to legal
or professional privilege and copyright. No representation is made that
this email is free of viruses or other defects. If you have received
this communication in error, you may not copy or distribute any part of
it or otherwise disclose its contents to anyone. Please advise the
sender of your incorrect receipt of this correspondence.



--
Adrian Klaver
adrian.klaver@aklaver.com



The contents of this email are confidential and may be subject to legal or professional privilege and copyright. No representation is made that this email is free of viruses or other defects. If you have received this communication in error, you may not copy or distribute any part of it or otherwise disclose its contents to anyone. Please advise the sender of your incorrect receipt of this correspondence.