Gatsby source plugin pg Pool max connections during develop
0 reputation · 28 Feb 2024, 17:03 UTC
When using a Gatsby source plugin with node-postgres (pg) for database queries, intermittent connection pool exhaustion can occur during gatsby develop. Each plugin manages its own Pool instance, which emits errors like too many clients, already connected when the max limit is exceeded.
During development, concurrent page requests trigger parallel sourceNodes executions, potentially exceeding the pool's limit. Adjusting the pool size via PGMAXCONNECTIONS environment variables or plugin configuration can help, but the changes only apply to new pools. A running server must be restarted to apply new limits.
How can you diagnose and resolve intermittent connection pool exhaustion in a Gatsby source plugin using pg during development? Specifically:
- What are the best practices for monitoring active connections and pool usage during
gatsby develop? - How can you capture and log
pgPool error events to identify exhaustion issues? - What steps should be taken to adjust the pool size and verify the changes without overwhelming the database?