Thread: Re: [NOVICE] Re: using LDAP for connection information lookup to doremote database connection

Hi Alb,Is there a way to give a username and passwd at the connection time? Another word, not to set the username in
gp_server.conffile.  Because psql just used my OS login id as username When I remove the username from pg_server.conf
file.


Garry

On 9/19/17, 11:35 AM, "pgsql-novice-owner@postgresql.org on behalf of Garry Chen" <pgsql-novice-owner@postgresql.org on
behalfof gc92@cornell.edu> wrote:
 
   HI Albe,       Thank you very much, It is working now after few modifications on pg_service file.      Garry      On
9/19/17,11:04 AM, "Albe Laurenz" <laurenz.albe@wien.gv.at> wrote:          Garry Chen wrote:       > Is it passable to
useLDAP for connection string lookup when try to       > connect to remote database using psql?  I have client install
onmy work station and my       > LDAP entry for remote postgresql database looks like this:       >        >
cn=pgrls,cn=OracleContext      > cn=pgrls       > objectclass=orclDBServer       > objectclass=top       >
objectclass=orclService      > description=host=pgrls.cy53k5nd.us-east-1.rds.amazonaws.com       >
description=port=5439      > description=dbname=pgrls       >        > And my .pg_service.conf       >
ldap://oid.ldap.cornell.edu:389:636/cn=OracleContext?description?one?(cn=pgrls)             You know that there has to
bemore than one line in the file?              There is a complete example of a stanza at the bottom of
https://www.postgresql.org/docs/current/static/libpq-ldap.html             In particular, the stanza has to begin with
aline in brackets, like       [mydatabase]              Other than that, the LDAP URL looks fine.              > When
   > > psql pgrls       > psql: could not connect to server: No such file or directory       >                 Is the
serverrunning locally and accepting       >                 connections on Unix domain socket
"/var/run/postgresql/.s.PGSQL.5432"?      >        > Can anyone guide me through how to?              You'd have to
callit like this:              psql "service=mydatabase"              (Assuming that you named the service control file
stanza"mydatabase".)              Yours,       Laurenz Albe                --    Sent via pgsql-novice mailing list
(pgsql-novice@postgresql.org)  To make changes to your subscription:   http://www.postgresql.org/mailpref/pgsql-novice

 


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

Garry Chen wrote:
> 
> Hi Alb,
>     Is there a way to give a username and passwd at the connection time? Another word, not to set the username in
gp_server.conffile.  Because psql just used my OS login id as username When I remove the username from pg_server.conf
file.

Hi Garr,

You can use the PGUSER environment variable to set the username, and a
.pgpass file (or another file pointed to by the PGPASSFILE environment
variable) to give a password.

-- 
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


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

Hmm the PGUSER is not working:

(GC92@gmc013:/users/gc92)
> PGUSER=dmtools
(GC92@gmc013:/users/gc92)
> psql "service=pgrls"
Password: 
psql: FATAL:  password authentication failed for user "gc92"
FATAL:  password authentication failed for user "gc92"
(GC92@gmc013:/users/gc92)
> echo $PGUSER
dmtools
(GC92@gmc013:/users/gc92)

On 9/20/17, 11:43 AM, "Alvaro Herrera" <alvherre@alvh.no-ip.org> wrote:
   Garry Chen wrote:   >    > Hi Alb,   >     Is there a way to give a username and passwd at the connection time?
Anotherword, not to set the username in gp_server.conf file.  Because psql just used my OS login id as username When I
removethe username from pg_server.conf file.      Hi Garr,      You can use the PGUSER environment variable to set the
username,and a   .pgpass file (or another file pointed to by the PGPASSFILE environment   variable) to give a password.
    --    Álvaro Herrera                https://www.2ndQuadrant.com/   PostgreSQL Development, 24x7 Support, Remote
DBA,Training & Services   
 


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

Garry Chen wrote:
> Hmm the PGUSER is not working:
> 
> (GC92@gmc013:/users/gc92)
> > PGUSER=dmtools

Well, you need to "export" it (examples assume Bourne shell, but maybe
yours is tcsh or something different, so YMMV).  Either

PGUSER=dmtools
export PGUSER
psql "service=.."

or

export PGUSER=dmtools
psql "service=..."

or

PGUSER=dmtools psql "service="..."

-- 
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


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

Alvaro,
It is not working.

(GC92@gmc013:/users/gc92)
> PGUSER=dmtools
(GC92@gmc013:/users/gc92)
> export PGUSER
(GC92@gmc013:/users/gc92)
> psql "service=pgrls"               
Password: 
psql: FATAL:  password authentication failed for user "gc92"
FATAL:  password authentication failed for user "gc92"
(GC92@gmc013:/users/gc92)
> psql --version
psql (PostgreSQL) 9.6.5


Garry

On 9/20/17, 12:50 PM, "Alvaro Herrera" <alvherre@alvh.no-ip.org> wrote:
   Garry Chen wrote:   > Hmm the PGUSER is not working:   >    > (GC92@gmc013:/users/gc92)   > > PGUSER=dmtools
Well,you need to "export" it (examples assume Bourne shell, but maybe   yours is tcsh or something different, so YMMV).
Either      PGUSER=dmtools   export PGUSER   psql "service=.."      or      export PGUSER=dmtools   psql "service=..."
   or      PGUSER=dmtools psql "service="..."      --    Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQLDevelopment, 24x7 Support, Remote DBA, Training & Services   
 


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

Garry Chen wrote:
> Is there a way to give a username and passwd at the connection time? Another word,
> not to set the username in gp_server.conf file.  Because psql just used my OS login id as
> username When I remove the username from pg_server.conf file.

Sure. Try something like:

$ psql "service=mydatabase user=mydbuser password=topsecret"

Yours,
Laurenz Albe

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

I got it to work now.  Thank you very much,

Garry

On 9/22/17, 3:38 AM, "Albe Laurenz" <laurenz.albe@wien.gv.at> wrote:
   Garry Chen wrote:   > Is there a way to give a username and passwd at the connection time? Another word,   > not to
setthe username in gp_server.conf file.  Because psql just used my OS login id as   > username When I remove the
usernamefrom pg_server.conf file.      Sure. Try something like:      $ psql "service=mydatabase user=mydbuser
password=topsecret"     Yours,   Laurenz Albe   
 


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