Let's say I have a pool of 4 parallel workers in my PostgreSQL database configuration. I also have 2 sessions.
In session#1, the SQL is currently executing, with my planner randomly choosing to launch 2 workers for this query.
So, in session#2, how can I know that my pool of workers has decreased by 2?
Internally, Postgres keeps track of how many parallel workers are active with two variables named
parallel_register_countandparallel_terminate_count. The difference between the two is the number of active parallel workers. See comment in in the source code.Before registering a new parallel worker, this number is checked against the
max_parallel_workerssetting in the source code here.Unfortunately, I don't know of any direct way to expose this information to the user.
You'll see the effects of an exhausted limit in query plans. You might try
EXPLAIN ANALYZEwith aSELECTquery on a big table that's normally parallelized. You would see fewer workers used than workers planned. The manual: