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...
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.