Skip to content

Add table_readonly MergeTree setting - #97652

Merged
alexey-milovidov merged 6 commits into
masterfrom
table-readonly-setting
Mar 1, 2026
Merged

alexey-milovidov merged 6 commits into
masterfrom
table-readonly-setting

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Feb 22, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Add a new table_readonly MergeTree setting that marks a table as read-only
  • When enabled, inserts and mutations are rejected with TABLE_IS_READ_ONLY
  • ALTER MODIFY SETTING / RESET SETTING are still allowed so the flag can be toggled back
  • When table_readonly is set, outdated parts are not loaded on startup since the table will never own them

This setting is split out from #95079 to be introduced independently of its usage in system log rotation.

Changelog category (leave one):

  • New Feature

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Add table_readonly MergeTree setting to mark tables as read-only, preventing inserts and modifications.

🤖 Generated with Claude Code

Version info

  • Merged into: 26.3.1.175

@clickhouse-gh

clickhouse-gh Bot commented Feb 22, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [47efe38]

Summary: ✅

@clickhouse-gh clickhouse-gh Bot added the pr-feature Pull request with new product feature label Feb 22, 2026
@ClickHouse ClickHouse deleted a comment from CLAassistant Feb 22, 2026
@alexey-milovidov
alexey-milovidov force-pushed the table-readonly-setting branch 2 times, most recently from 757ff0c to 0fa4655 Compare February 22, 2026 20:06
@ClickHouse ClickHouse deleted a comment from CLAassistant Feb 23, 2026
@alexey-milovidov
alexey-milovidov marked this pull request as draft February 23, 2026 13:11
alexey-milovidov and others added 2 commits February 27, 2026 21:50
Add a new `table_readonly` MergeTree setting that marks a table as
read-only. When enabled, inserts and mutations are rejected with
`TABLE_IS_READ_ONLY`. ALTER MODIFY SETTING / RESET SETTING are still
allowed so the flag can be toggled back.

When `table_readonly` is set, outdated parts are not loaded on startup
since the table will never own them.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@alexey-milovidov
alexey-milovidov marked this pull request as ready for review February 27, 2026 20:50
alexey-milovidov and others added 4 commits February 27, 2026 23:19
… history

The merge of master into the branch left a duplicate `table_readonly`
entry in the 26.2 section (it belongs only in 26.3), along with a
missing comma causing a syntax error.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@alexey-milovidov alexey-milovidov self-assigned this Mar 1, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Mar 1, 2026
Merged via the queue into master with commit 6d5c18b Mar 1, 2026
144 checks passed
@alexey-milovidov
alexey-milovidov deleted the table-readonly-setting branch March 1, 2026 00:45
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Mar 1, 2026
alexey-milovidov added a commit that referenced this pull request Mar 1, 2026
Add `table_readonly` MergeTree setting
@PedroTadim

PedroTadim commented Mar 3, 2026 •

Copy link
Copy Markdown
Member

With:

<remote_servers>
    <cluster0>
        <shard>
            <replica>
                <host>localhost</host>
                <port>9000</port>
            </replica>
        </shard>
    </cluster0>
</remote_servers>

If I run:

CREATE TABLE t0 ON CLUSTER 'cluster0' (c0 Int) ENGINE = MergeTree() ORDER BY tuple() SETTINGS table_readonly = 1;
OPTIMIZE TABLE t0 ON CLUSTER 'cluster0'; --hangs

Is this expected? Maybe not.

2026.03.03 16:04:14.415352 [ 2760653 ] {09e6f386-acdf-4d36-9b9d-dd4129d0afb3} <Error> executeQuery: Code: 242. DB::Exception: Table is in readonly mode. (TABLE_IS_READ_ONLY) (version 26.3.1.331 (official build)) (from 0.0.0.0:0) (in query: /* ddl_entry=query-0000000001 */ OPTIMIZE TABLE default.t0), Stack trace (when copying this message, always include the lines below):

0. contrib/llvm-project/libcxx/include/__exception/exception.h:113:14: Poco::Exception::Exception(String&&, int) @ 0x0000000026705233
1. src/Common/Exception.cpp:139:7: DB::Exception::Exception(DB::Exception::MessageMasked&&, int, bool) @ 0x00000000160f9e69
2. src/Common/Exception.h:171:100: DB::Exception::Exception(String&&, int, String, bool) @ 0x000000000e165d94
3. src/Common/Exception.h:57:54: DB::Exception::Exception(PreformattedMessage&&, int) @ 0x000000000e165891
4. src/Common/Exception.h:189:77: DB::Exception::Exception<>(int, FormatStringHelperImpl<>) @ 0x00000000160ff0b9
5. src/Storages/StorageMergeTree.cpp:3136:15: DB::StorageMergeTree::assertNotReadonly() const @ 0x000000001f213e63
6. src/Storages/StorageMergeTree.cpp:1963:5: DB::StorageMergeTree::optimize(boost::intrusive_ptr<DB::IAST> const&, std::shared_ptr<DB::StorageInMemoryMetadata const> const&, boost::intrusive_ptr<DB::IAST> const&, bool, bool, std::vector<String, std::allocator<String>> const&, bool, std::shared_ptr<DB::Context const>) @ 0x000000001f22b57d
7. src/Interpreters/InterpreterOptimizeQuery.cpp:112:12: DB::InterpreterOptimizeQuery::execute() @ 0x000000001c824a0e
8. src/Interpreters/executeQuery.cpp:1751:40: DB::executeQueryImpl(char const*, char const*, std::shared_ptr<DB::Context>, DB::QueryFlags, DB::QueryProcessingStage::Enum, std::unique_ptr<DB::ReadBuffer, std::default_delete<DB::ReadBuffer>>&, boost::intrusive_ptr<DB::IAST>&, std::shared_ptr<DB::ImplicitTransactionControlExecutor>, std::function<void ()>, DB::QueryResultDetails&) @ 0x000000001c7b463b
9. src/Interpreters/executeQuery.cpp:2307:19: DB::executeQuery(std::unique_ptr<DB::ReadBuffer, std::default_delete<DB::ReadBuffer>>, DB::WriteBuffer&, std::shared_ptr<DB::Context>, std::function<void (DB::QueryResultDetails const&)>, DB::QueryFlags, std::optional<DB::FormatSettings> const&, std::function<void (DB::IOutputFormat&, String const&, std::shared_ptr<DB::Context const> const&, std::optional<DB::FormatSettings> const&)>, std::function<void ()>, std::function<void ()>) @ 0x000000001c7ba6da
10. src/Interpreters/executeQuery.cpp:2169:5: DB::executeQuery(DB::ReadBuffer&, DB::WriteBuffer&, std::shared_ptr<DB::Context>, std::function<void (DB::QueryResultDetails const&)>, DB::QueryFlags, std::optional<DB::FormatSettings> const&, std::function<void (DB::IOutputFormat&, String const&, std::shared_ptr<DB::Context const> const&, std::optional<DB::FormatSettings> const&)>, std::function<void ()>, std::function<void ()>) @ 0x000000001c7ba02b
11. src/Interpreters/DDLWorker.cpp:556:9: DB::DDLWorker::tryExecuteQuery(DB::DDLTaskBase&, std::shared_ptr<zkutil::ZooKeeper> const&, bool) @ 0x000000001c250d91
12. src/Interpreters/DDLWorker.cpp:726:30: DB::DDLWorker::processTask(DB::DDLTaskBase&, std::shared_ptr<zkutil::ZooKeeper> const&, bool) @ 0x000000001c24eb32
13. src/Interpreters/DDLWorker.cpp:499:13: DB::DDLWorker::scheduleTasks(bool) @ 0x000000001c24ba45
14. src/Interpreters/DDLWorker.cpp:1260:13: DB::DDLWorker::runMainThread() @ 0x000000001c24254c
15. contrib/llvm-project/libcxx/include/__type_traits/invoke.h:0: ThreadFromGlobalPoolImpl<true, true>::ThreadFromGlobalPoolImpl<void (DB::DDLWorker::*)(), DB::DDLWorker*>(void (DB::DDLWorker::*&&)(), DB::DDLWorker*&&)::'lambda'()::operator()() @ 0x000000001c26951f
16. contrib/llvm-project/libcxx/include/__functional/function.h:508:12: ? @ 0x0000000016277d43
17. contrib/llvm-project/libcxx/include/__type_traits/invoke.h:0: void* std::__thread_proxy[abi:se210105]<std::tuple<std::unique_ptr<std::__thread_struct, std::default_delete<std::__thread_struct>>, void (ThreadPoolImpl<std::thread>::ThreadFromThreadPool::*)(), ThreadPoolImpl<std::thread>::ThreadFromThreadPool*>>(void*) @ 0x000000001627eb8e
18. start_thread @ 0x000000000009caa4
19. __clone3 @ 0x0000000000129c6c

2026.03.03 16:04:14.415478 [ 2760653 ] {09e6f386-acdf-4d36-9b9d-dd4129d0afb3} <Error> DDLWorker: Query /* ddl_entry=query-0000000001 */ OPTIMIZE TABLE default.t0 wasn't finished successfully, retriable true: Code: 242. DB::Exception: Table is in readonly mode. (TABLE_IS_READ_ONLY), Stack trace (when copying this message, always include the lines below):

0. contrib/llvm-project/libcxx/include/__exception/exception.h:113:14: Poco::Exception::Exception(String&&, int) @ 0x0000000026705233
1. src/Common/Exception.cpp:139:7: DB::Exception::Exception(DB::Exception::MessageMasked&&, int, bool) @ 0x00000000160f9e69
2. src/Common/Exception.h:171:100: DB::Exception::Exception(String&&, int, String, bool) @ 0x000000000e165d94
3. src/Common/Exception.h:57:54: DB::Exception::Exception(PreformattedMessage&&, int) @ 0x000000000e165891
4. src/Common/Exception.h:189:77: DB::Exception::Exception<>(int, FormatStringHelperImpl<>) @ 0x00000000160ff0b9
5. src/Storages/StorageMergeTree.cpp:3136:15: DB::StorageMergeTree::assertNotReadonly() const @ 0x000000001f213e63
6. src/Storages/StorageMergeTree.cpp:1963:5: DB::StorageMergeTree::optimize(boost::intrusive_ptr<DB::IAST> const&, std::shared_ptr<DB::StorageInMemoryMetadata const> const&, boost::intrusive_ptr<DB::IAST> const&, bool, bool, std::vector<String, std::allocator<String>> const&, bool, std::shared_ptr<DB::Context const>) @ 0x000000001f22b57d
7. src/Interpreters/InterpreterOptimizeQuery.cpp:112:12: DB::InterpreterOptimizeQuery::execute() @ 0x000000001c824a0e
8. src/Interpreters/executeQuery.cpp:1751:40: DB::executeQueryImpl(char const*, char const*, std::shared_ptr<DB::Context>, DB::QueryFlags, DB::QueryProcessingStage::Enum, std::unique_ptr<DB::ReadBuffer, std::default_delete<DB::ReadBuffer>>&, boost::intrusive_ptr<DB::IAST>&, std::shared_ptr<DB::ImplicitTransactionControlExecutor>, std::function<void ()>, DB::QueryResultDetails&) @ 0x000000001c7b463b
9. src/Interpreters/executeQuery.cpp:2307:19: DB::executeQuery(std::unique_ptr<DB::ReadBuffer, std::default_delete<DB::ReadBuffer>>, DB::WriteBuffer&, std::shared_ptr<DB::Context>, std::function<void (DB::QueryResultDetails const&)>, DB::QueryFlags, std::optional<DB::FormatSettings> const&, std::function<void (DB::IOutputFormat&, String const&, std::shared_ptr<DB::Context const> const&, std::optional<DB::FormatSettings> const&)>, std::function<void ()>, std::function<void ()>) @ 0x000000001c7ba6da
10. src/Interpreters/executeQuery.cpp:2169:5: DB::executeQuery(DB::ReadBuffer&, DB::WriteBuffer&, std::shared_ptr<DB::Context>, std::function<void (DB::QueryResultDetails const&)>, DB::QueryFlags, std::optional<DB::FormatSettings> const&, std::function<void (DB::IOutputFormat&, String const&, std::shared_ptr<DB::Context const> const&, std::optional<DB::FormatSettings> const&)>, std::function<void ()>, std::function<void ()>) @ 0x000000001c7ba02b
11. src/Interpreters/DDLWorker.cpp:556:9: DB::DDLWorker::tryExecuteQuery(DB::DDLTaskBase&, std::shared_ptr<zkutil::ZooKeeper> const&, bool) @ 0x000000001c250d91
12. src/Interpreters/DDLWorker.cpp:726:30: DB::DDLWorker::processTask(DB::DDLTaskBase&, std::shared_ptr<zkutil::ZooKeeper> const&, bool) @ 0x000000001c24eb32
13. src/Interpreters/DDLWorker.cpp:499:13: DB::DDLWorker::scheduleTasks(bool) @ 0x000000001c24ba45
14. src/Interpreters/DDLWorker.cpp:1260:13: DB::DDLWorker::runMainThread() @ 0x000000001c24254c
15. contrib/llvm-project/libcxx/include/__type_traits/invoke.h:0: ThreadFromGlobalPoolImpl<true, true>::ThreadFromGlobalPoolImpl<void (DB::DDLWorker::*)(), DB::DDLWorker*>(void (DB::DDLWorker::*&&)(), DB::DDLWorker*&&)::'lambda'()::operator()() @ 0x000000001c26951f
16. contrib/llvm-project/libcxx/include/__functional/function.h:508:12: ? @ 0x0000000016277d43
17. contrib/llvm-project/libcxx/include/__type_traits/invoke.h:0: void* std::__thread_proxy[abi:se210105]<std::tuple<std::unique_ptr<std::__thread_struct, std::default_delete<std::__thread_struct>>, void (ThreadPoolImpl<std::thread>::ThreadFromThreadPool::*)(), ThreadPoolImpl<std::thread>::ThreadFromThreadPool*>>(void*) @ 0x000000001627eb8e
18. start_thread @ 0x000000000009caa4
19. __clone3 @ 0x0000000000129c6c
 (version 26.3.1.331 (official build))
2026.03.03 16:04:14.420737 [ 2760653 ] {} <Error> DDLWorker: Unexpected error (65 times in a row), will try to restart main thread: Code: 341. DB::Exception: Unexpected error: Code: 242. DB::Exception: Table is in readonly mode. (TABLE_IS_READ_ONLY) (version 26.3.1.331 (official build)). (UNFINISHED), Stack trace (when copying this message, always include the lines below):

0. contrib/llvm-project/libcxx/include/__exception/exception.h:113:14: Poco::Exception::Exception(String&&, int) @ 0x0000000026705233
1. src/Common/Exception.cpp:139:7: DB::Exception::Exception(DB::Exception::MessageMasked&&, int, bool) @ 0x00000000160f9e69
2. src/Common/Exception.h:171:100: DB::Exception::Exception(String&&, int, String, bool) @ 0x000000000e165d94
3. src/Common/Exception.h:57:54: DB::Exception::Exception(PreformattedMessage&&, int) @ 0x000000000e165891
4. src/Common/Exception.h:189:77: DB::Exception::Exception<String&>(int, FormatStringHelperImpl<std::type_identity<String&>::type>, String&) @ 0x000000000e18aa43
5. src/Interpreters/DDLWorker.cpp:746:23: DB::DDLWorker::processTask(DB::DDLTaskBase&, std::shared_ptr<zkutil::ZooKeeper> const&, bool) @ 0x000000001c24f544
6. src/Interpreters/DDLWorker.cpp:499:13: DB::DDLWorker::scheduleTasks(bool) @ 0x000000001c24ba45
7. src/Interpreters/DDLWorker.cpp:1260:13: DB::DDLWorker::runMainThread() @ 0x000000001c24254c
8. contrib/llvm-project/libcxx/include/__type_traits/invoke.h:0: ThreadFromGlobalPoolImpl<true, true>::ThreadFromGlobalPoolImpl<void (DB::DDLWorker::*)(), DB::DDLWorker*>(void (DB::DDLWorker::*&&)(), DB::DDLWorker*&&)::'lambda'()::operator()() @ 0x000000001c26951f
9. contrib/llvm-project/libcxx/include/__functional/function.h:508:12: ? @ 0x0000000016277d43
10. contrib/llvm-project/libcxx/include/__type_traits/invoke.h:0: void* std::__thread_proxy[abi:se210105]<std::tuple<std::unique_ptr<std::__thread_struct, std::default_delete<std::__thread_struct>>, void (ThreadPoolImpl<std::thread>::ThreadFromThreadPool::*)(), ThreadPoolImpl<std::thread>::ThreadFromThreadPool*>>(void*) @ 0x000000001627eb8e
11. start_thread @ 0x000000000009caa4
12. __clone3 @ 0x0000000000129c6c

@alexey-milovidov

Copy link
Copy Markdown
Member Author

It's a minor problem - specifically about DDL queries in Replicated databases.

@alesapin

Copy link
Copy Markdown
Member

@alexey-milovidov but it has very weird behavior with replicated merge tree. It must be explicitly banned for all engines except ordinary MergeTree or it must be supported. Now someone can enable it for ReplicatedMergeTree and during startup table will not load oudated parts (which is crucial in some cases).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

post-rejected Should've been rejected, but got merged. pr-feature Pull request with new product feature pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants