Laravel Packages

PostgreSQL Monitoring and Schema Linting for Laravel with Vacuum

Published
PostgreSQL Monitoring and Schema Linting for Laravel with Vacuum image

Vacuum is a PostgreSQL monitoring package for Laravel from Rati Rukhadze. It reads the statistics PostgreSQL already keeps in views such as pg_stat_user_tables, pg_stat_activity, and pg_stat_statements, then lists the problems it finds along with the SQL statement that would fix them.

Here's the main features this package provides:

  • 13 advisor rules: wraparound, bloat, dead tuples, unused indexes, slow statements, and more
  • Health score: a grade out of 100, based on the findings
  • Blade and Filament Support: a dashboard at /vacuum, or a Filament 4 or 5 plugin
  • A vacuum:check Command: fails a build on critical findings
  • A vacuum:lint Command: flags schema problems like unindexed foreign keys in CI
  • History: trends and forecasts from scheduled snapshots
  • Lessons: 13 PostgreSQL explainers that use your own tables
  • And more...

The Dashboard and Advisor Rules

Every finding has a severity and grade, giving you a health score out of 100:

You can learn more about the rules from the package's readme. The package also provides a /learn endpoint that tells you why issues exist in your database using your own tables as working examples, such as N+1 queries.

The same rules run from the terminal:

php artisan vacuum:check
php artisan vacuum:check --fail-on=warning # critical, warning, info, or never
php artisan vacuum:check --format=json # score, grade, deductions, findings

Using a scheduled job against staging, you could use the above commands to fail when a table's freeze age crosses the critical threshold. Each rule reads its limits from config/vacuum.php, including dead_tuple_ratio (0.20) and slow_query_milliseconds (500).

Installation

Vacuum 1.2.0 requires PostgreSQL 14 and Laravel 11+. The pg_stat_statements extension is optional. Without it, the dashboard tells you the extension is missing.

composer require heyosseus/vacuum
php artisan vacuum:install

The dashboard opens only in the local environment. To access it in other environments, you can write a callback using the Vacuum::auth() method:

use Heyosseus\Vacuum\Vacuum;
 
Vacuum::auth(fn (Request $request) => $request->user()?->isAdmin() === true);

You can learn more about this package, get full installation instructions, and view the source code on GitHub.

Paul Redmond photo

Staff writer at Laravel News. Full stack web developer and author.

Sponsored

laravelcloud logo
Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Visit Laravel Cloud

The latest

View all →
Building EasyReply: How We Used Laravel to Unify Customer Support image

Building EasyReply: How We Used Laravel to Unify Customer Support

Read article
PayZephyr: One Payment API for Stripe, Paystack, and PayPal image

PayZephyr: One Payment API for Stripe, Paystack, and PayPal

Read article
Bifrost Turns One With AI Builds and New Workflows image

Bifrost Turns One With AI Builds and New Workflows

Read article
Preview Blade Templates in macOS Finder with Quick Blade image

Preview Blade Templates in macOS Finder with Quick Blade

Read article
Artisan Debugging Commands in Laravel Telescope 5.24.0 image

Artisan Debugging Commands in Laravel Telescope 5.24.0

Read article
Queue totalSize() and JobInterrupted Event in Laravel 13.31 image

Queue totalSize() and JobInterrupted Event in Laravel 13.31

Read article