Skip to content

Commit

Permalink
Add Postgres dead rows collector
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpon92 committed Apr 28, 2020
1 parent cf74185 commit e638888
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/Laravel/Collectors/Postgres/DeadRowsMetricsCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,18 @@ public function collect(): void
$metricsCollection = new MetricsCollection();

$deadRowsInfo = DB::connection($connection)
->table('pg_stat_user_tables')
->selectRaw(
'relname AS table_name,
->select(
'SELECT relname AS table_name,
n_live_tup AS live_tuples,
n_dead_tup AS dead_tuples,
CASE
WHEN n_live_tup = 0 THEN 0
ELSE round(n_dead_tup::numeric / n_live_tup::numeric * 100::numeric, 2)
END AS percent'
)
->get();
END AS percent
FROM pg_stat_user_tables'
);

if ($deadRowsInfo->isEmpty()) {
if (empty($deadRowsInfo)) {
continue;
}

Expand Down

0 comments on commit e638888

Please sign in to comment.