<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Standby on Postgres Scripts</title><link>https://www.postgresscripts.com/tags/standby/</link><description>Recent content in Standby on Postgres Scripts</description><generator>Hugo -- gohugo.io</generator><language>en</language><copyright>PostgresScripts.com</copyright><lastBuildDate>Fri, 22 May 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://www.postgresscripts.com/tags/standby/index.xml" rel="self" type="application/rss+xml"/><item><title>Monitor PostgreSQL Replication Lag with pg_stat_replication</title><link>https://www.postgresscripts.com/post/monitor-postgresql-replication-lag-with-pg-stat-replication/</link><pubDate>Fri, 22 May 2026 00:00:00 +0000</pubDate><guid>https://www.postgresscripts.com/post/monitor-postgresql-replication-lag-with-pg-stat-replication/</guid><description>
&lt;h2 id="monitor-postgresql-replication-lag-with-pg_stat_replication"&gt;Monitor PostgreSQL Replication Lag with pg_stat_replication&lt;/h2&gt;
&lt;p&gt;A standby lagging more than a few seconds is rarely a transient hiccup — it is a query backlog on the standby, a network ceiling between the nodes, a misconfigured &lt;code&gt;hot_standby_feedback&lt;/code&gt;, or a single-threaded apply storm. &lt;code&gt;pg_stat_replication&lt;/code&gt; joined to &lt;code&gt;pg_wal_lsn_diff()&lt;/code&gt; exposes each replica's byte lag and time lag in one row, on the primary, no SSH required.&lt;/p&gt;
&lt;script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1012089347386563"
crossorigin="anonymous"&gt;&lt;/script&gt;
&lt;ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-1012089347386563"
data-ad-slot="7945792173"
data-ad-format="auto"
data-full-width-responsive="true"&gt;&lt;/ins&gt;
&lt;script&gt;
(adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;h2 id="purpose-and-overview"&gt;Purpose and Overview&lt;/h2&gt;
&lt;p&gt;PostgreSQL streaming replication is asynchronous by default. The primary commits a transaction, writes the WAL record locally, the WAL sender forwards it to the standby, the standby writes it to its own WAL, flushes the WAL to disk, and finally replays it into the data files. Each stage runs on a separate thread of execution, and each stage has its own latency. Under load they diverge: write may be near-instant, flush a few milliseconds, and replay seconds or minutes behind on a busy standby.&lt;/p&gt;</description></item></channel></rss>