CYBERTEC PostgreSQL Logo

PostgreSQL underused features - WAL compression

06.2016 / Category: / Tags: |

The WAL compression feature

With the launch of Postgres 9.5, a new setting called "wal_compression" was introduced, that should decrease the IO load on behalf of CPU load. That is a desirable compromise considering typical constraints of modern hardware. But somehow the feature didn't get the publicity it deserved - it wasn't even mentioned in the What's new roundup and by default it's turned off. So I thought I'll try to broadcast the message out again and provide a simple test scenario to highlight the benefits.

Setup for testing WAL compression

First, we'll run the small script you can find below (for the "do try this at home" folks out there) in two versions, with wal_compression "on" and "off" accordingly. Testing scenario itself is pretty simple, we rely on our good old friend pgbench again. First we initialize the pgbench schema with a "scale" value of 100, translating into 10 Mio rows in the main "pgbench_accounts" table and at about 1.3 GB of "on disk" size. Then we do a short benchmark run with 200k transactions. Default transactions in pgbench consist mostly of random updates over the whole primary key space.

Here we'll be only interested here though only in the written WAL size, and take a note of that after every step. One thing to notice here is that for the WAL-s to accumulate we'll need to set the wal_keep_segments (min_wal_size would do the trick also) to a high value, so that no WAL files would be recycled and we can measure write activity directly off the filesystem.

Here is our test script for WAL compression.

Test results - WAL compression

After going through 2 runs I got the following numbers: 1st run, wal_compression = on

2nd run, wal_compression = off

Now let's do some calculations...

What we can see is that the size difference during initialization (sequential INSERTs) of the test schema yields a moderate ~6%, but random updates exhibit a whopping 255% difference in WAL written!

Conclusion

Ok, conclusion time. As we had a synthetic dataset we could say that if you're doing mostly random updates over the whole dataset, enabling wal_compression could bring you noticeable improvement in the form of: a replication lag decrease when the network between replicas is slow; disk space savings for your WAL archive when doing PITR; or most importantly, a general decrease of server disk IO contention. You should definitely give this setting a try! And the best part is that it's as easy as switching the flag in your config and restarting your server.

In case you need any assistance, please feel free to contact us.

2 responses to “PostgreSQL underused features - WAL compression”

  1. Hello,

    I ran many tests around this parameter on UBUNTU for INSERTs and Updates of 15,00,000 rows. Here is my observation:

    Parameter can be changed dynamically.

    In replicated environment, WAL_COMPRESSION needs to be enabled on all servers (master and slaves) for benefits..

    INSERT were 22% faster and UPDATES were 31% faster post wal_compression. I ran this test 4 times, every time response was faster.

    There is less positive impact on network bandwidth utilization due to wal_compression.

    WAL space consumption was around 5% less than normal. I didn't get big benefit in space, however I can see overall improvement in response time of INSERT and UPDATE.

Leave a Reply

Your email address will not be published. Required fields are marked *

CYBERTEC Logo white
Get the newest PostgreSQL Info & Tools


    This site is protected by reCAPTCHA and the Google Privacy Policy & Terms of Service apply.

    ©
    2024
    CYBERTEC PostgreSQL International GmbH
    phone-handsetmagnifiercrosscross-circle
    linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram