Skip to content

clickhouse: updates to system.query_log ttl don't survive restart #10444

@jmcarp

Description

@jmcarp

Our static clickhouse config sets a seven-day ttl on system.query_log:

    <query_log>
        <database>system</database>
        <table>query_log</table>
        <engine>Engine = MergeTree ORDER BY event_time TTL event_date + INTERVAL 7 DAY</engine>
        <flush_interval_milliseconds>10000</flush_interval_milliseconds>
    </query_log>

In #10366, we added support for setting table ttls via clickhouse-admin/omdb. This path uses ALTER TABLE...MODIFY TTL to update ttls for both oximeter tables and system.query_log. This works as intended for oximeter tables, and works initially for system tables. However, on clickhouse restart, clickhouse observes that the structure of system.query_log doesn't match the config.xml, aliases the existing system.query_log to system.query_log_1, and creates a new system.query_log with a seven-day ttl. So the ttl set by the user (specifically, support) only lasts until the next clickhouse restart, and we have potentially many log tables.

I think the "correct" fix would involve persisting retention policies in crdb, then propagating that setting to the clickhouse config.xml. That also sounds like a non-trivial change for a small benefit. In the interim, I wonder if it would make more sense to (1) pick a shorter default ttl for system.query_log, given we probably rarely/never look at it, and (2) exclude system.query_log from the retention policy logic in clickhouse-admin, given it's not currently persistent.

Note: I'm proposing a related change in #10443 that makes the query log table much smaller for read-heavy workloads, such as scraping oximeter for current metrics. That might make this issue less urgent, although we still have a bug in that setting query log ttl isn't persistent.

Another note: thinking about it more, if we do decide to properly expose the query log ttl to omdb/users, I think we should allow setting different ttls for oximeter tables and system tables. By default, we default to 30d for measurements and 7d for query logs, and I think it's not ideal to force users to couple those ttls if they want to update either of them.

cc @bnaecker

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions