How to get value of a FLAG in ClickHouse
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
In ClickHouse, a "flag" is usually a runtime setting such as memory limits, thread usage, or read-only behavior. Getting the current value is straightforward, but it is important to know whether you are reading session-level or server-level configuration. This guide shows reliable queries and explains how settings change across scopes.
Query Settings from system.settings
The primary way to inspect flags is the system.settings table. It includes the current value for the active session and whether it differs from default.
Important columns:
valueis the current effective value for your sessiondefaultis the built-in default valuechangedindicates whether session value differs from default
This is the best first query when troubleshooting unexpected query behavior.
Read Multiple Related Flags at Once
Performance or safety issues usually involve multiple settings, not one flag. Query several relevant settings together.
This avoids piecemeal debugging and gives a consistent snapshot of your current session state.
Get Value in Expressions with getSetting
When writing diagnostic queries, getSetting is useful because it returns setting values directly in expressions.
You can combine settings with computed metadata for quick audits.
Understand Session vs Server Configuration
A frequent confusion is reading a setting after SET and assuming it changed globally. In most cases, SET updates only current session.
Open a new session and you may see a different value. Global defaults usually come from server config files or user profiles.
Inspect User and Profile-Level Constraints
ClickHouse can override settings by user profile, quotas, or roles. If a flag appears fixed, the profile may enforce constraints.
Also inspect profile metadata on your deployment if available in system tables. Managed environments may restrict direct config access, so check admin documentation for profile mapping.
Boolean and Enum-Like Flags
Some settings behave like booleans represented as numeric values. For example, readonly often uses integer values.
Always confirm expected value semantics in your ClickHouse version, because meanings can vary for specific flags.
Practical Troubleshooting Workflow
When queries behave unexpectedly:
- capture relevant settings from
system.settings - compare across working and failing sessions
- check user profile or role differences
- test controlled overrides with
SETin one session
This workflow isolates whether issue is SQL logic, configuration, or permission policy.
Persisting and Auditing Setting Changes
If a setting must remain stable across sessions, persist it through user profile or server configuration rather than repeated SET in client code. Keep a small audit query that records effective values at job startup to simplify incident analysis when behavior changes after deployment.
Common Pitfalls
- Assuming
SETmodifies server-wide behavior for all users. - Inspecting one setting while related limits remain unchanged.
- Ignoring user profile restrictions that override session intent.
- Treating all numeric settings as simple booleans without verifying semantics.
- Comparing behavior across sessions without capturing setting snapshots.
Summary
- Use
system.settingsto read active flag values and defaults. - Use
getSettingfor inline diagnostics in SQL queries. - Distinguish session-level changes from server or profile defaults.
- Check user/profile constraints when settings appear immutable.
- Capture grouped setting snapshots for faster troubleshooting and reproducibility.
Related reading
- How to grant all privileges to root user in MySQL 8.0
- How to grant remote access permissions to mysql server for user?
- How to group nearby latitude and longitude locations stored in SQL
- How to handle consensus in a decentralized event sourced database?
- How to handle data migrations in distributed microservice databases
- How to handle database migrations in Spring Boot with Hibernate?
- How to handle database migrations with Kubernetes and Skaffold
- How to handle many to many in DynamoDB

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.