<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Pg_cancel_backend on Postgres Scripts</title><link>https://www.postgresscripts.com/tags/pg_cancel_backend/</link><description>Recent content in Pg_cancel_backend on Postgres Scripts</description><generator>Hugo -- gohugo.io</generator><language>en</language><copyright>PostgresScripts.com</copyright><lastBuildDate>Tue, 14 Apr 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://www.postgresscripts.com/tags/pg_cancel_backend/index.xml" rel="self" type="application/rss+xml"/><item><title>Cancel vs Terminate PostgreSQL Backends Explained</title><link>https://www.postgresscripts.com/post/cancel-vs-terminate-postgresql-backends/</link><pubDate>Tue, 14 Apr 2026 00:00:00 +0000</pubDate><guid>https://www.postgresscripts.com/post/cancel-vs-terminate-postgresql-backends/</guid><description>
&lt;h2 id="cancel-vs-terminate-postgresql-backends-what-every-dba-should-know"&gt;Cancel vs Terminate PostgreSQL Backends: What Every DBA Should Know&lt;/h2&gt;
&lt;p&gt;PostgreSQL gives you two tools for dealing with problem backends: &lt;code&gt;pg_cancel_backend()&lt;/code&gt; and &lt;code&gt;pg_terminate_backend()&lt;/code&gt;. They sound similar but behave very differently. Using the wrong one can disrupt users unnecessarily, or leave a problematic connection in place when you needed it gone entirely.&lt;/p&gt;
&lt;p&gt;This guide explains both functions, when to use each, and how to identify the right PIDs to target.&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="sample-code"&gt;Sample Code&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Cancel a running query (leaves the connection open):&lt;/strong&gt;&lt;/p&gt;</description></item><item><title>Find Idle in Transaction Sessions in PostgreSQL</title><link>https://www.postgresscripts.com/post/find-idle-in-transaction-sessions-postgresql/</link><pubDate>Sat, 28 Mar 2026 00:00:00 +0000</pubDate><guid>https://www.postgresscripts.com/post/find-idle-in-transaction-sessions-postgresql/</guid><description>
&lt;h2 id="how-to-find-idle-in-transaction-sessions-in-postgresql"&gt;How to Find Idle in Transaction Sessions in PostgreSQL&lt;/h2&gt;
&lt;p&gt;An idle-in-transaction session is a database connection that has started a transaction but is not currently running a query. It is just sitting there, holding the transaction open. This is different from a regular idle connection, which has no open transaction.&lt;/p&gt;
&lt;p&gt;Idle-in-transaction sessions are a common problem. They hold locks, block autovacuum, and prevent rows from being cleaned up. If they stay open long enough, they can cause serious performance problems — including transaction ID wraparound.&lt;/p&gt;</description></item><item><title>Kill Idle PostgreSQL Sessions with SQL</title><link>https://www.postgresscripts.com/post/kill-idle-postgresql-sessions-with-pg-terminate-backend/</link><pubDate>Tue, 24 Mar 2026 00:00:00 +0000</pubDate><guid>https://www.postgresscripts.com/post/kill-idle-postgresql-sessions-with-pg-terminate-backend/</guid><description>
&lt;h2 id="kill-idle-postgresql-sessions-with-sql"&gt;Kill Idle PostgreSQL Sessions with SQL&lt;/h2&gt;
&lt;p&gt;The connection count sits at &lt;code&gt;max_connections&lt;/code&gt;, new clients are being refused, and &lt;code&gt;pg_stat_activity&lt;/code&gt; is full of sessions that have run nothing for hours. Freeing the slots takes one statement, &lt;code&gt;pg_terminate_backend()&lt;/code&gt;, but the choices around it decide whether the cleanup is safe: which sessions to select, which signal to send, who is allowed to send it, and what happens to the client on the other end.&lt;/p&gt;</description></item></channel></rss>