Skip to main content
The credentials of an S3Queue table are engine arguments, and ALTER TABLE can change only the settings of the table. To switch to new credentials, create a second S3Queue table with the new credentials on the same keeper_path, pause the old table, swap the two tables with EXCHANGE TABLES, and drop the old one. The record of which files are processed is stored in ClickHouse Keeper under keeper_path, so the new table continues where the old one stopped and skips the files that are recorded there as processed.

Starting point

The steps below assume a queue, a target table and a materialized view like these:

Steps

  1. Find the Keeper path of the current table:
The query returns the path that the table uses, also when keeper_path was not set in CREATE TABLE. In that case the path consists of the s3queue_default_zookeeper_path setting (/clickhouse/s3queue/ by default), the UUID of the database and the UUID of the table. system.s3_queue_settings is available from ClickHouse 24.10. On older versions, run SHOW CREATE TABLE s3_events_queue: if it contains an explicit keeper_path, use that value. Otherwise, construct the default path from the uuid columns of system.databases and system.tables.
  1. Create the new credentials in your cloud provider. Keep the old ones valid until the last step.
  2. Create a second table with the new credentials and the path from step 1. Copy everything else from SHOW CREATE TABLE s3_events_queue:
The new table reads nothing yet, because no materialized view selects from it.
  1. Pause the table with the old credentials:
The table finishes the batch of files that it is processing and starts no new one. Do not skip this step. A table that is working through a backlog does not notice that the next step takes its materialized view away: it keeps processing files, their rows are inserted nowhere, and the files are still recorded as processed, so the new table never reads them. SYSTEM PAUSE works for S3Queue tables from ClickHouse 26.8. On an earlier version, run the next step only while the queue is idle: stop the uploads to the bucket and wait until every file is ingested.
  1. Swap the names of the two tables:
The materialized view refers to its source by name, so it now reads from the table with the new credentials, which starts to process files. The table with the old credentials is now called s3_events_queue_new, has no view attached and stays paused. A batch that it started before the exchange still goes through the view.
  1. Drop the table with the old credentials:
If the table is still in the middle of its last batch, DROP TABLE interrupts it, and the new table reads the files that the batch did not record as processed, from their beginning. The state in Keeper is kept, because another table is still registered on the path. ClickHouse removes it only when the last table that uses the path is dropped.
  1. Revoke the old credentials.
To check the result, run SHOW CREATE TABLE s3_events_queue: it shows the new access key ID and the explicit keeper_path. For the next rotation, reuse the same keeper_path value.

What must match

Both tables describe the same queue, so ClickHouse compares the new definition with the one stored in Keeper. The URL (endpoint, bucket and path), the format, the columns, mode, after_processing, tracked_files_limit, tracked_file_ttl_sec and, in ordered mode, buckets must be the same. The credentials are not compared. If something differs, CREATE TABLE fails, for example:
CREATE TABLE does not compare the other settings, but do not use the new table to change them. Some settings, such as loading_retries and processing_threads_num, belong to the queue and not to the table: two tables on the same server share them, so the new table keeps the values of the existing one, although SHOW CREATE TABLE shows what you wrote. system.s3_queue_settings shows the values in effect. Copy the settings unchanged and change them after the rotation, for example with ALTER TABLE s3_events_queue MODIFY SETTING loading_retries = 5.

Things to know

  • The procedure is the same for the ordered mode.
  • SYSTEM PAUSE acts only on the server where you run it. If several servers have the table on the same keeper_path, pause it on each of them before the exchange.
  • The rotation does not change which files are tracked. In the unordered mode, ClickHouse Keeper keeps the records of at most tracked_files_limit processed files (1000 by default) and, if tracked_file_ttl_sec is set, only for that many seconds. A file that is still in the bucket when its record is removed is read again, with or without a rotation.
  • Do the exchange while the old credentials still work. Failed attempts to read a file are counted in Keeper under the shared path, and a file that fails loading_retries times is recorded as failed and skipped, also by the new table.
  • EXCHANGE TABLES works only in databases whose engine supports it, such as Atomic. See the EXCHANGE statement.
  • For an S3Queue table, ALTER TABLE accepts only MODIFY SETTING and RESET SETTING. Any other ALTER fails with Only MODIFY/RESET SETTING alter is allowed for S3Queue, and the credentials are not a setting.