Settings

Theme

Truncate vs. Delete: Efficiently Clearing Data from a Postgres Table

lob.com

20 points by mgartner 7 years ago · 4 comments

Reader

protomyth 7 years ago

Wow, that is the exact opposite of Sybase (and I suspect MSSQL). Also, I seem to remember that Truncate couldn't be used inside a transaction in Sybase as it was basically a big deallocate that couldn't be reversed.

This is one of those commands that shows why you should really review the database's own documentation on common commands. They really don't all work the same. SQL remains a standard where there is a second level of knowledge springing from the database engines.

adeel_siddiqui 7 years ago

Good point. If you are doing this, you also need a good autovacuuming strategy on your pg database. Depending on the size of the tables and the frequency of DELETEs, not vacuuming regularly could potentially cause problems like bloated size on disk, slow queries, etc.

  • mgartnerOP 7 years ago

    You're totally right. In our case, our test infrastructure spins up a new Postgres container for every build. Because it's not a long-running database, bloat is not a concern.

shearnie 7 years ago

Yeah MSSQL is the opposite in massive orders of magnitude

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection