Technology
The readonlydb module provides a separate read-only database connection for Project Forge applications. This enables read-heavy operations to be offloaded to a dedicated read replica or separate database instance, improving performance and reducing load on the primary database.
Overview
This module extends applications with database module enabled by adding:
- Separate Read Connection: Independent database connection pool for read operations
- Flexible Configuration: Complete control over read database settings
- Performance Optimization: Offload read queries to reduce primary database load
- High Availability: Support for read replicas and database separation
Key Features
Performance Benefits
- Dedicated connection pool for read operations
- Reduces load on primary write database
- Optimizes query distribution across database infrastructure
- Configurable connection limits for read workloads
Configuration Flexibility
- Independent database server configuration
- Separate credentials and connection settings
- Support for different database schemas
- Debug logging for read operations
Database Support
- PostgreSQL: Full support for read replicas
- MySQL: Compatible with MySQL read slaves
- SQLite: Separate database file support
- SQL Server: Read-only connection support
Configuration Variables
The module provides comprehensive configuration through environment variables:
Connection Settings
read_db_host(string): Hostname for read database connection (default:localhost)read_db_port(int): Port for read database connection (default:3306)read_db_user(string): Username for read database authenticationread_db_password(string): Password for read database authenticationread_db_database(string): Database name for read connectionsread_db_schema(string): Schema name for read operationsread_db_debug(bool): Enable debug logging for all read database interactions
Usage
Application Integration
When enabled, the read-only database connection is available through the application state:
1 | |
Best Practices
- Use read connection for reports and analytics
- Route heavy SELECT queries to read database
- Keep write operations on primary database
- Monitor read replica lag in production
Dependencies
- Required:
database- Provides core database functionality - Compatible: Works with all supported database technologies
Source Code
- Repository: https://github.com/kyleu/projectforge/tree/main/module/readonlydb
- License: CC0 (Public Domain)
- Author: Kyle U (kyle@kyleu.com)
See Also
- Database Module - Core database functionality
- Configuration Variables - Complete environment variable reference
- Project Forge Documentation - Complete documentation