0

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 Answers1

1

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.

Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263
  • I see. I thought `parallel_workers` was a system wide thing, not a per table thing. How do I ask my table what its current `parallel_workers` value is? – ReverseFlowControl Oct 21 '20 at 06:36
  • 1
    You can use `\d+ table_name` in `psql` to see the storage parameters, or `SELECT reloptions FROM pg_class WHERE relname = 'table_name';`. `parallel_workers` is just an override for the normal optimizer logic based on `min_parallel_table_scan_size`, but it is trumped by `max_parallel_workers_per_gather` and `max_parallel_workers`. – Laurenz Albe Oct 21 '20 at 06:39