datapusher-plus
datapusher-plus copied to clipboard
Commit after truncate to reduce lock contention
Truncate takes an AccessExclusive lock on the table, which blocks all other transactions from accessing the table, including select for datastore_info and any other access to the table contents. Since those operations are called from the web interface, the UI can hang for the timeout period or untill the copy finishes. This is poor user experience when dealing with large files.
So, truncate in it's own transaction, so that the AccessExclusive lock is held for the least amount of time possible.