snipt

Ctrl+h for KB shortcuts

SQL

Monitor active PostgreSQL queries against a database

1
2
3
4
SELECT procpid, current_query, waiting
FROM   pg_stat_activity
WHERE  datname = 'your_database_name'
AND    current_query <> '<IDLE>';
https://snippets.siftie.com/embed/47684408f6eae77c0384c2e2644d693d/
/raw/47684408f6eae77c0384c2e2644d693d/
47684408f6eae77c0384c2e2644d693d
sql
SQL
4
2019-04-12T00:38:12
True
False
False
/api/public/snipt/13311/
monitor-active-postgresql-queries-against-a-database
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="k">SELECT</span> <span class="n">procpid</span><span class="p">,</span> <span class="n">current_query</span><span class="p">,</span> <span class="n">waiting</span> </span><span id="L-2"><a name="L-2"></a><span class="k">FROM</span> <span class="n">pg_stat_activity</span> </span><span id="L-3"><a name="L-3"></a><span class="k">WHERE</span> <span class="n">datname</span> <span class="o">=</span> <span class="s1">&#39;your_database_name&#39;</span> </span><span id="L-4"><a name="L-4"></a><span class="k">AND</span> <span class="n">current_query</span> <span class="o">&lt;&gt;</span> <span class="s1">&#39;&lt;IDLE&gt;&#39;</span><span class="p">;</span> </span></pre></div> </td></tr></table>
db, psql, query