Skip to main content

Improve performance on concurrent UPDATEs for a timestamp column in Postgres

I am using a timestamp column called updated_at for cache invalidation. More information on this particular technique here.

The queries all have the same format

UPDATE "managers" SET "updated_at" = '2014-07-25 15:00:24.212512' WHERE "managers"."id" = 1

The problem is that there is too much activity on this Server, which leads to slow writes. I'm assuming the slowdowns are being caused by the locking mechanism. There is no index on the column.

We have been trying to mitigate this by batching together operations that would cause multiple updates and this did help but the whole system is still suffering.

  1. Would a different kind of column be faster? For example an integer.
  2. Is there some way to not lock the column?
  3. Any other tips to improve this?

We are actually thinking of moving this to redis and using INCR.