@@ -915,10 +915,14 @@ void LocalServer::processConfig()
915915
916916 if (getClientConfiguration ().has (" path" ))
917917 {
918- attachSystemTablesServer (global_context, *createMemoryDatabaseIfNotExists (global_context, DatabaseCatalog::SYSTEM_DATABASE), false );
919918 attachInformationSchema (global_context, *createMemoryDatabaseIfNotExists (global_context, DatabaseCatalog::INFORMATION_SCHEMA));
920919 attachInformationSchema (global_context, *createMemoryDatabaseIfNotExists (global_context, DatabaseCatalog::INFORMATION_SCHEMA_UPPERCASE));
921920
921+ // / Attaching "automatic" tables in the system database is done after attaching the system database.
922+ // / Consequently, it depends on whether we load it from the path.
923+ // / If it is loaded from a user-specified path, we load it as usual. If not, we create it as a memory (ephemeral) database.
924+ bool attached_system_database = false ;
925+
922926 String path = global_context->getPath ();
923927
924928 // / Lock path directory before read
@@ -933,6 +937,9 @@ void LocalServer::processConfig()
933937 {
934938 LoadTaskPtrs load_system_metadata_tasks = loadMetadataSystem (global_context);
935939 waitLoad (TablesLoaderForegroundPoolId, load_system_metadata_tasks);
940+
941+ attachSystemTablesServer (global_context, *DatabaseCatalog::instance ().tryGetDatabase (DatabaseCatalog::SYSTEM_DATABASE), false );
942+ attached_system_database = true ;
936943 }
937944
938945 if (!getClientConfiguration ().has (" only-system-tables" ))
@@ -947,6 +954,9 @@ void LocalServer::processConfig()
947954
948955 LOG_DEBUG (log, " Loaded metadata." );
949956 }
957+
958+ if (!attached_system_database)
959+ attachSystemTablesServer (global_context, *createMemoryDatabaseIfNotExists (global_context, DatabaseCatalog::SYSTEM_DATABASE), false );
950960 }
951961 else if (!getClientConfiguration ().has (" no-system-tables" ))
952962 {
0 commit comments