db: use a thread instead of a tmpfile to COPY data to postgresql
Avoids writing a bunch of temporary files for no good reason. swh/infra/sysadm-environment#866 (closed) was a symptom of this.
Test Plan
No regressions in the unit tests
Migrated from D282 (view on Phabricator)