Manual:$wgReadOnly

Details
Functionally this setting is the same as $wgReadOnlyFile, but uses a variable instead of a file.

If set to a string in "LocalSettings.php",  disallows editing, displaying the string given as the reason. The reason provided is preceded by the contents of MediaWiki:Readonlywarning.

$wgReadOnly = 'This wiki is currently being upgraded to a newer software version.';

The above example locks the database and provides a readonlyWarning>MediaWiki:Readonlywarning|default statement on edit pages and also gives the included string  as an explanation for why the database was locked.

DB caching
Some caches that use the database may still be written to during read only mode. This can be avoided by disabling cache, albeit at the cost of making your wiki slow. This can be accomplished with the following settings in LocalSettings.php: $wgMessageCacheType = $wgMainCacheType = $wgParserCacheType = CACHE_NONE; $wgLocalisationCacheConf['storeClass'] = 'LCStoreNull';

If you want your wiki to be fast, well still not using the DB, you should consider using something like Memcached. See Manual:$wgMainCacheType and Manual:$wgLocalisationCacheConf for details.