Re: passing linux user to PG server as a variable ?

Поиск
Список
Период
Сортировка
От David G. Johnston
Тема Re: passing linux user to PG server as a variable ?
Дата
Msg-id CAKFQuwYEPDGPueKmG6vK5Lpk3HzOHV=3ypH-En48wW0rKL7ErQ@mail.gmail.com
обсуждение исходный текст
Ответ на passing linux user to PG server as a variable ?  (David Gauthier <davegauthierpg@gmail.com>)
Ответы Re: passing linux user to PG server as a variable ?  (David Gauthier <davegauthierpg@gmail.com>)
Список pgsql-general
On Mon, Aug 17, 2020 at 12:53 PM David Gauthier <davegauthierpg@gmail.com> wrote:
Looking at psql command line options, I see "-v" (lowercase) which is described as...

-v assignment
--set=assignment
--variable=assignment

Perform a variable assignment, like the \set meta-command. Note that you must separate name and value, if any, by an equal sign on the command line. To unset a variable, leave off the equal sign. To set a variable with an empty value, use the equal sign but leave off the value. These assignments are done during a very early stage of start-up, so variables reserved for internal purposes might get overwritten later.

So I tried that without success.  
"-v sysinfo.osuser=foo" 
failed the connect with...
"psql: could not set variable "sysinfo.osuser""

Next I tried...
"-v osuser=foo"
This didn't fail the connect, but once I got in...
"show osuser" gave... 
"ERROR:  unrecognized configuration parameter "osuser""
The part of the description that says "like the \set meta-command" means you need to read its description as well.  There, and through links therein, you will learn that what you are creating is a variable within the psql client itself, not on the server.  Usage of that client-side variable is documented.  As long as you don't need the variable on the server, and oftentimes you do not, then this feature will work just fine for you.

The SHOW SQL command (and other documented options[1]) is a server command and inspects server variables.  If you really need to create one of those in the current session it may be possible - though I believe you have to use a namespace prefix (i.e., your sysinfo.osuser) to get the system to recognize a user-created variable name.  There is some work on improving things in this area.  Though worse case you can just stick the desired value into a temporary table and maybe create some function wrappers to modify/access it.

David J.




В списке pgsql-general по дате отправления:

Предыдущее
От: Tim Clarke
Дата:
Сообщение: Re: passing linux user to PG server as a variable ?
Следующее
От: David Gauthier
Дата:
Сообщение: Re: passing linux user to PG server as a variable ?