## Introduction When you're using DDEV, you can see the database from a PHPMyAdmin interface in: `https://myname.ddev.site:8037`. You can see all the tables there, included the log registers by default in Drupal, the so called "watchdog" table, with annotations about all the incidences in your Drupal installation. This table is managed by [the Dblog module, present in Drupal core](https://git.drupalcode.org/project/drupal/-/tree/9.2.x/core/modules/dblog). The `watchdog`table contains columns as: uid (user triggering the event), the type of the log message, the severity of the event, a location url, a timestamp and many others. Sometimes the `watchdog` table can grow out of control, so you can get a lot of errors from MySQL and/or slow down the performance of your Drupal installation. You must learn how to reduce the table, truncate it, delete certain records, etc. And perhaps you may have to turn off this module in Live / Production Environments. **Alternatives to the Dblog module in Drupal** - [Monolog](https://www.drupal.org/project/monolog) - [Logs HTTP](https://www.drupal.org/project/logs_http) - [Syslog -in Core-](https://www.drupal.org/docs/8/core/modules/syslog/overview) ## Using SQL queries in Drupal While the watchdog table is SQL-based, you can get or delete register using SQL queries as usual. Just like: ```SQL DELETE FROM table_name WHERE condition; ``` In the Drupal context, this can be managed in two ways or styles: [dynamic queries](https://www.drupal.org/docs/8/api/database-api/dynamic-queries/introduction-to-dynamic-queries) or [static queries](https://www.drupal.org/docs/7/api/database-api/static-queries), for instance: First, we gonna get a database connection object. ```php $connection = \Drupal::database(); // Or $connection = \Drupal::service('database'); ``` And then using a query builder object: ```php $num_deleted = $connection->delete('watchdog') ->condition('type', 'cron') ->execute(); // Is just like: DELETE FROM {watchdog} WHERE type='cron'; ``` ```php // Dynamic queries in Drupal database API. $database = \Drupal::database(); $query = $database->truncate('watchdog'); $query->execute(); // Or \Drupal::database()->truncate('watchdog')->execute(); // Truncates the whole table. ``` Or by doing: ```php // Static queries in Drupal database API using db_query() function. $query = db_query("TRUNCATE TABLE watchdog"); // Or DELETE FROM {watchdog} WHERE type='cron $query = db_query("DELETE FROM {watchdog} WHERE type = 'cron'"); $records = $query->fetchAll(); ``` **Read more about the Database API of Drupal:** [drupal.org/docs/database-api](https://www.drupal.org/docs/drupal-apis/database-api) ## Using Drupal services You can delete registers in the watchdog table by using the database() service in Drupal: ```php \Drupal::database()->truncate('watchdog')->execute(); ``` ## Using Drush When you're deploying environments using DDEV and wanna using drush: ```bash $ ddev drush -y wd-del all ``` If you're working out of a DDEV deploy, then use only drush: ```bash $ drush -y wd-del all ``` Delete messages in watchdog containing certain strings: ```bash $ drush watchdog-delete "cron run succesful" ``` Delete all messages with severity of error: ```bash $ drush watchdog-delete --severity=error ``` Delete all messages of type php: ```bash $ drush watchdog-delete --type=php ```