Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

bbenz's avatar
Level 1

sqlite: "php artisan db" works but "db:show" fails. no such table: dbstat

I am using sqlite for my app, I'd like to use the artisan command php artisan db:show to inspect my database. I'm getting the following error:

Illuminate\Database\QueryException
SQLSTATE[HY000]: General error: 1 no such table: dbstat (SQL: SELECT SUM(pgsize) AS size FROM dbstat WHERE name=failed_jobs)

If I access the db using php artisan db I can run the following query no problem:

SELECT SUM(pgsize) AS size FROM dbstat WHERE name='failed_jobs'

By all other accounts my db connection is working fine, it works on the command line and in the app.

I was wondering if maybe the prepared statement needed quotes around it, so I opened up vendor/laravel/framework/src/Illuminate/Database/Console/DatabaseInspectionCommand.php and changed the query to "SELECT SUM(pgsize) AS size FROM dbstat WHERE name='?'" but that didn't help. The connection still can't find the table dbstat. I don't know if it matters that dbstat is a virtual table. Has anybody dealt with this problem?

Laravel Version: Laravel Framework 9.29.0

Sqlite3 Version: 3.37.0 2021-12-09 01:34:53 9ff244ce0739f8ee52a3e9671adb4ee54c83c640b02e3f9d185fd2f9a179aapl

0 likes
14 replies
bbenz's avatar
Level 1

I think dbstat is enabled though. I am able to run SELECT * FROM dbstat when I open a sqlite3 database from the command line.

I ran the following command to see if it's enabled:

echo "PRAGMA compile_options;" | sqlite3 | grep -i dbstat

And ENABLE_DBSTAT_VTAB appeared in the output. Unless I'm missing something, I think this should be working? Does laravel/php use the system's sqlite or does it use some other built in sqlite engine?

Sinnbeck's avatar

Can you try composer update to get the newest laravel version. Maybe there is a hot fix

bbenz's avatar
Level 1

I tried that, but it's actually more broken on the most updated version. When I update from v9.29.0 to v9.34.0 the command php artisan db stops working too. I get the following output:

  ERROR  No host specified for this database connection.
  Use the [--read] and [--write] options to specify a read or write connection.

The flags --read and --write do not solve the problem.

php artisan db --read

   ErrorException

  Undefined array key "read"

  at vendor/laravel/framework/src/Illuminate/Database/Console/DbCommand.php:78
     74▕             $connection = (new ConfigurationUrlParser)->parseConfiguration($connection);
     75▕         }
     76▕
     77▕         if ($this->option('read')) {
  ➜  78▕             if (is_array($connection['read']['host'])) {
     79▕                 $connection['read']['host'] = $connection['read']['host'][0];
     80▕             }
     81▕
     82▕             $connection = array_merge($connection, $connection['read']);

      +15 vendor frames
  16  artisan:37
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

At least on v9.24.0 I can get the database to work. I'm on MacOS, if that's relevant.

Sinnbeck's avatar

@bbenz Hm yeah that seems to be a new bug. But db:show works in the newest it seems

Sinnbeck's avatar

Can you try giving it a fake host in the config?

'sqlite' => [
            'driver' => 'sqlite',
            'url' => env('DATABASE_URL'),
            'database' => env('DB_DATABASE', database_path('database.sqlite')),
            'prefix' => '',
            'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
            'host' => 'a', //fake
        ],
bbenz's avatar
Level 1

@Sinnbeck Interesting, that brings php artisan db back online but db:show is still not working in the newest version for me. I'm still getting the original error pertaining to dbstat.

Sinnbeck's avatar

@bbenz That is indeed strange. It works for me on linux. Maybe another mac user can give it a shot?

bbenz's avatar
Level 1

@Sinnbeck I just fired up a linux machine and set up my project there, it seems like none of these issues exist on v9.29 or v9.34 so I guess it's either a Mac issue or there's something strange going on with my setup.

bbenz's avatar
Level 1

@Sinnbeck No worries, this is actually not terribly critical, it's just a minor frustration and I can work around it. I appreciate your help!

Sinnbeck's avatar

@bbenz Happy to help. Hopefully others have the same error, and a fix is released soon

Please or to participate in this conversation.