pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
psql profiles?
6+ messages / 4 participants
[nested] [flat]

* psql profiles?
@ 2018-12-06 22:19  Matt Zagrabelny <mzagrabe@d.umn.edu>
  0 siblings, 1 reply; 6+ messages in thread

From: Matt Zagrabelny @ 2018-12-06 22:19 UTC (permalink / raw)
  To: pgsql-general

Greetings,

I'm setting up my workstation to use "gss" for auth to a variety of Pg
systems on different hosts.

I'd rather not have to specify the "-h" for a connection:

psql -h db-host-1.example.com foo

I'd rather do:

psql foo

and have it know that I connect to foo on host db-host-1.example.com.

Is this possible with psql or do I hack together some wrapper script?

Thanks for any input!

-m

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: psql profiles?
@ 2018-12-06 22:23  Alvaro Herrera <alvherre@2ndquadrant.com>
  parent: Matt Zagrabelny <mzagrabe@d.umn.edu>
  0 siblings, 1 reply; 6+ messages in thread

From: Alvaro Herrera @ 2018-12-06 22:23 UTC (permalink / raw)
  To: Matt Zagrabelny <mzagrabe@d.umn.edu>; +Cc: pgsql-general

On 2018-Dec-06, Matt Zagrabelny wrote:

> I'd rather do:
> 
> psql foo
> 
> and have it know that I connect to foo on host db-host-1.example.com.
> 
> Is this possible with psql or do I hack together some wrapper script?

Sure, just define a pg_service.conf file.
https://www.postgresql.org/docs/11/libpq-pgservice.html

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




^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: psql profiles?
@ 2018-12-06 22:34  Matt Zagrabelny <mzagrabe@d.umn.edu>
  parent: Alvaro Herrera <alvherre@2ndquadrant.com>
  0 siblings, 1 reply; 6+ messages in thread

From: Matt Zagrabelny @ 2018-12-06 22:34 UTC (permalink / raw)
  To: alvherre@2ndquadrant.com; +Cc: pgsql-general

On Thu, Dec 6, 2018 at 4:24 PM Alvaro Herrera <alvherre@2ndquadrant.com>
wrote:

> On 2018-Dec-06, Matt Zagrabelny wrote:
>
> > I'd rather do:
> >
> > psql foo
> >
> > and have it know that I connect to foo on host db-host-1.example.com.
> >
> > Is this possible with psql or do I hack together some wrapper script?
>
> Sure, just define a pg_service.conf file.
> https://www.postgresql.org/docs/11/libpq-pgservice.html


Thanks Alvaro!

Is there any shorter version than:

psql "service=foo"

?

If not, I can make a shell alias that puts the "service=$@" into the
command.

Thanks again!

-m

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: psql profiles?
@ 2018-12-07 13:41  Arthur Zakirov <a.zakirov@postgrespro.ru>
  parent: Matt Zagrabelny <mzagrabe@d.umn.edu>
  0 siblings, 1 reply; 6+ messages in thread

From: Arthur Zakirov @ 2018-12-07 13:41 UTC (permalink / raw)
  To: Matt Zagrabelny <mzagrabe@d.umn.edu>; alvherre@2ndquadrant.com; +Cc: pgsql-general

On 07.12.2018 01:34, Matt Zagrabelny wrote:
> 
> 
> On Thu, Dec 6, 2018 at 4:24 PM Alvaro Herrera <alvherre@2ndquadrant.com 
> <mailto:alvherre@2ndquadrant.com>> wrote:
> 
>     Sure, just define a pg_service.conf file.
>     https://www.postgresql.org/docs/11/libpq-pgservice.html
> 
> 
> Thanks Alvaro!
> 
> Is there any shorter version than:
> 
> psql "service=foo"
> 
> ?
> 
> If not, I can make a shell alias that puts the "service=$@" into the 
> command.

Also you can set environment variable PGSERVICE=foo in your .bashrc. Or 
you can just set variable PGHOST=db-host-1.example.com. In last case you 
don't need pg_service.conf file.

-- 
Arthur Zakirov
Postgres Professional: http://www.postgrespro.com
Russian Postgres Company




^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: psql profiles?
@ 2018-12-07 16:45  Matt Zagrabelny <mzagrabe@d.umn.edu>
  parent: Arthur Zakirov <a.zakirov@postgrespro.ru>
  0 siblings, 1 reply; 6+ messages in thread

From: Matt Zagrabelny @ 2018-12-07 16:45 UTC (permalink / raw)
  To: a.zakirov@postgrespro.ru; +Cc: alvherre@2ndquadrant.com; pgsql-general

On Fri, Dec 7, 2018 at 7:42 AM Arthur Zakirov <a.zakirov@postgrespro.ru>
wrote:

> On 07.12.2018 01:34, Matt Zagrabelny wrote:
> >
> >
> > On Thu, Dec 6, 2018 at 4:24 PM Alvaro Herrera <alvherre@2ndquadrant.com
> > <mailto:alvherre@2ndquadrant.com>> wrote:
> >
> >     Sure, just define a pg_service.conf file.
> >     https://www.postgresql.org/docs/11/libpq-pgservice.html
> >
> >
> > Thanks Alvaro!
> >
> > Is there any shorter version than:
> >
> > psql "service=foo"
> >
> > ?
> >
> > If not, I can make a shell alias that puts the "service=$@" into the
> > command.
>
>
>
Thanks for the hints and discussion about this.

Here's my final implementation for the curious and to close the loop:

# a zsh function to avoid having to type "service="

$ which pssql
pssql () {
        psql "service=$@"
}

# and a zsh completion function:

$ cat ~/.fpath/_pssql
#compdef pssql

PG_SERVICES_CONF=~/.pg_service.conf

if [[ -r ${PG_SERVICES_CONF} ]]; then
    compadd $(sed -nE 's/^ *\[(.*)\] *$/\1/p' ${PG_SERVICES_CONF})
fi

 It works like a charm!

Thanks for all the help!

-m

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: psql profiles?
@ 2018-12-07 17:14  Ron <ronljohnsonjr@gmail.com>
  parent: Matt Zagrabelny <mzagrabe@d.umn.edu>
  0 siblings, 0 replies; 6+ messages in thread

From: Ron @ 2018-12-07 17:14 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

On 12/07/2018 10:45 AM, Matt Zagrabelny wrote:
>
> On Fri, Dec 7, 2018 at 7:42 AM Arthur Zakirov <a.zakirov@postgrespro.ru 
> <mailto:a.zakirov@postgrespro.ru>> wrote:
>
>     On 07.12.2018 01:34, Matt Zagrabelny wrote:
>     >
>     >
>     > On Thu, Dec 6, 2018 at 4:24 PM Alvaro Herrera
>     <alvherre@2ndquadrant.com <mailto:alvherre@2ndquadrant.com>
>     > <mailto:alvherre@2ndquadrant.com <mailto:alvherre@2ndquadrant.com>>>
>     wrote:
>     >
>     >     Sure, just define a pg_service.conf file.
>     > https://www.postgresql.org/docs/11/libpq-pgservice.html
>     >
>     >
>     > Thanks Alvaro!
>     >
>     > Is there any shorter version than:
>     >
>     > psql "service=foo"
>     >
>     > ?
>     >
>     > If not, I can make a shell alias that puts the "service=$@" into the
>     > command.
>
>
>
> Thanks for the hints and discussion about this.
>
> Here's my final implementation for the curious and to close the loop:
>
> # a zsh function to avoid having to type "service="
>
> $ which pssql
> pssql () {
>         psql "service=$@"
> }
>
> # and a zsh completion function:
>
> $ cat ~/.fpath/_pssql
> #compdef pssql
>
> PG_SERVICES_CONF=~/.pg_service.conf
>
> if [[ -r ${PG_SERVICES_CONF} ]]; then
>     compadd $(sed -nE 's/^ *\[(.*)\] *$/\1/p' ${PG_SERVICES_CONF})
> fi
>
>  It works like a charm!

I made bash functions to do something similar, with just hardcoded server 
names.  It has auto-complete and allows me to use descriptive names instead 
of server names and custom postgres versions.

-- 
Angular momentum makes the world go 'round.

^ permalink  raw  reply  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2018-12-07 17:14 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-12-06 22:19 psql profiles? Matt Zagrabelny <mzagrabe@d.umn.edu>
2018-12-06 22:23 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2018-12-06 22:34   ` Matt Zagrabelny <mzagrabe@d.umn.edu>
2018-12-07 13:41     ` Arthur Zakirov <a.zakirov@postgrespro.ru>
2018-12-07 16:45       ` Matt Zagrabelny <mzagrabe@d.umn.edu>
2018-12-07 17:14         ` Ron <ronljohnsonjr@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox