Database Issues
Cannot connect to PostgreSQL database
Cannot connect to PostgreSQL database
Symptoms
- API server fails to start with connection error
- Error message:
connection to server at "127.0.0.1", port 5432 failed - Database queries timeout or fail
Solutions
1. Check if PostgreSQL is running:.env:Database schema not found or missing tables
Database schema not found or missing tables
Symptoms
- Error:
relation "collection_centers" does not exist - API endpoints return 500 errors
- Empty database after creation
Solutions
1. Verify database exists:- app_configuration
- collection_center_members
- collection_centers
- dispatches
- generators
- tickets
- vehicles
schema.sql. Look for ERROR messages indicating permission issues or syntax problems.pg_trgm extension not found
pg_trgm extension not found
Database connection pool exhausted
Database connection pool exhausted
Symptoms
- Slow API responses under load
- Error:
remaining connection slots are reserved - Application hangs waiting for database connections
Solutions
1. Increase PostgreSQL max_connections:server/index.js:Application Issues
Port already in use (EADDRINUSE)
Port already in use (EADDRINUSE)
Build errors with npm/pnpm
Build errors with npm/pnpm
CORS errors in browser
CORS errors in browser
Symptoms
- Browser console shows:
Access to fetch blocked by CORS policy - API requests fail from frontend
- Network tab shows OPTIONS requests failing
Solutions
1. Check CORS configuration inserver/index.js:API returns 500 Internal Server Error
API returns 500 Internal Server Error
Symptoms
- API endpoints return 500 status
- No specific error message to client
- Generic server error
Solutions
1. Check API server logs:- Database connection failed (see Database Issues above)
- Missing environment variables in
.env - Database table/column doesn’t exist
- Invalid SQL query
- Unhandled exception in route handler
server/index.js:Migration and Data Issues
Ticket number generation fails
Ticket number generation fails
Symptoms
- Error when creating tickets
- Message:
collection center not configured - Ticket numbers not sequential
Solutions
1. Configure active collection center:In the application, go to Configuration module and select an active collection center.Or manually in database:AV-[STATE_CODE]-[YEAR]-[SEQUENCE]The state code is derived from the first 3 letters of the state name.Data integrity issues after migration
Data integrity issues after migration
Seed data fails to load
Seed data fails to load
Performance Issues
Slow query performance
Slow query performance
Symptoms
- API endpoints take several seconds to respond
- Dashboard loads slowly
- Ticket list pagination is slow
Solutions
1. Verify indexes are created:- idx_tickets_generator_id
- idx_tickets_date
- idx_tickets_created_at
- idx_tickets_ticket_number_trgm
- idx_tickets_generator_name_trgm
- And more…
High memory usage
High memory usage
Symptoms
- Server runs out of memory
- Application crashes with OOM errors
- Slow performance under load
Solutions
1. Monitor Node.js memory:Prevention Best Practices
Getting Help
If you encounter issues not covered here:- Check application logs for detailed error messages
- Review PostgreSQL logs for database errors
- Enable debug logging in development
- Verify environment configuration
- Test database connection manually
- Check system resources (disk, memory, CPU)