Skip to content

on_cluster clause in optimize table query throws syntax error - #255

Merged
bakwc merged 5 commits into
bakwc:masterfrom
iamtalhaasghar:optimize-bug
Mar 25, 2026
Merged

on_cluster clause in optimize table query throws syntax error#255
bakwc merged 5 commits into
bakwc:masterfrom
iamtalhaasghar:optimize-bug

Conversation

@iamtalhaasghar

Copy link
Copy Markdown
Contributor

fixes following bug:

2026.03.25 12:16:28.382791 [ 1224350 ] {7265776f-53f7-4feb-9ea7-f4f9e0ac4cbc} <Error> DynamicQueryHandler: Code: 62. DB::Exception: Syntax error: failed at position 51 (ON): ON CLUSTER {redacted} SETTINGS mutations_sync = 2. Expected one of: DEDUPLICATE, CLEANUP, INTO OUTFILE, FORMAT, SETTINGS, ParallelWithClause, PARALLEL WITH, end of query. (SYNTAX_ERROR)

Wrong:
optimize table db.table_name final on cluster cluster_name settings {....}

Correct:
optimize table db.table_name final settings {....}

Have also added alter_sync=2 to tell clickhouse client to wait for optimize query to successfully complete on replica nodes as well.

https://clickhouse.com/docs/sql-reference/statements/optimize

When OPTIMIZE is used with the ReplicatedMergeTree family of table engines, ClickHouse creates a task for merging and waits for execution on all replicas (if the alter_sync setting is set to 2)

https://clickhouse.com/docs/operations/settings/settings#alter_sync

Allows you to specify the wait behavior for actions that are to be executed on replicas by ALTER, OPTIMIZE or TRUNCATE queries.

Possible values:

0 — Do not wait.
1 — Wait for own execution.
2 — Wait for everyone.
3 - Only wait for active replicas.

Cloud default value: 0.

Added note about adjusting timezone for Docker container.
fetch upstream changes
optimize table query doesnt allow on_cluster clause
@iamtalhaasghar
iamtalhaasghar marked this pull request as draft March 25, 2026 09:24
@iamtalhaasghar
iamtalhaasghar marked this pull request as ready for review March 25, 2026 09:29
@bakwc
bakwc merged commit 9f0a6df into bakwc:master Mar 25, 2026
1 check passed
@iamtalhaasghar
iamtalhaasghar deleted the optimize-bug branch March 25, 2026 12:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants