connect by service name in psql

Started by Stuart McGrawover 18 years ago4 messagesgeneral
Jump to latest
#1Stuart McGraw
smcg2297@frii.com

I can't find an option in psql to connect to a database
by "service" name? Should there be one?

#2Stuart McGraw
smcg2297@frii.com
In reply to: Stuart McGraw (#1)
Re: connect by service name in psql

"Stuart" wrote in message news:fanpne$n01$1@sea.gmane.org:

I can't find an option in psql to connect to a database
by "service" name? Should there be one?

Sorry for folowing up my own post but since I got asked in
email, and since I wrote code to do essentially the same thing
before noticing it in the PG docs...

By "service" I am refering to the pg_service.conf file described in
http://www.postgresql.org/docs/8.2/interactive/libpq-connect.html
(see the "service" parameter) and
http://www.postgresql.org/docs/8.2/interactive/libpq-pgservice.html

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Stuart McGraw (#2)
Re: connect by service name in psql

"Stuart" <smcg2297@frii.com> writes:

I can't find an option in psql to connect to a database
by "service" name? Should there be one?

In 8.3 libpq will have code that interprets what's usually the database
name parameter as a "conninfo" string if there's an "=" in it, which
means you can get at the service name as well as a lot of other arcane
options even if the calling application (such as psql) doesn't know they
exist.

For instance,

$ psql "service = foo"
psql: ERROR: service file "/home/postgres/version83/etc/pg_service.conf" not found

(I didn't actually bother to make a service file, but you can see that
the code knew what it was supposed to do.)

I suppose this is more awkward than something like "psql -S foo", but
we're unlikely to want to keep putting connection-related switches into
psql and all the other client apps ...

regards, tom lane

#4Stuart McGraw
smcg2297@frii.com
In reply to: Stuart McGraw (#1)
Re: connect by service name in psql

"Tom Lane" wrote in message news:26413.1188010872@sss.pgh.pa.us:

"Stuart" <smcg2297@frii.com> writes:

I can't find an option in psql to connect to a database
by "service" name? Should there be one?

In 8.3 libpq will have code that interprets what's usually the database
name parameter as a "conninfo" string if there's an "=" in it, [...]

Thank you, that's good news!