I just looked at some old, which among other things writes to a db. On inspection, the way I was doing things look dumb bordering on insane. Basically, I have a bunch of files which I am processing, and for reasons unknown to me, I decided to break each file up into pieces and add each piece to the db separately, first drop constraints, run copy, then readd constraints. the result is that the process is dominated by ALTER TABLE, which is screwy