db: use a thread instead of a tmpfile to COPY data to postgresql
Summary:
Avoids writing a bunch of temporary files for no good reason. T866 was a symptom
of this.
Test Plan: No regressions in the unit tests
Reviewers: Reviewers!
Differential Revision: https://forge.softwareheritage.org/D282