
## Generate lineage

URL: https://docs.atlan.com/apps/connectors/database/clickhouse/how-tos/generate-lineage-with-clickhouse-miner

> Enable query logging and configure your ClickHouse instance so the ClickHouse Miner workflow can extract query history and generate lineage.

<!--vale off-->

# Generate lineage for ClickHouse assets 

<!--vale on-->

To generate lineage for your ClickHouse assets, the ClickHouse Miner reads query history from `system.query_log`. Before you run the miner, query logging must be enabled and the crawler user must have access to that table. Once that's in place, you can [run the miner](https://docs.atlan.com/llms/connectors/clickhouse/mine-clickhouse/llms.txt) to start building lineage.

## Before you begin

Make sure you have:

* Set up ClickHouse by following [Set up ClickHouse](https://docs.atlan.com/llms/connectors/clickhouse/set-up-clickhouse/llms.txt).
* Crawled ClickHouse metadata by following [Crawl ClickHouse](https://docs.atlan.com/llms/connectors/clickhouse/crawl-clickhouse/llms.txt).
* ClickHouse 21.8 or later (recommended for full `system.query_log` support).

## Generate lineage

Validate your ClickHouse environment so the miner can extract query history from `system.query_log`.

1. Confirm that query logging is enabled. ClickHouse enables the `query_log` table by default. Verify by running:

 ```sql
 SELECT count(*) FROM system.query_log;
 ```

 If this query returns an error, query logging may be disabled. Check your ClickHouse server configuration (`config.xml` or `config.d/`) and make sure the `<query_log>` section is present:

 ```xml
 <query_log>
 <database>system</database>
 <table>query_log</table>
 <flush_interval_milliseconds>7500</flush_interval_milliseconds>
 </query_log>
 ```

2. Grant the crawler user access to read from `system.query_log`.

 ```sql
 GRANT SELECT ON system.query_log TO {{username}};
 ```

 - Replace `{{username}}` with the ClickHouse user you configured when [setting up ClickHouse](https://docs.atlan.com/llms/connectors/clickhouse/set-up-clickhouse/llms.txt).

3. Verify that `system.query_log` is collecting data. Run a sample query and then check that it appears in the log:

 ```sql
 SELECT 1;
 SYSTEM FLUSH LOGS;
 SELECT count(*) FROM system.query_log WHERE event_date = today();
 ```

4. To limit the query log retention period, configure `query_log` TTL settings in your server configuration. The default TTL is sufficient for most deployments.

### Run miner

After you confirm query logging is enabled, create and run the **ClickHouse Miner** workflow to extract query history and generate lineage:

1. Follow [Mine ClickHouse](https://docs.atlan.com/llms/connectors/clickhouse/mine-clickhouse/llms.txt) to select the **ClickHouse Miner** package and configure connection and extraction method.
2. Run the miner once or on a schedule.

Once the miner completes, your existing ClickHouse assets are enriched with lineage from query history in `system.query_log`.

## Need help

If you need help configuring the miner or enabling query logging, contact Atlan Support by [submitting a request](https://docs.atlan.com/support/submit-request).

---
