Re: functions + shared libraries - Mailing list pgsql-general

From Doug McNaught
Subject Re: functions + shared libraries
Date
Msg-id m3d6ob71gp.fsf@varsoon.wireboard.com
Whole thread Raw
In response to functions + shared libraries  (Eric B.Ridge <ebr@tcdi.com>)
Responses Re: functions + shared libraries  ("Shridhar Daithankar" <shridhar_daithankar@persistent.co.in>)
List pgsql-general
Eric B.Ridge <ebr@tcdi.com> writes:

> Is it possible, via a shared library that contains functions used by
> postgres, to detect when the library is first loaded and when it is
> unloaded?

You could have a 'static' variable in the library, that all its
functions check first thing, and set to 1 after checking.  That would
be a little clumsy, but would work.

As for unloading, I don't think you can detect it other than running a
function on process exit with an atexit() handler.

> Also, each postgres process loads its own copy of a library that
> contains functions.  Is it possible to make a single library instance
> shared across all postgres processes?  I suspect the answer is no b/c
> I assume the postmaster exec()'s postgres, rather than forking, but it
> doesn't hurt to ask.

Shared libraries are not shared memory.  Each process has its own copy
of the library data area; though the text (library code) is usually
shared, it's read-only.  If you want chared memory then use the SysV
or POSIX shm API.

-Doug

pgsql-general by date:

Previous
From: Martijn van Oosterhout
Date:
Subject: Re: UPDATE syntax problem
Next
From: "Shridhar Daithankar"
Date:
Subject: Re: functions + shared libraries