Fix race when the database did not exist before starting.

 This is probably relevant for all automated tests of fresh builds, i.e. also Jenkins system tests.

Tests for this PR are in dbcore/37960-db-creation-race, see git log there, `make check`.

BugzID: 37960