Postgres storage: introduce a db() context manager
This helper avoids us repeating the get_db/put_db pattern all the time.