Обсуждение: Unique ID for current connection from C

Поиск
Список
Период
Сортировка

Unique ID for current connection from C

От
Shawn Garbett
Дата:
I'm still trying to figure out how to save a variable
attached to a connection. The basic problem is that a
front end app server has a connection pool, all with
the same user/password login. I want to communicate
the authenticated user to auditing triggers firing in
a postgres backend. I can add a query into the
beginning of a transaction by using an intercepter
from the persistence layer. The goal is that the query
will then place the authenticated user info somewhere
that a Postgres trigger can use it.

I am exploring writing an extension in C to Postgres,
but I can't find how to get a unique number
identifying the current connection. Then I can use a
global hash (with updates protected by a semaphore).
Is there a way to get an ID for the current connection
from C? If so I know how to do the rest.

Shawn

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

Re: Unique ID for current connection from C

От
Tom Lane
Дата:
Shawn Garbett <shawn_garbett@yahoo.com> writes:
> I am exploring writing an extension in C to Postgres,
> but I can't find how to get a unique number
> identifying the current connection.

There isn't a globally unique number.  If you're satisfied with
something unique among active connections, I'd suggest backend PID.

            regards, tom lane

Re: Unique ID for current connection from C

От
Shawn Garbett
Дата:
--- Tom Lane <tgl@sss.pgh.pa.us> wrote:

> Shawn Garbett <shawn_garbett@yahoo.com> writes:
> > I am exploring writing an extension in C to
> Postgres,
> > but I can't find how to get a unique number
> > identifying the current connection.
>
> There isn't a globally unique number.  If you're
> satisfied with
> something unique among active connections, I'd
> suggest backend PID.

That'll do it! Thanks, the alternatives to this
approach take many thousands of lins of code.

Shawn

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com