From: Rajesh Kumar Mallah <mallah.rajesh@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-sql@postgresql.org
Subject: Re: transactional shared variable in postgresql
Date: Mon, 20 Nov 2006 16:07:19 +0530
Message-ID: <a97c77030611200237s2d5c86dr7b4da34a5386a732@mail.gmail.com> (raw)
In-Reply-To: <532.1163875210@sss.pgh.pa.us>
References: <a97c77030611180430p764dac32ue19ade554ec80cbe@mail.gmail.com>
<532.1163875210@sss.pgh.pa.us>
On 11/19/06, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> "Rajesh Kumar Mallah" <mallah.rajesh@gmail.com> writes:
> > In our webapps, we use the same username to connect to the database
> > for all kind of updates. Hence we are not able to makeout whoo modified
> > what . However at application level we have different "userid" for
> different
> > users of the system. we want to somehow pass this "userid" to the
> databasee
> > server and accesss it from the triggers that implement the audit
> functions.
>
> Perhaps it would be better to make your "userid" be the actual database
> user? But anyway, the custom GUC variable facility might serve your
> needs.
> http://www.postgresql.org/docs/8.1/static/runtime-config-custom.html
Dear Tom,
Thanks for the suggestion , it seems to be working.
i used GetConfigOption of guc.c to retrieve the value.
I am setting the variable from psql eg:
SET general.employee to 101;
I hope what i am doing is correct . I have very little
experience in using C for triggers. can you please tell
if its fine.
in postgresql.conf i declared.
custom_variable_classes = 'general'
And inside the TRIGGER FUNCTION i use the below
------------ x------------------------
int employee = 0 ; /* int for holding employee_id */
char *employee_str ; /* for storing result for GetConfigOption */
employee_str = (char *) GetConfigOption("general.employee") ;
if (employee_str != NULL) {
employee = atoi(employee_str);
}
-------------x----------------------------
also if i do not cast using (char *) the compiler gives a warning:
audit_trail.c:82: warning: assignment discards qualifiers from pointer
target type
why so?
I have verified that the variable is isolated in transaction and
serves my purpose.
Regards
Mallah.
>
> regards, tom lane
>
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: mallah.rajesh@gmail.com, tgl@sss.pgh.pa.us
Subject: Re: transactional shared variable in postgresql
In-Reply-To: <a97c77030611200237s2d5c86dr7b4da34a5386a732@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox