Slow Query Log
The Slow Queries feature of the Arvancloud Cloud Database helps you identify queries that took a long time to run in the past 24 hours. By reviewing this data, you can troubleshoot and solve your database's performance problems faster. The solution to these problems can be improving the query, tuning indexes, or configuring the schema and database settings.
These logs are collected and shown in a managed, automatic way, and the data is kept for 24 hours.
Note that this feature is currently only available for MySQL databases.
Viewing Slow Queries
To see the list of slow queries, go to the database list in the Arvancloud Cloud Database menu, click the cluster you want, and select the Logs tab.
On this page, you can review a list of slow queries with the following details:
-
User
The username that ran the query.
-
Time
The time the query ran
-
Host IP
The IP address the query was run from.
-
Query Time
The total time it took to run the query.
-
Lock Time
The time the query waited to acquire a table lock (for example, when it was blocked by another operation).
-
Query
The exact text of the SQL query, with a copy button for quicker use and review
Testing How Slow Queries Works
You can use the following scenarios to make sure this feature works. Before running these scenarios, create a MySQL database cluster and connect to the database with the Arvancloud cloud shell or any other MySQL client.
Scenario 1: Creating a simple delay
Run the following query:
SELECT SLEEP (6);
This query runs for 6 seconds, which is longer than the 5-second threshold. That's why you can see it in the slow queries list when you go to the Logs tab.
Scenario 2: Running a complex join query with sample data
First, create two tables:
CREATE TABLE `default`.`person` (
`id` INT NOT NULL,
`name` VARCHAR(255),
`class` VARCHAR(255),
`age` INT,
`salary` DECIMAL(10,2),
`phone number` INT,
`national id` INT,
`account id` INT,
`address` VARCHAR(255),
PRIMARY KEY (`id`)
);
CREATE TABLE `default`.`person1` (
`id` INT NOT NULL,
`name` VARCHAR(255),
`class` VARCHAR(255),
`age` INT,
`salary` DECIMAL(10,2),
`phone number` INT,
`national id` INT,
`account id` INT,
`address` VARCHAR(255),
PRIMARY KEY (`id`)
);
Then fill them with random data using tools such as Navicat or SQL scripts. Depending on the database's processing power, these two tables should be filled with a large number of records (for example, one million records).
After that, run the following query:
SELECT t1.*, t2.*
FROM person t1
JOIN person1 t2 ON t1.id != t2.id
WHERE t1.name LIKE '%slowsearch%'
AND t2.class = 'active'
AND t1.age < (
SELECT MAX(age)
FROM person
WHERE class = 'inactive'
)
ORDER BY t1.age DESC
LIMIT 1000;
Now you can see this query by refreshing the Slow Queries tab in the Arvancloud panel.