The SETTING_CONSTRAINT_VIOLATION error is raised when a user tries to set a value that falls outside the boundaries defined by a profile's constraints. A typical message reads DB::Exception: Setting max_memory_usage shouldn't be greater than 10000000000. ClickHouse allows administrators to define minimum and maximum bounds for settings on a per-profile basis, and any attempt to exceed those bounds results in this error.
Impact
The query or SET statement that violates the constraint is rejected. This means the user cannot push a setting beyond the administratively defined limit for their profile. While this is a protective mechanism -- it prevents individual users from consuming excessive resources -- it can block legitimate workloads that genuinely need higher limits. The error is scoped to the specific session and does not affect other users or the server itself.
Common Causes
- Exceeding a
maxconstraint -- For example, trying to setmax_memory_usagehigher than the maximum defined in the user's profile. - Going below a
minconstraint -- Setting a value lower than the minimum bound, such as settingmax_execution_timeto 0 (unlimited) when the profile enforces a minimum. - Attempting to change a
constsetting -- A setting marked asconstin constraints cannot be changed at all. (This can also surface asREADONLY_SETTING, depending on the configuration.) - Profile inheritance confusion -- A user may inherit constraints from a parent profile without realizing it.
- Application defaults conflicting with server constraints -- Client libraries or BI tools may set default values that conflict with the constraints defined for the connecting user.
Troubleshooting and Resolution Steps
Identify the constraint that is being violated: The error message itself usually states the setting name and the bound. Check the current value and constraint:
SELECT name, value, min, max, readonly FROM system.settings WHERE name = 'max_memory_usage';The
minandmaxcolumns show the constraint boundaries. Thereadonlycolumn shows whether the setting can be modified at all.Review the profile constraints in configuration: Constraints are typically defined in
users.xmlor in SQL-based settings profiles:<profiles> <restricted_profile> <constraints> <max_memory_usage> <min>1000000</min> <max>10000000000</max> </max_memory_usage> </constraints> </restricted_profile> </profiles>Adjust the constraint if appropriate: If you are an administrator and the user legitimately needs a higher (or lower) limit, modify the constraint:
-- SQL-based access control ALTER SETTINGS PROFILE 'restricted_profile' SETTINGS max_memory_usage = 10000000000 MIN 1000000 MAX 20000000000;Or edit the XML configuration and reload:
# After editing users.xml clickhouse-client --query "SYSTEM RELOAD CONFIG"Check profile inheritance:
SELECT * FROM system.settings_profile_elements WHERE profile_name = 'your_profile';Constraints may come from a parent profile. Trace the chain to find where the limit is defined.
Adjust the query to work within constraints: If you cannot change the constraints, optimize your query to work within the limits. For
max_memory_usageconstraints, consider usingmax_bytes_before_external_sortormax_bytes_before_external_group_byto spill to disk rather than exceeding memory limits.Create a dedicated profile for special workloads: Rather than raising limits globally, create a separate profile with higher bounds and assign it only to the users or service accounts that need it.
Best Practices
- Use constraints to enforce resource governance, especially in multi-tenant ClickHouse deployments.
- Set
minandmaxbounds rather than usingconst, so users retain some flexibility within safe limits. - Document constraint values for each profile and communicate them to users.
- Monitor queries that hit constraint violations -- they may indicate workloads that need optimization rather than higher limits.
- Prefer profile-based constraints over application-level enforcement, as they cannot be bypassed by the client.
Frequently Asked Questions
Q: How do I see all constraints that apply to my current session?
A: Run SELECT name, value, min, max, readonly FROM system.settings WHERE min != '' OR max != '' OR readonly = 1. This shows every setting that has bounds or is locked for your session.
Q: What happens if I set a value exactly equal to the min or max bound?
A: The bounds are inclusive. Setting a value equal to min or max is allowed and will not trigger the error.
Q: Can constraints be applied per-query rather than per-profile?
A: No. Constraints are defined at the profile level and apply to all sessions using that profile. However, you can assign different profiles to different users to achieve per-user granularity.
Q: Is there a way to temporarily bypass constraints for debugging?
A: Not from the constrained session itself. An administrator would need to temporarily modify the profile or connect with a different user that has a less restrictive profile. Always revert changes after debugging.
Q: Do constraints apply to settings in CREATE TABLE ... SETTINGS?
A: No. Profile-level constraints apply to session and query settings, not to MergeTree table-level settings specified in DDL statements.