Is it possible to guarantee a minimum set number of workers for a parallel aggregate function in postgres?

531 Views Asked by At

I have a custom parallel aggregate extension to Postgresql and I would like to have at least N worker processes performing the aggregation every time the aggregate function is used.

Is it possible to tell postgresql to ALWAYS use at least N workers for this function?

1

There are 1 best solutions below

2
On BEST ANSWER

What you can do is set the storage parameter parallel_workers on a table. Then every parallelized scan of that table uses that many workers. But it cannot be done per function, which makes sense, because it depends on the table whether parallelism is useful or not.

Also, you will never be able to guarantee that a certain number of workers is always used, because the cluster-wide maximum of parallel workers is max_parallel_workers, and if that limit is reached, you will not get a parallel worker, even if the optimizer would like to parallelize.

I would just leave that decision to the optimizer.