Database Reference
In-Depth Information
There's more...
Some more explanations about the preceding may be appropriate here.
No need for "= true"
As the column waiting is already boolean, you can safely omit the = true part from the query
and simply write the following:
SELECT datname,usename,current_query
FROM pg_stat_activity
WHERE waiting;
This catches only queries waiting on locks
The pg_stat_activity.waiting field shows only if the query is waiting on a PostgreSQL
internal lock.
Although this is the main cause of waiting when using pure SQL, it is possible to write something
in any of the PostgreSQL's embedded languages, which can wait on other system resources,
such as waiting for an http response, a file write to complete, or just waiting on timer.
An example:
Write a simple function in PL/PythonU (the U version means untrusted; that is, only
superusers can create functions in this language):
create or replace function wait(seconds float)
returns void as $$
import time;
time.sleep(seconds)
$$
language plpythonu;
When you run the following function:
db=# select wait(10);
<it "stops" for 10 seconds here>
wait
------
(1 row)
it will show up with as not waiting in the pg_stat_activity view, even though the query
is in fact "blocked" on timer.
 
Search WWH ::




Custom Search