2

Suppose my PostgreSQL instance suddenly abnormally stopped and data is dirty and not saved in RAM or WAL. In that case what will happen ?

Where from I can recover that data? and also if server also shutdown in that case what will happen to dirty data?

Is there any separate file where that dirty data stored to recover?

asked Jul 7, 2022 at 8:39
1

3 Answers 3

6

data is dirty and not saved in RAM or WAL.

Where would that data be if not in those locations?

Within the Postgres executable there is a strictly defined sequence of when data in memory, WAL and disk files are written. This ensures consistent recovery after system crashes. Transactions which have been committed still show in the data after recovery. Transactions which made changes but were not committed are rolled back. Whatever "dirtyness" they may have caused is wiped clean.

You do not need to do anything manually to achieve this. It is built into the executable.

answered Jul 7, 2022 at 8:55
2

Dirty data from your transaction are "saved" in RAM (but that will not survive a shutdown), and they may also be saved in the WAL. They may even be written to the data files and persisted to disk.

However, all that does not matter. As long as the transaction was not committed, the transaction is not marked as committed in the commit log, and all the data are invisible. If any of the data from your aborted transaction made it to data files before the shutdown, autovacuum will remove them at some later point.

answered Jul 8, 2022 at 7:38
1

The PosgreSQL documentation has a whole section on reliability and the Write Ahead Log. It's quite detailed as to how it works, and how data is managed. Once it's committed and written to the WAL, it can be considered to be in the database. If it isn't committed to the WAL, it won't be in the database. There is no more to it than that.

answered Jul 8, 2022 at 10:14

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.