Table of contents

PostgreSQL Advisory Locks

Advisory locks are a feature of PostgreSQL to achieve mutual exclusion between different processes. This is a session-level feature: a lock acquired in a transaction will be held until it is explicitly released or the session ends, even if the transaction is rolled back.

Apps which use advisory locks

  • The email-alert-api uses an advisory lock to prevent concurrent generation of emails in many of its workers, for example the ImmediateEmailGenerationWorker. Not using the lock here can result in duplicate emails being sent out.

  • The publishing-api uses an advisory lock to prevent concurrent writes to the content-store in ContentStoreWriter. Not using the lock here can result in overlapping modifications to the same content item.

A complete and up-to-date list can be found using the GitHub search.

This page was last reviewed . It needs to be reviewed again by the page owner #govuk-2ndline.