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

From: "Daniel Verite" <daniel(at)manitou-mail(dot)org>
To: "David Gauthier" <davegauthierpg(at)gmail(dot)com>
Cc: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>,"Postgres General" <pgsql-general(at)postgresql(dot)org>
Subject: Re: passing linux user to PG server as a variable ?
Date: 2020-08-18 08:35:15
Message-ID: e5dd8836-4eb0-4b4a-a33e-228b487a653f@manitou-mail.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

David Gauthier wrote:

> I can avoid the error by just throwing a namespace in there...
> atletx7-reg036:/home/dgauthie[ 214 ] --> setenv PGOPTIONS "-c
> 'os.user=$USER' "
> But once in, "show os.user" is undefined.

It's documented to work [1], but you need to remove these single
quotes. For instance:

$ env PGOPTIONS="-c os.user=$USER" psql -d postgres
psql (12.4 (Debian 12.4-1.pgdg90+1))
Type "help" for help.

postgres=> show "os.user";
os.user
---------
daniel
(1 row)

If characters needed to be quoted in the value, backslash
should be used as the quote character. Since it's also
a quote character for the shell, two levels of quoting
are needed:

$ env PGOPTIONS="-c os.user=user\\ is\\ $USER" psql -d postgres
psql (12.4 (Debian 12.4-1.pgdg90+1))
Type "help" for help.

postgres=> show "os.user";
os.user
----------------
user is daniel
(1 row)

[1] https://www.postgresql.org/docs/current/config-setting.html

Best regards,
--
Daniel Vérité
PostgreSQL-powered mailer: https://www.manitou-mail.org
Twitter: @DanielVerite

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Daulat Ram 2020-08-18 10:10:58 Point in time recovery
Previous Message Olivier Gautherot 2020-08-18 07:52:56 Re: "Go" (lang) standard driver