Postgres locks per mode and thing locked

From #1009