I'm working on a design for a concurrency-safe incremental aggregate rollup system,and track_commit_timestamp (pg_xact_commit_timestamp) sounds perfect. But I've found very little commentary on it generally, and couldn't figure out how it works in detail from the source code.
Hopefully, someone knows the answers to one or more of my questions:
Is it possible for the commit timestamp feature to produce times out of order? What I'm after is a way to identify records that have been changed since a specific time so that I can get any later changes for processing. If there are identical timestamps, I don't need them in perfect commit sequence.
How many bytes are added to each row in the final implementation? The discussions I saw seemed to be ranging from 12-24 bytes. There was discussion of adding in extra bytes for "just in case." This is pre 9.5, so a world ago.
Are the timestamps indexed internally? With a B-tree? I ask for capacity-planning reasons.
I've seen on StackOverflow and the design discussions that the timestamps are not kept indefinitely, but can't find the details on exactly how long they are stored.
Any rules of thumb on the performance impact of enabling track_commit_timestamp? I don't need the data on all tables but, where I do, it sounds like it might work perfectly.
Any gotchas? I tried running VACUUM FULL on a test table and none of the pg_xact_commit_timestamp changed. It seems like a physical operation like VACUUM shouldn't change anything, but there could easily be something I've not thought of. And, honestly, my quick VACUUM test might not even mean anything.
Many thanks for any assistance!
I've edited my question to clarify what I'm trying to accomplish, I'm looking to track processed and unprocessed data based on update stamps.
select max(pg_xact_commit_timestamp(xmin)) from scan;-- 2019-07-07 20:46:14.694288+10
update scan set quantity = 5 where quantity = 1; -- Change some data.
select max(pg_xact_commit_timestamp(xmin)) from scan; -- 2019-07-10 09:38:17.920294+10
-- Find the changed row(s):
select *
from scan
where pg_xact_commit_timestamp(xmin) > '2019-07-07 20:46:14.694288+10';
The idea is to do a rollup on rows incrementally and regularly. So,
-- Track the last rolled up timestamp.
-- Wait for 5 minutes (or whatever.)
-- Find the current max commit timestamp.
-- Search for rows where the commit timestamp is between the last processed timestamp and the max.
-- Roll them up.
Transaction IDs alone can't work because they can commit out of order very easily. And this timestamp system doesn't have to be 100% perfect, but I'm aiming for something very close to perfect. So, a bit of clock wiggle and even a bit of confusion around overlapping start/end times is likely tolerable.
Is there a glaring flaw in this plan?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…