Skip to content

Instantly share code, notes, and snippets.

Last active February 25, 2021 10:11
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?

When you a clickhouse cluster and you run queries on all the replicas it's not easy to get all the queries ran. I use system.query_log all the time to check timings, errors and so on.

So what I do is create a global query_log:

:) create view query_log_all on cluster my_cluster as select * from remote(',', 'system.query_log')

So I can inspect queries in all the replicas with a single query:

    toStartOfHour(query_start_time) AS hour,
    count() AS c,
FROM query_log_all
WHERE query_start_time > (now() - toIntervalHour(24))

│ 2021-02-24 11:00:0020288118.4436119873817 │
│ 2021-02-24 12:00:001594285.94304353280643 │
│ 2021-02-24 22:00:002544851.757387613957874 │
│ 2021-02-25 07:00:003100659.56853512223441 │
│ 2021-02-24 20:00:001298858.15121650754543 │

You can add as many ip addresses as you replicas you have. You can get that list with the following SQL.

select arrayStringConcat(groupArray(host_name), ',') as hosts from system.clusters where cluster = 'my_cluster'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment