Read-only mode

The database supports a read-only mode which can be used during upgrades or for failover/verification.

Read-only mode is separate from restore mode - restore mode generally disables tasks that have external effects or trigger modifications, but does not block updates to the database itself.

Read-only mode works at the HareScript level and is checked at work begin and commit. Direct connections to the database can still modify it.

To enter read-only mode: `wh db setserver readonly`

To exit read-only mode: `wh db setserver readwrite`

Effects of readonly mode

`GetPrimary()->BeginWork()` will throw immediately. You can check %IsDatabaseReadonly to help prevent this situation, but to handle this in a race-free manner you need to properly handle the %DatabaseReadonlyExceptionĀ 

`ScreenBase::BeginWork` will work, but Finish will report that the database is in readonly mode and fail (Similar to deadlock/unique constraint violations that aren't caught until Finish)

Upgrading Posgresql

To upgrade the WebHare database on macOS from 12 to 13:

cd $WEBHARE_DATAROOT  # see 'wh dirs' fo the proper value if needed
mv postgresql/db postgresql/db.bak
brew install postgresql@12
initdb -D postgresql/db --auth-local=trust -E 'UTF-8' --locale='en_US.UTF-8'
pg_upgrade -b /usr/local/Cellar/postgresql@12/12.4/bin/ -d postgresql/db.bak -D postgresql/db

If all seems fine, you can delete $WHDATA/postgresql/db.bak at some point