Thread: Confusion between psql options and pg_service file config
The following documentation comment has been logged on the website: Page: https://www.postgresql.org/docs/15/libpq-connect.html Description: Hi folks, 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 - 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. Then it says "For a detailed discussion of the available options, consult [Chapter 20](https://www.postgresql.org/docs/15/runtime-config.html)." - Suddenly, I don't know why I'm in "Server Configuration" (Chapter 20). Sure, it is a TOC with sections that document options, but mostly only relevant to a superuser. - I thought I'd get a list of options valid as arguments to the 'options' keyword. What am I suddenly doing here? It seems an odd landing point for the link. 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.) 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, and the pages are reasonable long, it's easy to lose track of exactly which piece of documentation I am looking at for which feature. (not an easy problem to solve there, just an additional curveball) Hopefully, I've kept this all objective, and not let any of my frustration spill out; if I did, that certainly wasn't my intention! Thanks for all your work, -Randall
On Tue, Mar 28, 2023 at 1:30 PM PG Doc comments form <noreply@postgresql.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.