Hello all,

I'm writing a C-language function that is similar to nextval() but should return the next member of the recurrent sequence: T(n+1) = f(T(n), T(n-1), ..., T(n-k)), where f is some function and k is a constant. The state of this object should be persistent between database restarts and should be easily recovered if the database crashes.

So the first problem I encountered was where to store the current state of this object (n and values T(n), T(n-1), ... T(n-k)). I believe that TopMemoryContext is not shared between processes, therefore I must use shmem functions from backend/storage/ipc/shmem.c to create a structure in shared memory.

The next issue is how to synchronize backends' reads/writes to this chunk of shared memory. I suppose there must be something to handle with semaphores in the Postgres code.

Then I periodically need to persist the state of this object to the database, for example for every 100 generated values, as well as on the postmaster's shutdown. What is the best method for doing that?

Please let me know if this problem has been solved before. Thanks for you help.

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to