Postgres

Avoid Integer for File Sizes in Postgres

Here’s a small bug we recently encountered in production. Occasionally, PDF generation jobs would fail, and the cause turned out to be a small oversight when designing database tables.

The PDF metadata is stored in a table, and the column for file size was defined as integer, also known as int4.

Since this data type is signed in Postgres, those 4 bytes only allow for files up to 2.1 GB (2_147_483_647 bytes). You might think, 2^31 bytes ought to be enough for everybody … except apparently for our PDFs.