> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-mintlify-3a82795f.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> System table containing information about the dependent views executed when running a query, for example, the view type or the execution time.

# system.query_views_log

<Info>
  **Querying in ClickHouse Cloud**

  The data in this system table is held locally on each node in ClickHouse Cloud. Obtaining a complete view of all data, therefore, requires the `clusterAllReplicas` function. See [here](/reference/system-tables/overview#system-tables-in-clickhouse-cloud) for further details.
</Info>

<h2 id="description">
  Description
</h2>

Contains information about the dependent views executed when running a query, for example, the view type or the execution time.

To start logging:

1. Configure parameters in the [query\_views\_log](/reference/settings/server-settings/settings#query_views_log) section.
2. Set [log\_query\_views](/reference/settings/session-settings#log_query_views) to 1.

The flushing period of data is set in `flush_interval_milliseconds` parameter of the [query\_views\_log](/reference/settings/server-settings/settings#query_views_log) server settings section. To force flushing, use the [SYSTEM FLUSH LOGS](/reference/statements/system#flush-logs) query.

ClickHouse does not delete data from the table automatically. See [Introduction](/reference/system-tables/overview#system-tables-introduction) for more details.

You can use the [log\_queries\_probability](/reference/settings/session-settings#log_queries_probability)) setting to reduce the number of queries, registered in the `query_views_log` table.

<h2 id="columns">
  Columns
</h2>

* `hostname` ([LowCardinality(String)](/reference/data-types/lowcardinality)) — Hostname of the server executing the query.
* `event_date` ([Date](/reference/data-types/date)) — The date when the last event of the view happened.
* `event_time` ([DateTime](/reference/data-types/datetime)) — The date and time when the view finished execution.
* `event_time_microseconds` ([DateTime64(6)](/reference/data-types/datetime64)) — The date and time when the view finished execution with microseconds precision.
* `view_duration_ms` ([UInt64](/reference/data-types/int-uint)) — Duration of view execution (sum of its stages) in milliseconds.
* `initial_query_id` ([String](/reference/data-types/string)) — ID of the initial query (for distributed query execution).
* `view_name` ([String](/reference/data-types/string)) — Name of the view.
* `view_uuid` ([UUID](/reference/data-types/uuid)) — UUID of the view.
* `view_type` ([Enum8('Default' = 1, 'Materialized' = 2, 'Live' = 3, 'Window' = 4)](/reference/data-types/enum)) — Type of the view. Values: 'Default' = 1 — Default views. Should not appear in this log, 'Materialized' = 2 — Materialized views, 'Live' = 3 — Live views.
* `view_query` ([String](/reference/data-types/string)) — The query executed by the view.
* `view_target` ([String](/reference/data-types/string)) — The name of the view target table.
* `read_rows` ([UInt64](/reference/data-types/int-uint)) — Number of read rows.
* `read_bytes` ([UInt64](/reference/data-types/int-uint)) — Number of read bytes.
* `written_rows` ([UInt64](/reference/data-types/int-uint)) — Number of written rows.
* `written_bytes` ([UInt64](/reference/data-types/int-uint)) — Number of written bytes.
* `peak_memory_usage` ([Int64](/reference/data-types/int-uint)) — The maximum difference between the amount of allocated and freed memory in context of this view.
* `ProfileEvents` ([Map(LowCardinality(String), UInt64)](/reference/data-types/map)) — ProfileEvents that measure different metrics. The description of them could be found in the table system.events.
* `status` ([Enum8('QueryStart' = 1, 'QueryFinish' = 2, 'ExceptionBeforeStart' = 3, 'ExceptionWhileProcessing' = 4)](/reference/data-types/enum)) — Status of the view. Values: 'QueryStart' = 1 — Successful start the view execution. Should not appear, 'QueryFinish' = 2 — Successful end of the view execution, 'ExceptionBeforeStart' = 3 — Exception before the start of the view execution., 'ExceptionWhileProcessing' = 4 — Exception during the view execution.
* `exception_code` ([Int32](/reference/data-types/int-uint)) — Code of an exception.
* `exception` ([String](/reference/data-types/string)) — Exception message.
* `stack_trace` ([String](/reference/data-types/string)) — Stack trace. An empty string, if the query was completed successfully.

**Aliases:**

* `ProfileEvents.Names` — Alias for `mapKeys(ProfileEvents)`.
* `ProfileEvents.Values` — Alias for `mapValues(ProfileEvents)`.

<h2 id="example">
  Example
</h2>

```sql title="Query" theme={null}
SELECT * FROM system.query_views_log LIMIT 1 \G;
```

```text title="Response" theme={null}
Row 1:
──────
hostname:                clickhouse.eu-central1.internal
event_date:              2021-06-22
event_time:              2021-06-22 13:23:07
event_time_microseconds: 2021-06-22 13:23:07.738221
view_duration_ms:        0
initial_query_id:        c3a1ac02-9cad-479b-af54-9e9c0a7afd70
view_name:               default.matview_inner
view_uuid:               00000000-0000-0000-0000-000000000000
view_type:               Materialized
view_query:              SELECT * FROM default.table_b
view_target:             default.`.inner.matview_inner`
read_rows:               4
read_bytes:              64
written_rows:            2
written_bytes:           32
peak_memory_usage:       4196188
ProfileEvents:           {'FileOpen':2,'WriteBufferFromFileDescriptorWrite':2,'WriteBufferFromFileDescriptorWriteBytes':187,'IOBufferAllocs':3,'IOBufferAllocBytes':3145773,'FunctionExecute':3,'DiskWriteElapsedMicroseconds':13,'InsertedRows':2,'InsertedBytes':16,'SelectedRows':4,'SelectedBytes':48,'ContextLock':16,'RWLockAcquiredReadLocks':1,'RealTimeMicroseconds':698,'SoftPageFaults':4,'OSReadChars':463}
status:                  QueryFinish
exception_code:          0
exception:
stack_trace:
```

<h2 id="see-also">
  See Also
</h2>

{/*AUTOGENERATED_END*/}
