OK, I am aware that this is rather vague, but unfortunately I was not able not reproduce my problem in simplified code.
I am running a series of functions within another function (
main()). All functions do something within a Postgresql 9.4 / PostGIS 2.1.7 database and work well when executed separately.
main() basically a couple of large tables and corresponding views with geospatial data will be dropped and recreated. The function in question will then do some polygon analysis using the following functions:
main()uses the same connection which is being committed after each function call.
Now when I run the function from within the main function, it will take take forever (i.e. hours instead of seconds) to execute and I have no clue why that is. If I run the function right after main() has finished, it will also be slower than usual. If I wait 1-2 minutes it will be fast again. So it feels to me like some housekeeping is required. I tired (will be updated):
VACUUM ANALYZEof the involved tables
COMMITafter each step
Do you have ideas what the reason could be or how I can further debug my problem?
Update: Well, I found out how to solve my problem (see my answer below). But if anyone feels like explaining why that works, I will be happy to accept their answer.