Thanks for your response (and the error codes link).
I am not sure at all whether the 'too many connections' error (which seems to be the most frequent error description by far) happens when a process initially tries to connect or whether the process has already performed some action using the database and is coming back to try another db transaction later after some time has elapsed. I suspect it is an initial connection failure in most cases but I also want to prevent the dropped connection as well. It's pretty difficult to diagnose exactly which is happening because of the forking of processes and the fact that many, many processes all write to the same file. Basically what happens is that I have N machines, each of which has one master process which connects to the database to lock-and-fetch 500 records in a database table. The master process then starts to fork off one new process to handle each locked record and that forked off process must make its own connection to the database to avoid any crosstalk between it and its parent process -- you can't have them sharing the same db connection resource.
As each forked-off child process works, it is downloading an image and then rendering thumbnails and then uploading them to a CDN -- a possibly time-consuming process involving lots of data crunching and possibly network latencies at various stages. It's a distinct possibility that the database connection might drop or time out or something between its initial connection and final database call.