
How Exposed Postgres view Took 8 Minutes to Retrieve data
To keep production traffic isolated from heavy reporting queries, we maintain a separate analytics database. Our main service database handles user traffic, while a dedicated analytics database aggregates and enriches organization data. Twice a day, a background job synchronizes data from analytics into the service database. The analytics team exposes a PostgreSQL view as a clean interface — no direct table access, just a stable SELECT contract. It worked perfectly. Until one day the sync started taking 8 minutes . And the query had a LIMIT 5000 . The Setup Here’s roughly how the data flowed: On the analytics side, we had something like this: analytics.organizations analytics.organization_domains analytics.partner_organizations analytics.custom_projects The analytics team exposed a view: CREATE VIEW analytics . v_sync_organizations AS SELECT ... FROM analytics . organizations UNION ALL SELECT ... FROM analytics . partner_organizations UNION ALL SELECT ... FROM analytics . custom_projec
Continue reading on Dev.to Webdev
Opens in a new tab

