[NOT] OVERRIDABLE keywords and XML attributes
and/or the configuration option allow_named_collection_override_by_default.
Storing named collections in the system database
DDL example
key_1can always be overridden.key_2can never be overridden.urlcan be overridden or not depending on the value ofallow_named_collection_override_by_default.
Permissions to create named collections with DDL
To manage named collections with DDL a user must have thenamed_collection_control privilege. This can be assigned by adding a file to /etc/clickhouse-server/users.d/. The example gives the user default both the access_management and named_collection_control privileges:
/etc/clickhouse-server/users.d/user_default.xml
Storage for named collections
Named collections can either be stored on local disk or in ZooKeeper/Keeper. By default local storage is used. They can also be stored using encryption with the same algorithms used for disk encryption, whereaes_128_ctr is used by default.
To configure named collections storage you need to specify a type. This can be either local or keeper/zookeeper. For encrypted storage,
you can use local_encrypted or keeper_encrypted/zookeeper_encrypted.
To use ZooKeeper/Keeper we also need to set up a path (path in ZooKeeper/Keeper, where named collections will be stored) to
named_collections_storage section in configuration file. The following example uses encryption and ZooKeeper/Keeper:
update_timeout_ms by default is equal to 5000.
Storing named collections in configuration files
XML example
/etc/clickhouse-server/config.d/named_collections.xml
key_1can always be overridden.key_2can never be overridden.urlcan be overridden or not depending on the value ofallow_named_collection_override_by_default.
Modifying named collections
Named collections that are created with DDL queries can be altered or dropped with DDL. Named collections created with XML files can be managed by editing or deleting the corresponding XML.Alter a DDL named collection
Change or add the keyskey1 and key3 of the collection collection2
(this will not change the value of the overridable flag for those keys):
key1 and allow it to be always overridden:
key2 from collection2:
key1 and delete the key key3 of the collection collection2:
overridable flag, you have to
remove and re-add the key.
Drop the DDL named collection collection2:
Named collections for accessing S3
The description of parameters see s3 Table Function.DDL example
XML example
s3() function and S3 Table named collection examples
Both of the following examples use the same named collections3_mydata:
s3() function
S3 table
Named collections for accessing MySQL database
The description of parameters see mysql.DDL example
XML example
mysql() function, MySQL table, MySQL database, and Dictionary named collection examples
The four following examples use the same named collectionmymysql:
mysql() function
The named collection does not specify the
table parameter, so it is specified in the function call as table = 'test'.MySQL table
The DDL overrides the named collection setting for connection_pool_size.
MySQL database
MySQL Dictionary
Named collections for accessing PostgreSQL database
The description of parameters see postgresql. Additionally, there are aliases:usernameforuserdbfordatabase.
addresses_expr is used in a collection instead of host:port. The parameter is optional, because there are other optional ones: host, hostname, port. The following pseudo code explains the priority:
Example of using named collections with the postgresql function
Example of using named collections with database with engine PostgreSQL
PostgreSQL copies data from the named collection when the table is being created. A change in the collection does not affect the existing tables.
Example of using named collections with database with engine PostgreSQL
Example of using named collections with a dictionary with source POSTGRESQL
Named collections for accessing a remote ClickHouse database
The description of parameters see remote. Example of configuration:secure is not needed for connection because of remoteSecure, but it can be used for dictionaries.
Example of using named collections with the remote/remoteSecure functions
Example of using named collections with a dictionary with source ClickHouse
Named collections for accessing Kafka
The description of parameters see Kafka.DDL example
XML example
Example of using named collections with a Kafka table
Both of the following examples use the same named collectionmy_kafka_cluster:
Named collections for backups
For the description of parameters see Backup and Restore.DDL example
XML example
Named collections for accessing MongoDB Table and Dictionary
For the description of parameters see mongodb.DDL example
XML example
MongoDB table
The DDL overrides the named collection setting for options.
MongoDB Dictionary
The named collection specifies
my_collection for the collection name. In the function call it is overwritten by collection = 'my_dict' to select another collection.