Fix EZP-18096: allow dumping big databases without running out of memory

This is the 2nd part / cleanup part of the work started in 2ce01e71cdb8c43272af7cb74e9f3b8bc1db48c2

In short: commit 2ce01e71cdb8c43272af7cb74e9f3b8bc1db48c2 merged half each of the fixes for EZP-18096 and EZP-15449.
It was thus later reverted.

Now this pull request, along with 802, allow to cleanly finish the work started 2 years ago :-)