Avoid race conditions when automatically creating databases.
Merge branch 'safe-write' into fork-master