japananh / TIL

Today I learned

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WAL (Write ahead log)

japananh opened this issue · comments

How does WAL work?

  • WAL (Write ahead log or Redo log) is a method used to ensure that changes to a database are recorded before the actual data is updated. It's primarily used in database management systems (DBMS) like PostgreSQL and SQLite.
  • How it works: When a change is made to the data, it's first written to a log (the WAL), and then the actual data is updated. This ensures that changes are durable and can be replayed if there's a crash or failure.
  • Configure WAL segment size in the configuration file (postgresql.conf)

Best practices

  • WAL has a size, when the WAL is full, it's time to flush changes into disk. Keep the WAL segment size as short as possible to reduce the checkpoint time, so the flushing of data from WAL to disk will be more frequent.

References