Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent Write Ahead Logging on just one table in PostgreSQL?

Tags:

postgresql

I am considering log-shipping of Write Ahead Logs (WAL) in PostgreSQL to create a warm-standby database. However I have one table in the database that receives a huge amount of INSERT/DELETEs each day, but which I don't care about protecting the data in it. To reduce the amount of WALs produced I was wondering, is there a way to prevent any activity on one table from being recorded in the WALs?

like image 388
Guy C Avatar asked Sep 01 '08 16:09

Guy C


People also ask

What is write ahead logging in PostgreSQL?

WAL (write-ahead log) is the log of changes made to the database cluster which is replayed either as part of the database recovery process when a database isn't shutdown correctly (such as when a crash occurs), or is used by standbys to replay the changes to replicate the database.

What is WAL or XLOG Postgres?

In PostgreSQL, the history data are known as XLOG record(s) or WAL data. XLOG records are written into the in-memory WAL buffer by change operations such as insertion, deletion, or commit action. They are immediately written into a WAL segment file on the storage when a transaction commits/aborts.

What is WAL buffer in PostgreSQL?

WAL Buffers The write ahead log (WAL) buffers are also called "transaction log buffers", which is an amount of memory allocation for storing WAL data. This WAL data is the metadata information about changes to the actual data, and is sufficient to reconstruct actual data during database recovery operations.

What is unlogged table in Postgres?

Unlogged tables is a PostgreSQL feature that can be used effectively to optimize bulk inserts. PostgreSQL uses Write-Ahead Logging (WAL). It provides atomicity and durability, by default. Atomicity, consistency, isolation, and durability make up the ACID properties.


2 Answers

Ran across this old question, which now has a better answer. Postgres 9.1 introduced "Unlogged Tables", which are tables that don't log their DML changes to WAL. See the docs for more info, but at least now there is a solution for this problem.

See Waiting for 9.1 - UNLOGGED tables by depesz, and the 9.1 docs.

like image 152
xzilla Avatar answered Sep 21 '22 14:09

xzilla


Unfortunately, I don't believe there is. The WAL logging operates on the page level, which is much lower than the table level and doesn't even know which page holds data from which table. In fact, the WAL files don't even know which pages belong to which database.

You might consider moving your high activity table to a completely different instance of PostgreSQL. This seems drastic, but I can't think of another way off the top of my head to avoid having that activity show up in your WAL files.

like image 38
Greg Hewgill Avatar answered Sep 20 '22 14:09

Greg Hewgill