Search Postgresql Archives

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 17/08/2020 20:52, David Gauthier wrote:
9.6.7 on linux

I need to insert the linux username of a user on the client side into a col using an insert statement.  I realize that the server knows nothing about who the linux user was on a client, but I was thinking that I might be able to pass that in somehow through a variable.
 

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

I don't even know if this approach has any legs or not given what I want to do.  I'm just trying ideas hoping something will work.  But if it might work, is this setting a variable like this something that can be run unconditionally whenever a linux user connects to the DB on a client server ?  If so, where would this be inserved in the connect process ? TO get the linux user, I would just tap $USER or backtick `whoami` or something like that.

Of course if there is another way to accomplish my goal, I'm all ears :-)

Thanks in advance for any replies/ideas !



How many users do you have to identify? Have them log in to your application and thence to PG then you can pick up the PG CURRENT_USER var?


Tim Clarke

 

Telephone: Witham: +44(0)1376 503500 | London: +44 (0)20 3009 0853 | Frankfurt: +49 (0)69 7191 6000 | Hong Kong: +852 5803 1687 | Toronto: +1 647 503 2848
Web: https://www.manifest.co.uk/

 

Minerva Analytics Ltd - A Solactive Company
9 Freebournes Court | Newland Street | Witham | Essex | CM8 2BL | United Kingdom


Copyright: This e-mail may contain confidential or legally privileged information. If you are not the named addressee you must not use or disclose such information, instead please report it to admin@xxxxxxxxxxxx
Legal: Minerva Analytics is the trading name of: Minerva Analytics Ltd: Registered in England Number 11260966 & The Manifest Voting Agency Ltd: Registered in England Number 2920820 Registered Office at above address. Please Click Here https://www.manifest.co.uk/legal/ for further information.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux