Configuration
Profiling
#### Enable Profiling {#docs:configuration:pragmas::enable-profiling}  
The following query enables profiling with the default format, `query_tree`.
Independent of the format, `enable_profiling` is **mandatory** to enable profiling.  
```sql
PRAGMA enable_profiling;
PRAGMA enable_profile;
```  
###### Profiling Format {#docs:configuration:pragmas::profiling-format}  
The format of `enable_profiling` can be specified as `query_tree`, `json`, `query_tree_optimizer`, or `no_output`.
Each format prints its output to the configured output, except `no_output`.  
The default format is `query_tree`.
It prints the physical query plan and the metrics of each operator in the tree.  
```sql
SET enable_profiling = 'query_tree';
```  
Alternatively, `json` returns the physical query plan as JSON:  
```sql
SET enable_profiling = 'json';
```  
To return the physical query plan, including optimizer and planner metrics:  
```sql
SET enable_profiling = 'query_tree_optimizer';
```  
Database drivers and other applications can also access profiling information through API calls, in which case users can disable any other output.
Even though the parameter reads `no_output`, it is essential to note that this **only** affects printing to the configurable output.
When accessing profiling information through API calls, it is still crucial to enable profiling:  
```sql
SET enable_profiling = 'no_output';
```  
#### Profiling Output {#docs:configuration:pragmas::profiling-output}  
By default, DuckDB prints profiling information to the standard output.
However, if you prefer to write the profiling information to a file, you can use `PRAGMA` `profiling_output` to specify a filepath.  
> **Warning.  ** The file contents will be overwritten for every newly issued query.
> Hence, the file will only contain the profiling information of the last run query:  
```sql
SET profiling_output = '/path/to/file.json';
SET profile_output = '/path/to/file.json';
```  
#### Profiling Mode {#docs:configuration:pragmas::profiling-mode}  
By default, a limited amount of profiling information is provided (` standard`).  
```sql
SET profiling_mode = 'standard';
```  
For more details, use the detailed profiling mode by setting `profiling_mode` to `detailed`.
The output of this mode includes profiling of the planner and optimizer stages.  
```sql
SET profiling_mode = 'detailed';
```  
#### Custom Metrics {#docs:configuration:pragmas::custom-metrics}  
By default, profiling enables all metrics except those activated by detailed profiling.  
Using the `custom_profiling_settings` `PRAGMA`, each metric, including those from detailed profiling, can be individually enabled or disabled.
This `PRAGMA` accepts a JSON object with metric names as keys and Boolean values to toggle them on or off.
Settings specified by this `PRAGMA` override the default behavior.  
> **Note.  ** This only affects the metrics when the `enable_profiling` is set to `json` or `no_output`.
> The `query_tree` and `query_tree_optimizer` always use a default set of metrics.  
In the following example, the `CPU_TIME` metric is disabled.
The `EXTRA_INFO`, `OPERATOR_CARDINALITY`, and `OPERATOR_TIMING` metrics are enabled.  
```sql
SET custom_profiling_settings = '{"CPU_TIME": "false", "EXTRA_INFO": "true", "OPERATOR_CARDINALITY": "true", "OPERATOR_TIMING": "true"}';
```  
The profiling documentation contains an overview of the available [metrics](#docs:dev:profiling::metrics).  
#### Disable Profiling {#docs:configuration:pragmas::disable-profiling}  
To disable profiling:  
```sql
PRAGMA disable_profiling;
PRAGMA disable_profile;
```