The maintenance script rebuildLocalizationCache.php shouldn't really need a DB connection in order to run.
However when run with the Gadgets extension loaded a getWithSetCallback call on WanCache calls Database::getCacheSetOptions which requires a database connection.
With no DB connection this results in:
[0ecc9d2086ceee9fdbb9e20b] [no req] Wikimedia\Rdbms\DBConnectionError from line 1213 of /var/www/html/includes/libs/rdbms/loadbalancer/LoadBalancer.php: Cannot access the database: No working replica DB server: Unknown error ()
Backtrace:
#0 /var/www/html/includes/libs/rdbms/loadbalancer/LoadBalancer.php(749): Wikimedia\Rdbms\LoadBalancer->reportConnectionError()
#1 /var/www/html/includes/GlobalFunctions.php(2637): Wikimedia\Rdbms\LoadBalancer->getConnection(boolean, array, boolean)
#2 /var/www/html/extensions/Gadgets/includes/MediaWikiGadgetsDefinitionRepo.php(105): wfGetDB(integer)
#3 /var/www/html/includes/libs/objectcache/WANObjectCache.php(1414): MediaWikiGadgetsDefinitionRepo->{closure}(boolean, integer, array, NULL)
#4 /var/www/html/includes/libs/objectcache/WANObjectCache.php(1275): WANObjectCache->doGetWithSetCallback(string, integer, Closure, array)
#5 /var/www/html/extensions/Gadgets/includes/MediaWikiGadgetsDefinitionRepo.php(115): WANObjectCache->getWithSetCallback(string, integer, Closure, array)
#6 /var/www/html/extensions/Gadgets/includes/MediaWikiGadgetsDefinitionRepo.php(31): MediaWikiGadgetsDefinitionRepo->loadGadgets()
#7 /var/www/html/extensions/Gadgets/includes/GadgetHooks.php(143): MediaWikiGadgetsDefinitionRepo->getGadgetIds()
#8 /var/www/html/includes/Hooks.php(174): GadgetHooks::registerModules(ResourceLoader)
#9 /var/www/html/includes/Hooks.php(202): Hooks::callHook(string, array, array, NULL)
#10 /var/www/html/includes/resourceloader/ResourceLoader.php(263): Hooks::run(string, array)
#11 /var/www/html/includes/ServiceWiring.php(444): ResourceLoader->__construct(GlobalVarConfig, WikWikiLogger)
#12 /var/www/html/includes/libs/services/ServiceContainer.php(430): Wikimedia\Services\ServiceContainer->{closure}(MediaWiki\MediaWikiServices)
#13 /var/www/html/includes/libs/services/ServiceContainer.php(414): Wikimedia\Services\ServiceContainer->createService(string)
#14 /var/www/html/includes/MediaWikiServices.php(771): Wikimedia\Services\ServiceContainer->getService(string)
#15 /var/www/html/includes/cache/localisation/LocalisationCache.php(1037): MediaWiki\MediaWikiServices->getResourceLoader()
#16 /var/www/html/includes/cache/localisation/LocalisationCacheBulkLoad.php(100): LocalisationCache->recache(string)
#17 /var/www/html/maintenance/rebuildLocalisationCache.php(162): LocalisationCacheBulkLoad->recache(string)
#18 /var/www/html/maintenance/rebuildLocalisationCache.php(122): RebuildLocalisationCache->doRebuild(array, LocalisationCacheBulkLoad, boolean)
#19 /var/www/html/maintenance/doMaintenance.php(99): RebuildLocalisationCache->execute()
#20 /var/www/html/maintenance/rebuildLocalisationCache.php(181): require_once(string)
#21 {main}