Re: transactional shared variable in postgresql

From: "Rajesh Kumar Mallah" <mallah(dot)rajesh(at)gmail(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: transactional shared variable in postgresql
Date: 2006-11-20 10:37:19
Message-ID: a97c77030611200237s2d5c86dr7b4da34a5386a732@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On 11/19/06, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> "Rajesh Kumar Mallah" <mallah(dot)rajesh(at)gmail(dot)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
>

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2006-11-20 16:50:34 Re: tsvector_eq appears to be inconsistent.
Previous Message Dimitri Fontaine 2006-11-20 09:16:32 Re: planner used functional index in 7.3.6, now does a seq