postgres query performance
Most of the time is spent aggregating and sorting the data.
I don't know how the tables are partitioned, but if the partitioning key is part of the join condition or the aggregate can be calculated partition by partition, you might benefit by setting enable_partitionwise_aggregate and enable_partitionwise_join to on.
There is not much more I can say with that little information.