Use Common Table Expression (CTE) to reduce locks (max_locks_per_transaction)
A CTE is no table and won't need an entry in the lock table.

It is probably a good idea not to create and drop temporary tables all the time. Apart from the problem you are experiencing, it can lead to a bloated pg_attribute catalog table (all those added and deleted columns).

Mind that a CTE is only for the duration of a single table.