0

If data is inserted into a postgresql database using asynchronous commit, is it possible for a subsequent select query to guarantee that the data it reads has been written to disk?

I am storing generated data in postgresql and since the data can be regenerated, I would like to take advantage of asynchronous commit to increase throughout. But the generated data is periodically synchronised with an external system and it is important that data that has been sent to the external system is not lost.

asked Apr 1, 2018 at 13:23

1 Answer 1

1

Have the sync program update a counter or timestamp in some dummy table and commit the update:

begin;
select * from async_inserted;
-- maybe do something in the external system here
update dummy set synctime=now();
commit;
-- or maybe do something external here instead

Of course if the update or commit fails, that could still leave you not knowing what state the external system should be in. You might need to use prepared transactions (aka "2 phase commit") to bond the two systems together atomically.

answered Apr 1, 2018 at 13:44

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.