Skip to content

PopSQL: limited support.

Migrate now →

Sequences past 80% of their range

An integer sequence that reaches its maximum stops the inserts on that table. This catches it months earlier.

PostgreSQL · SQL
SELECT schemaname || '.' || sequencename AS sequence_name,
       last_value,
       max_value,
       ROUND(100.0 * last_value / max_value, 2) AS used_pct
FROM pg_sequences
WHERE last_value IS NOT NULL
  AND last_value > max_value * 0.8
ORDER BY used_pct DESC

This query is part of the "PostgreSQL health" pack: connect the database in DataRunner and install the whole pack — queries, dashboard and checks — at once.

  • Check that ships with it: No sequence past 80% of its range