<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Concurrency on Postgres Scripts</title><link>https://www.postgresscripts.com/tags/concurrency/</link><description>Recent content in Concurrency on Postgres Scripts</description><generator>Hugo -- gohugo.io</generator><language>en</language><copyright>PostgresScripts.com</copyright><lastBuildDate>Mon, 08 Jun 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://www.postgresscripts.com/tags/concurrency/index.xml" rel="self" type="application/rss+xml"/><item><title>PostgreSQL Advisory Locks with pg_advisory_lock</title><link>https://www.postgresscripts.com/post/postgresql-advisory-locks-with-pg-advisory-lock/</link><pubDate>Mon, 08 Jun 2026 00:00:00 +0000</pubDate><guid>https://www.postgresscripts.com/post/postgresql-advisory-locks-with-pg-advisory-lock/</guid><description>
&lt;h2 id="postgresql-advisory-locks-with-pg_advisory_lock"&gt;PostgreSQL Advisory Locks with pg_advisory_lock&lt;/h2&gt;
&lt;p&gt;Two scheduled jobs fire at the same minute and both try to process the same nightly batch. Nothing in the data stops them — there is no single row to lock, because the work has not produced rows yet. Row and table locks are the wrong tool here. What you want is a named lock that the application agrees to respect, held for as long as the job runs. PostgreSQL provides this with advisory locks through &lt;code&gt;pg_advisory_lock&lt;/code&gt; and its companion functions.&lt;/p&gt;</description></item></channel></rss>