Enable SQL Query Optimization
To enable the SQL Query Optimization feature, please select your installation type and follow the instructions below. Once enabled, you'll see the first automatic SQL Query Recommendation in one week.
- Linux
- AWS RDS
- GCP Cloud SQL
- Azure MySQL
- Docker
- Windows
Existing Linux Installation
Automatic Installation
Note: If your server is already installed, you can use automatic installation, as it won't add a new server if it has the same hostname.
Run the helper mode from the installer:
For MySQL/MariaDB/Percona Servers:
RELEEM_MYSQL_TYPE=1 bash -c "$(curl -L https://releem.s3.amazonaws.com/v2/install.sh)" enable_query_optimization
For PostgreSQL Servers:
RELEEM_PG_TYPE=1 bash -c "$(curl -L https://releem.s3.amazonaws.com/v2/install.sh)" enable_query_optimization
Use RELEEM_PG_TYPE=1 to explicitly select the PostgreSQL path, or RELEEM_MYSQL_TYPE=1 to explicitly select the MySQL path. Set RELEEM_PG_ROOT_LOGIN and RELEEM_PG_ROOT_PASSWORD when the PostgreSQL superuser is not available through peer/passwordless authentication. Set RELEEM_MYSQL_ROOT_LOGIN and RELEEM_MYSQL_ROOT_PASSWORD when the MySQL root user requires a password. If the password is omitted, the installer first tries passwordless access and then prompts for it in the console.
This command updates /opt/releem/releem.conf, enables query optimization, and prepares the required database permissions.
Manual Installation
If you prefer to update the agent manually:
MySQL/MariaDB/Percona Servers
- Grant additional permissions to the
releemuser. The SQL Query Optimization feature requires Additional Permissions for the Releem Agent user. - Add
query_optimization=truesetting to the/opt/releem/releem.conf. - Restart Releem Agent using the following command:
systemctl restart releem-agent - Run the following command:
/opt/releem/mysqlconfigurer.sh -p
PostgreSQL Servers
- Grant additional permissions to the
releemuser as a PostgreSQL superuser:Replace-- PostgreSQL 14+
GRANT pg_read_all_data TO releem;
-- PostgreSQL 12/13
GRANT CONNECT ON DATABASE "<database_name>" TO releem;
GRANT USAGE ON SCHEMA "<schema_name>" TO releem;
GRANT SELECT ON ALL TABLES IN SCHEMA "<schema_name>" TO releem;
GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA "<schema_name>" TO releem;<database_name>and<schema_name>with all monitored databases/schemas. For most self-managed deployments with a default database set, start withpostgresandpublic. - Add
query_optimization=truesetting to the/opt/releem/releem.conf. - Restart Releem Agent using the following command:
systemctl restart releem-agent - Run the following command to enable
pg_stat_statementssettings:/opt/releem/mysqlconfigurer.sh -p
New Linux Installation
Add this environment variable to the installation command:
RELEEM_QUERY_OPTIMIZATION=true
- Click "Add Server" link at Releem Customer Portal.
- Select the installation type.
- Modify the one-step installation command and the following environment variable:
RELEEM_QUERY_OPTIMIZATION=true - Run the modified installation command on your server.
- Grant additional permissions to the releem user. The SQL Query Optimization feature requires Additional Permissions for the Releem Agent user.
- Set the following MySQL variables in the Parameter Group to allow Releem to collect more queries for optimization:
performance_schema = 1
- Reboot the RDS instance if AWS marks the change as pending reboot.
- Enable query optimization in the agent:
If the agent is managed by CloudFormation, update the releem-agent stack and set QueryOptimization to true.
- Select CloudFormation Stack - releem-agent, click the Update button.
- Select "Replace existing template".
- Paste in "Amazon S3 URL" the URL
https://releem.s3.amazonaws.com/v2/releem-agent-cloudformation.ymland click Next. - Change the option "QueryOptimization" to true and click Next.
- Click Next and Submit.
If the agent runs in Docker, recreate the Docker container with RELEEM_QUERY_OPTIMIZATION=true environment variable enabled.
Ensure that the RELEEM_HOSTNAME variable should be the same as the currently added server.
If the agent runs on EC2, set query_optimization=true in /opt/releem/releem.conf and restart the service:
systemctl restart releem-agent
- Grant additional permissions to the releem user. The SQL Query Optimization feature requires Additional Permissions for the Releem Agent user.
- Enable Performance Schema in Cloud SQL database flags:
performance_schema = 1
- Restart the Cloud SQL instance if required.
- Enable query optimization in the agent:
If the agent runs in Docker, recreate the Docker container with RELEEM_QUERY_OPTIMIZATION=true environment variable enabled.
Ensure that the RELEEM_HOSTNAME variable should be the same as the currently added server.
If the agent runs on VM, set query_optimization=true in /opt/releem/releem.conf and restart the service:
systemctl restart releem-agent
- Grant additional permissions to the releem user. The SQL Query Optimization feature requires Additional Permissions for the Releem Agent user.
- Enable Performance Schema on Azure Database for MySQL Flexible Server if it is disabled.
- Enable query optimization in the agent:
If the agent runs in Docker, recreate the Docker container with RELEEM_QUERY_OPTIMIZATION=true environment variable enabled.
Ensure that the RELEEM_HOSTNAME variable should be the same as the currently added server.
If the agent runs on VM, set query_optimization=true in /opt/releem/releem.conf and restart the service:
systemctl restart releem-agent
-
Grant additional permissions to the releem user. The SQL Query Optimization feature requires Additional Permissions for the Releem Agent user.
-
Recreate the agent container with query optimization enabled:
docker rm -f releem-agent
docker run -d --name releem-agent \
-e RELEEM_QUERY_OPTIMIZATION=true \
... \
releem/releem-agent:[version]
For Docker Compose, set:
environment:
RELEEM_QUERY_OPTIMIZATION: true
Ensure that the RELEEM_HOSTNAME variable should be the same as the currently added server.
If the agent cannot automatically apply MySQL settings, add these settings to MySQL configuration and restart MySQL:
performance-schema-consumer-events-statements-history = ON
performance-schema-consumer-events-statements-current = ON
- Grant additional permissions to the releem user. The SQL Query Optimization feature requires Additional Permissions for the Releem Agent user.
- Set
query_optimization=trueinC:\ProgramData\ReleemAgent\releem.conf. - Add these settings to MySQL configuration and restart MySQL:
performance-schema-consumer-events-statements-history = ON
performance-schema-consumer-events-statements-current = ON
- Restart the Releem Agent Windows service.
Additional Database Permissions Required
For MySQL/MariaDB/Percona, the SQL Query Optimization feature requires Additional Permissions for the Releem Agent user.
For PostgreSQL, grant optimization read access to the Releem Agent user:
GRANT pg_read_all_data TO releem;
For PostgreSQL 12/13, use schema-level permissions instead:
GRANT CONNECT ON DATABASE "<database_name>" TO releem;
GRANT USAGE ON SCHEMA "<schema_name>" TO releem;
GRANT SELECT ON ALL TABLES IN SCHEMA "<schema_name>" TO releem;
GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA "<schema_name>" TO releem;
Data Collection and Analysis
Once the SQL Query Optimization feature is enabled, Releem will automatically collect and save the EXPLAIN outputs of the top 100 queries and the top 100 slowest queries. This data helps in analyzing the execution plan of queries and optimizing them further.
An example of the EXPLAIN output collected by Releem is provided below:
{
"query_block": {
"select_id": 1,
"cost_info": {
"query_cost": "0.60"
},
"table": {
"table_name": "sale_internals_order_discount",
"access_type": "ref",
"possible_keys": [
"IX_SALE_ORDER_DSC_HASH"
],
"key": "IX_SALE_ORDER_DSC_HASH",
"used_key_parts": [
"DISCOUNT_HASH"
],
"key_length": "98",
"ref": [
"const"
],
"rows_examined_per_scan": 1,
"rows_produced_per_join": 1,
"filtered": "100.00",
"cost_info": {
"read_cost": "0.50",
"eval_cost": "0.10",
"prefix_cost": "0.60",
"data_read_per_join": "1K"
},
"used_columns": [
"ID",
"MODULE_ID",
"DISCOUNT_ID",
"NAME",
"DISCOUNT_HASH",
"CONDITIONS",
"UNPACK",
"ACTIONS",
"APPLICATION",
"USE_COUPONS",
"SORT",
"PRIORITY",
"LAST_DISCOUNT",
"ACTIONS_DESCR"
]
}
}
}