passing linux user to PG server as a variable ? - Mailing list pgsql-general

From David Gauthier
Subject passing linux user to PG server as a variable ?
Date
Msg-id CAMBRECCo03UqbEdKLbgzq7UpApOLNjiHrGx+iumcT5OqMtQNSA@mail.gmail.com
Whole thread Raw
Responses Re: passing linux user to PG server as a variable ?  (Tim Clarke <tim.clarke@minerva.info>)
Re: passing linux user to PG server as a variable ?  ("David G. Johnston" <david.g.johnston@gmail.com>)
Re: passing linux user to PG server as a variable ?  (Ian Barwick <ian.barwick@2ndquadrant.com>)
Re: passing linux user to PG server as a variable ?  (Paul Förster <paul.foerster@gmail.com>)
List pgsql-general
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 !



pgsql-general by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: Bytea Example
Next
From: Tim Clarke
Date:
Subject: Re: passing linux user to PG server as a variable ?