Skip to content

fix: stats table empty when using PostgreSQL backend - #260

Open
brewle wants to merge 1 commit into
0xfurai:mainfrom
brewle:fix/stats-empty-postgresql
Open

fix: stats table empty when using PostgreSQL backend#260
brewle wants to merge 1 commit into
0xfurai:mainfrom
brewle:fix/stats-empty-postgresql

Conversation

@brewle

@brewle brewle commented Feb 24, 2026

Copy link
Copy Markdown

Problem

When using PostgreSQL as the database backend, the response time charts and uptime statistics are always empty, even though heartbeats are being recorded correctly.

The root cause is in UpsertStat method in stats.sql.repository.go.
The original implementation used an UPDATE -> check RowsAffected -> INSERT pattern. On PostgreSQL, RowsAffected() returns -1 for UPDATE queries without a RETURNING clause (this is a known behavior of the lib/pq driver). As a result, the fallback INSERT never executes and the stats table remains empty.

This does not affect SQLite because SQLite always returns the correct RowsAffected value.

Fix

Replace the UPDATE -> check -> INSERT pattern with a single atomic INSERT ... ON CONFLICT (monitor_id, timestamp) DO UPDATE statement.
This works correctly on both PostgreSQL and SQLite.

Related issues

Fixes #188
Fixes #196

@netlify

netlify Bot commented Feb 24, 2026

Copy link
Copy Markdown

Deploy Preview for peekaping ready!

Name Link
🔨 Latest commit 2a22b83
🔍 Latest deploy log https://app.netlify.com/projects/peekaping/deploys/699db4f92def370008455f33
😎 Deploy Preview https://deploy-preview-260--peekaping.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Feb 24, 2026

Copy link
Copy Markdown

Deploy Preview for docspeekaping ready!

Name Link
🔨 Latest commit 2a22b83
🔍 Latest deploy log https://app.netlify.com/projects/docspeekaping/deploys/699db4f9ff38320008e64f48
😎 Deploy Preview https://deploy-preview-260--docspeekaping.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Response time chart is empty Stats are broken (no uptime %, no line chart)

1 participant