Merge pull request #49100 from kssenii/fix-postgres-setting

Fix postgres database setting
This commit is contained in:
Kseniia Sumarokova 2023-04-25 23:56:16 +02:00 committed by GitHub
commit 6396e2e5b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 1 deletions

View File

@ -17,6 +17,7 @@
#include <Databases/PostgreSQL/fetchPostgreSQLTableStructure.h>
#include <Common/quoteString.h>
#include <Common/filesystemHelpers.h>
#include <Common/logger_useful.h>
#include <filesystem>
namespace fs = std::filesystem;
@ -51,6 +52,7 @@ DatabasePostgreSQL::DatabasePostgreSQL(
, configuration(configuration_)
, pool(std::move(pool_))
, cache_tables(cache_tables_)
, log(&Poco::Logger::get("DatabasePostgreSQL(" + dbname_ + ")"))
{
cleaner_task = getContext()->getSchedulePool().createTask("PostgreSQLCleanerTask", [this]{ removeOutdatedTables(); });
cleaner_task->deactivate();
@ -192,7 +194,10 @@ StoragePtr DatabasePostgreSQL::fetchTable(const String & table_name, ContextPtr,
ColumnsDescription{columns_info->columns}, ConstraintsDescription{}, String{}, configuration.schema, configuration.on_conflict);
if (cache_tables)
{
LOG_TEST(log, "Cached table `{}`", table_name);
cached_tables[table_name] = storage;
}
return storage;
}

View File

@ -73,6 +73,7 @@ private:
mutable Tables cached_tables;
std::unordered_set<std::string> detached_or_dropped;
BackgroundSchedulePool::TaskHolder cleaner_task;
Poco::Logger * log;
String getTableNameForLogs(const String & table_name) const;

View File

@ -397,7 +397,7 @@ StoragePostgreSQL::Configuration StoragePostgreSQL::processNamedCollectionResult
required_arguments.insert("table");
validateNamedCollection<ValidateKeysMultiset<ExternalDatabaseEqualKeysSet>>(
named_collection, required_arguments, {"schema", "on_conflict", "addresses_expr", "host", "hostname", "port"});
named_collection, required_arguments, {"schema", "on_conflict", "addresses_expr", "host", "hostname", "port", "use_tables_cache"});
configuration.addresses_expr = named_collection.getOrDefault<String>("addresses_expr", "");
if (configuration.addresses_expr.empty())

View File

@ -327,6 +327,17 @@ def test_predefined_connection_configuration(started_cluster):
node1.query(f"SELECT count() FROM postgres_database.test_table").rstrip()
== "100"
)
node1.query(
"""
DROP DATABASE postgres_database;
CREATE DATABASE postgres_database ENGINE = PostgreSQL(postgres1, use_tables_cache=1);
"""
)
assert (
node1.query(f"SELECT count() FROM postgres_database.test_table").rstrip()
== "100"
)
assert node1.contains_in_log("Cached table `test_table`")
node1.query("DROP DATABASE postgres_database")
cursor.execute(f"DROP TABLE test_table ")