From: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> |
---|---|
To: | Igor Korot <ikorot01(at)gmail(dot)com> |
Cc: | Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>, pgsql-general <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Connection options |
Date: | 2017-06-15 22:12:33 |
Message-ID: | CAKFQuwZBWTkX0aiEQGRo3Lah0Cb_cxPp2KSWvDVVGOm+GQXD7w@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Thu, Jun 15, 2017 at 2:41 PM, Igor Korot <ikorot01(at)gmail(dot)com> wrote:
>
> On Thu, Jun 15, 2017 at 4:46 PM, David G. Johnston
> <david(dot)g(dot)johnston(at)gmail(dot)com> wrote:
> > On Thu, Jun 15, 2017 at 1:23 PM, Igor Korot <ikorot01(at)gmail(dot)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:
https://www.postgresql.org/docs/current/static/config-setting.html
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.
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2017-06-15 22:16:14 | Re: Connection options |
Previous Message | Adrian Klaver | 2017-06-15 21:47:29 | Re: Connection options |