Back to blog
Optimizing Database Queries in Magento
Nipul Purohit
8 min read
Magento 2
Database
Performance
# Optimizing Database Queries in Magento
Slow queries are a common performance bottleneck in large-scale Magento 2 deployments. Database profiling and index optimization can improve your API and frontend load times significantly.
## Profiling Slow Queries
To find bottlenecks, enable the Magento database profiler in `app/etc/env.php`:
```php
'db' => [
'connection' => [
'default' => [
'profiler' => [
'class' => '\Magento\Framework\DB\Profiler',
'enabled' => true
]
]
]
]
```
Alternatively, use MySQL's Slow Query Log to track queries taking longer than 1 second.
Slow queries are a common performance bottleneck in large-scale Magento 2 deployments. Database profiling and index optimization can improve your API and frontend load times significantly.
## Profiling Slow Queries
To find bottlenecks, enable the Magento database profiler in `app/etc/env.php`:
```php
'db' => [
'connection' => [
'default' => [
'profiler' => [
'class' => '\Magento\Framework\DB\Profiler',
'enabled' => true
]
]
]
]
```
Alternatively, use MySQL's Slow Query Log to track queries taking longer than 1 second.