How to Manage Slow Query Logging for Vultr Managed Databases for MySQL

Updated on November 27, 2024

Slow Query Logging instructs MySQL to store SQL statements that take long to execute. The log allows you to identify and optimize such queries to improve your application's performance. Optimizing queries reduces the CPU and memory usage causing your database to run more efficiently. Running faster queries also lead to a more responsive and enjoyable user experience.

Follow this guide to manage slow query logging for Vultr Managed Databases for MySQL using Vultr Customer Portal, API, and CLI.

  • Vultr Customer Portal
  • Vultr API
  • Vultr CLI
  1. Navigate to Products and select Databases.

  2. Click the target database instance.

    Select Managed Database

  3. Click Settings and select MySQL Configuration. Then, navigate to Slow Query Logging. Turn the feature to YES or NO and click Apply Changes. If you turn the feature to YES specify a Long Query Time value in seconds. The minimum value is 10 seconds.

    Slow Query Logging

  1. List all the database instances by sending a GET request to the List Managed Databases endpoint and note the database ID (For example, 43b4c774-5dff-4ac0-a01f-78a23c2205b5) and the active mysql_slow_query_log status.

    console
    $ curl "https://api.vultr.com/v2/databases" \
        -X GET \
        -H "Authorization: Bearer ${VULTR_API_KEY}"
    
  2. Send a PUT request to the Update Managed Database endpoint and specify the database ID to change the mysql_slow_query_log status.

    console
    $ curl "https://api.vultr.com/v2/databases/database_id" \
        -X PUT \
        -H "Authorization: Bearer ${VULTR_API_KEY}" \
        -H "Content-Type: application/json" \
        --data '{
            "mysql_slow_query_log": false
        }'
    
  1. List all database instances and note the database ID. For instance, d6ac2a3c-92ea-43ef-8185-71a23e58ad8c.

    console
    $ vultr-cli database list --summarize
    
  2. Run the following command and specify a database ID to update mysql-slow-query-log and mysql-long-query-time.

    console
    $ vultr-cli database update database_id \
    --mysql-slow-query-log true \
    --mysql-long-query-time 20