Forum OpenACS Q&A: Re: Ran out of database pools (pool2 pool3 pool1)
Where he's wrong is that all you need to do is to add another pool to your configuration.
The bad news is that nesting db_foreach three deep is a very expensive way to calculate dynamic data. If each db_foreach process 10 rows, the inner query will be executed 100 times. If each process 50 rows ... oh boy.
Are you sure you can't combine the nested loops?