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
- Find the Keeper path of the current table:
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.
- Create the new credentials in your cloud provider. Keep the old ones valid until the last step.
-
Create a second table with the new credentials and the path from step 1. Copy everything else from
SHOW CREATE TABLE s3_events_queue:
- Pause the table with the old credentials:
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.
- Swap the names of the two tables:
s3_events_queue_new, has no view attached and stays paused. A batch that it started before the exchange still goes through the view.
- Drop the table with the old credentials:
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.
- Revoke the old credentials.
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
orderedmode. SYSTEM PAUSEacts only on the server where you run it. If several servers have the table on the samekeeper_path, pause it on each of them before the exchange.- The rotation does not change which files are tracked. In the
unorderedmode, ClickHouse Keeper keeps the records of at mosttracked_files_limitprocessed files (1000 by default) and, iftracked_file_ttl_secis 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_retriestimes is recorded as failed and skipped, also by the new table. EXCHANGE TABLESworks only in databases whose engine supports it, such asAtomic. See theEXCHANGEstatement.- For an
S3Queuetable,ALTER TABLEaccepts onlyMODIFY SETTINGandRESET SETTING. Any otherALTERfails withOnly MODIFY/RESET SETTING alter is allowed for S3Queue, and the credentials are not a setting.
Related pages
S3Queuetable engine, including thekeeper_pathsettingEXCHANGEstatementsystem.s3_queue_settings