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