defaults = { 'backups': { 'paths': { '/var/lib/postgresql', }, }, 'bash_functions': { 'pg_query_mon': "watch -n 2 \"echo \\\"SELECT pid, age(clock_timestamp(), query_start), usename, query FROM pg_stat_activity WHERE query != '' AND query NOT ILIKE '%pg_stat_activity%' ORDER BY query_start desc;\\\" | psql postgres\"" }, 'postgresql': { 'max_connections': 100, 'autovacuum_max_workers': 3, 'maintenance_work_mem': 64, 'work_mem': 4, 'shared_buffers': 128, 'temp_buffers': 8, 'slow_query_log_sec': 0, }, } @metadata_reactor.provides( 'apt/repos/postgresql', 'postgresql/version', ) def default_postgresql_version_for_debian(metadata): # versions_in_debian = { '11': '13', # bullseye } os = str(node.os_version[0]) version_to_be_installed = metadata.get('postgresql/version', versions_in_debian[os]) if version_to_be_installed != versions_in_debian[os]: return { 'apt': { 'repos': { 'postgresql': { 'items': { 'deb https://apt.postgresql.org/pub/repos/apt/ {os_release}-pgdg main', }, }, }, }, 'postgresql': { 'version': version_to_be_installed, }, } return { 'postgresql': { 'version': version_to_be_installed, }, } @metadata_reactor.provides( 'postgresql/effective_io_concurrency', 'postgresql/max_worker_processes', 'postgresql/max_parallel_workers', 'postgresql/max_parallel_workers_per_gather', ) def worker_processes(metadata): return { 'postgresql': { # This is the amount of parallel I/O Operations the # postgresql process is allowed to do on disk. We set # this to max_connections by default. 'effective_io_concurrency': metadata.get('postgresql/max_connections'), # Try to request one worker process per 10 configured # connections. The default is 8 for both of these values. 'max_worker_processes': int(metadata.get('postgresql/max_connections')/10), 'max_parallel_workers': int(metadata.get('postgresql/max_connections')/10), # default 2 'max_parallel_workers_per_gather': max(int(metadata.get('postgresql/max_connections')/100), 2), }, }