Re: Confusion between psql options and pg_service file config

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: rsindlin(at)gmail(dot)com, pgsql-docs(at)lists(dot)postgresql(dot)org
Subject: Re: Confusion between psql options and pg_service file config
Date: 2023-03-28 21:52:19
Message-ID: CAKFQuwajUR5c47JrcCFZagG2FeK0yZ_b4+jXMDY_Tikppd5CRg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

On Tue, Mar 28, 2023 at 1:30 PM PG Doc comments form <noreply(at)postgresql(dot)org>
wrote:

> The following documentation comment has been logged on the website:
>
> Page: https://www.postgresql.org/docs/15/libpq-connect.html
> Description:
>
I feel like I'm going in circles trying to square `psql` options (15: psql)
> with connection service file parameters (15: 34.17). I've lost exactly
> which page I started on, but it was something like this...
>
> - I start at https://www.postgresql.org/docs/15/app-psql.html
> - Under "Options"
> -c _command_ shows that I can run an arbitrary command on connection.
> Great!
>
> - But I'd like to specify something similar in the pg_service file, so I
> look up I look up the Connection Service File, section 34.17 -
> https://www.postgresql.org/docs/15/libpq-pgservice.html

That isn't going to work. You use the startup script, PSQLRC, if you want
to perform some actions after the connection is established.

>
> - So far, so good. The "parameters are connection parameters; see
> [Section
> 34.1.2](
> https://www.postgresql.org/docs/15/libpq-connect.html#LIBPQ-PARAMKEYWORDS)
> for a list."
> - Following that link, I scroll down to the key word "options" which
> "Specifies command line options" presumably like those for psql.

This is an incorrect assumption. The command line options are precisely
those that the server recognizes since the point of this feature is to
configure the initially established session. In effect it is an
alternative to the "SET" SQL Command.

> What I have found particularly confusing is some of the keywords for the
> pg_service file clearly duplicate the options for `psql` but some of them
> are equivalent, but not identical keywords (eg, `psql --username` vs
> pg_service.conf keyword 'user'). Are both valid, or are they restricted to
> their respective realm? (That's a question I'm asking the documentation to
> answer, not a question I'm directly asking you.)
>

You should assume that options described within a specific context are only
valid (or the only valid spelling) in said context.

>
> There is also no particularly clear connection between psql options and the
> connection service file; it's even hard to find where the app-psql.html
> page
> indicates that using a service name in conjunction with a connection
> service
> file can make invoking psql so much easier :- )
>
> Additionally, since the concepts are so similar to each other,

I suppose, but the pg_service.conf file is a fairly small subset of the
things that psql has to deal with. For the overlapping subset I do agree
there is great value in using the options defined in the pg_service.conf
file and then tell psql to use the named service instead of environment
variables or command line options. But psql can do so much more, none of
which is related to establishing the initial connection to the database.

In short, "-c" has nothing to do with making an initial connection to the
database. "-o" is a bit of a hack, and if you use a connection pooler (at
least pg_bouncer) one that isn't actually supported.

David J.

In response to

Browse pgsql-docs by date

  From Date Subject
Next Message Bruce Momjian 2023-03-29 19:56:00 Re: I think that the transaction tutorial document (3.4) should mention transaction isolation
Previous Message Tom Lane 2023-03-28 20:45:53 Re: Minor typo in 13.3.5. Advisory Locks