# PostgreSQL 15 configuration optimized for Odoo Multi-Tenant SaaS
# Assume 16GB system RAM, 4 CPU Cores

# Connectivity
max_connections = 500
superuser_reserved_connections = 3

# Memory Sizing
shared_buffers = 4GB                  # 25% of total RAM
work_mem = 16MB                       # Allocates per operation
maintenance_work_mem = 512MB
effective_cache_size = 12GB            # 75% of total RAM
temp_buffers = 8MB

# Write-Ahead Log (WAL)
wal_level = replica
max_wal_size = 4GB
min_wal_size = 1GB
checkpoint_completion_target = 0.9
checkpoint_timeout = 15min

# Disk I/O & Query Planner
random_page_cost = 1.1                # Optimized for SSD storage
effective_io_concurrency = 200        # Concurrent read requests (SSD)

# Background Writer & Autovacuum (Crucial for Odoo table cleanup)
autovacuum = on
autovacuum_max_workers = 4
autovacuum_naptime = 1min
autovacuum_vacuum_threshold = 50
autovacuum_analyze_threshold = 50
autovacuum_vacuum_scale_factor = 0.05
autovacuum_analyze_scale_factor = 0.02
autovacuum_vacuum_cost_limit = 1000

# Logging
log_destination = 'stderr'
logging_collector = on
log_directory = 'log'
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'
log_min_messages = warning
log_min_error_statement = error
log_min_duration_statement = 250      # Log slow queries taking longer than 250ms
