Re: [GENERAL] Connection options - Mailing list pgsql-general

From David G. Johnston
Subject Re: [GENERAL] Connection options
Date
Msg-id CAKFQuwZBWTkX0aiEQGRo3Lah0Cb_cxPp2KSWvDVVGOm+GQXD7w@mail.gmail.com
Whole thread Raw
In response to Re: [GENERAL] Connection options  (Igor Korot <ikorot01@gmail.com>)
List pgsql-general
On Thu, Jun 15, 2017 at 2:41 PM, Igor Korot <ikorot01@gmail.com> wrote:

On Thu, Jun 15, 2017 at 4:46 PM, David G. Johnston
<david.g.johnston@gmail.com> wrote:
> On Thu, Jun 15, 2017 at 1:23 PM, Igor Korot <ikorot01@gmail.com> wrote:
>>
>> And could you clarify on the first part of this?
>> From the quote I poste it sounds like this is available only in
>> command-line
>> tools. And if someone will use it inside the program it will be ignored.
>
>
> The options you pass from the client via the "options" attribute are
> interpreted by *the server* as command-line options.  They are not options
> that control libpq itself.

Can you give an example or try to explain it?
What do you mean by "interpreted by the server as command-line options"?

Does this mean I can just ignore this parameter inside my C{++} program?
Or I can set some options and pass it to the server thru this parameter?

​Reading this should help:


Note especially 19.1.4 - Parameter Interaction via the Shell

For example:

postgres -c 'search_path=app,public'

is roughly equivalent to:

psql "options='-c search_path=app,public'"

which can written directly in libpq as (not a C programmer here so I'm going for pseudo code):

keyarray=[options]
valarray=["-c search_path=app,public"]
PQconnectdbParams(keyarray, valarray, 0)

Equivalent in that the session that ends up being started will already have a search_path value of "app,public" (it does depend on where else search_path defaults are setup).

Note that you can get much the same behavior by doing:

$ psql
> SET search_path TO app, public;

In fact, if your are routing your connections through pg_bouncer making use of "options" (-c search_path=app,public) won't work and you'll want to either use "SET search_path TO app, public" or possibly one of the "ALTER DATABASE/ ALTER USER" commands to setup your connection defaults.

In short, you can choose to forgo using session startup options which are passed to the server and treated by it as command-line (shell) options.  I suspect most users do.

32.1.2 lists all of the words that can appear in the "keyarray" above - these configure the client so it can talk to the server.  If the word chosen is "options", however, the valid values come from what the server recognizes and instructs the server to start the newly connected session with the GUC/configuration variables set to the specified values.

David J.



pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: [GENERAL] Connection options
Next
From: Tom Lane
Date:
Subject: Re: [GENERAL] Connection options