This recipe is a work in progress and has never been run as-is.
- timeouts are in ms
- lock timeout: in postgres, when a statement that wants a restrictive lock waits on another lock, other statements that want locks can't jump the queue. so even though the statement that is waiting might only take a very short amount of time, when it starts running, while it is waiting no other statements can begin. So we set the lock timeout pretty low and retry if we don't get it.
- statement timeout: we set a short statement timeout before statements which do lock and which we expect to take a short amount of time, just in case something about our assumptions/understanding is wrong and the statement ends up taking a long time. if this happens the statement will bail early without causing harm, and we can investigate what is wrong with
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE ROLE owner LOGIN ENCRYPTED PASSWORD 'secret' CONNECTION LIMIT 3; | |
ALTER ROLE owner SET statement_timeout = 20000; | |
ALTER ROLE owner SET lock_timeout = 3000; | |
ALTER ROLE owner SET idle_in_transaction_session_timeout = 3000; -- v9.6+ | |
CREATE ROLE readwrite_users NOLOGIN; | |
CREATE ROLE readonly_users NOLOGIN; | |
CREATE DATABASE exampledb WITH OWNER owner ENCODING UTF8 LC_COLLATE 'en_US.UTF-8' LC_CTYPE 'en_US.UTF-8'; |