SQL query logging for debugging

System Information
  • Strapi Version: 3.14
  • Operating System: Debian 10
  • Database: MariaDB 10.3
  • Node Version: 14.,18.1
  • NPM Version: 6.14.15
  • Yarn Version:

Is there a way to enable DB query logging to a log file?

I tried ‘–debug’, but that didn’t add SQL queries. I tried ‘debug: true’ in the database.js file, but that didn’t result in queries being logged either (I am not sure I put that statement in the right place, but Strapi didn’t complain).

Is this possible in version 3.14 or even a newer version?

I have the same question

If you are using Strapi v4 you can do:

module.exports = ({ env }) => ({
  connection: {
    client: 'sqlite',
    connection: {
      filename: path.join(__dirname, '..', env('DATABASE_FILENAME', '.tmp/data.db')),
    useNullAsDefault: true,

in your ./config/database.js
if it does not seem to work, perhaps is not in the right place. It should bein the outer object beneath the useNullAsDefault

I’ve been digging into strapi over the last week or so and am looking at the generated queries like this (and saving to file).

What I did was add an environment variable to my ,env


Then start strapi and redirect the output (I’m using linux but the principle should be the same on other platforms).

npm run develop 2> ~/logtest.txt

This is on the current v4.3.4

Hope that’s useful.


how to view the actual query instead of t0, $1, $2 etc?

I found out we can see bindings for queries like this