2020-11-13 11:37:26 +00:00
defaults = {
' backups ' : {
' paths ' : {
' /var/lib/postgresql ' ,
} ,
} ,
2021-02-20 09:56:20 +00:00
' bash_functions ' : {
' pg_query_mon ' : " watch -n 2 \" echo \\ \" SELECT pid, age(clock_timestamp(), query_start), usename, query FROM pg_stat_activity WHERE query != ' <IDLE> ' AND query NOT ILIKE ' % pg_stat_activity % ' ORDER BY query_start desc; \\ \" | psql postgres \" "
} ,
2020-11-21 17:55:21 +00:00
' icinga2_api ' : {
2020-11-22 06:40:34 +00:00
' postgresql ' : {
2020-11-21 17:55:21 +00:00
' services ' : {
' POSTGRESQL PROCESS ' : {
' command_on_monitored_host ' : ' /usr/lib/nagios/plugins/check_procs -C postgres -c 1: ' ,
} ,
} ,
} ,
} ,
2021-01-23 10:35:03 +00:00
' 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 ,
2023-06-03 11:21:23 +00:00
' cache_size ' : 256 ,
2021-01-23 10:35:03 +00:00
} ,
2020-11-13 11:37:26 +00:00
}
2020-08-29 19:30:12 +00:00
2021-05-02 11:09:01 +00:00
if node . has_bundle ( ' telegraf ' ) :
defaults [ ' telegraf ' ] = {
' input_plugins ' : {
' builtin ' : {
' postgresql ' : [ {
' address ' : repo . vault . password_for ( f ' { node . name } postgresql telegraf ' ) . format_into ( ' postgres://telegraf: {} @localhost:5432/telegraf?sslmode=disable ' ) ,
' ignored_databases ' : [
' template0 ' ,
' template1 ' ,
2021-05-02 12:01:26 +00:00
' telegraf ' ,
2021-05-02 11:09:01 +00:00
] ,
} ] ,
} ,
} ,
}
defaults [ ' postgresql ' ] . update ( {
' roles ' : {
' telegraf ' : {
' password ' : repo . vault . password_for ( f ' { node . name } postgresql telegraf ' ) ,
} ,
} ,
' databases ' : {
' telegraf ' : {
' owner ' : ' telegraf ' ,
} ,
} ,
} )
2020-08-29 19:30:12 +00:00
if node . has_bundle ( ' zfs ' ) :
defaults [ ' zfs ' ] = {
' datasets ' : {
' tank/postgresql ' : {
' mountpoint ' : ' /var/lib/postgresql ' ,
2022-02-14 21:05:09 +00:00
' recordsize ' : ' 8192 ' ,
2020-08-29 19:30:12 +00:00
} ,
} ,
}
2021-05-15 18:32:23 +00:00
else :
defaults [ ' backups ' ] [ ' paths ' ] . add ( ' /var/tmp/postgresdumps ' )
2021-01-23 10:35:03 +00:00
@metadata_reactor.provides (
' apt/repos/postgresql ' ,
)
def default_postgresql_version_for_debian ( metadata ) :
# <https://packages.debian.org/search?keywords=postgresql>
versions_in_debian = {
' 10 ' : ' 11 ' , # buster
' 11 ' : ' 13 ' , # bullseye
}
os = str ( node . os_version [ 0 ] )
2022-02-27 11:51:53 +00:00
version_to_be_installed = metadata . get ( ' postgresql/version ' )
2021-01-23 10:35:03 +00:00
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 ' ,
} ,
} ,
} ,
} ,
}
2021-02-12 19:37:36 +00:00
2022-02-27 11:51:53 +00:00
return { }
2021-04-23 12:02:04 +00:00
@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 ) ,
} ,
}