Shared sequence-like objects in PostgreSQL - Mailing list pgsql-hackers

From Vlad Arkhipov
Subject Shared sequence-like objects in PostgreSQL
Date
Msg-id 4E799006.4030308@dc.baikal.ru
Whole thread Raw
Responses Re: Shared sequence-like objects in PostgreSQL
List pgsql-hackers
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.


pgsql-hackers by date:

Previous
From: Peter Geoghegan
Date:
Subject: Re: Inlining comparators as a performance optimisation
Next
From: Magnus Hagander
Date:
Subject: Re: Online base backup from the hot-standby