Compare commits

...

2 commits

Author SHA1 Message Date
mwiegand
c37be21034 home.server more ram 2022-06-28 13:12:40 +02:00
mwiegand
57079a0cbe postgres tuning 2022-06-28 13:12:18 +02:00
3 changed files with 54 additions and 3 deletions

View file

@ -1,5 +1,8 @@
from bundlewrap.utils.dicts import merge_dict
version = node.metadata.get('postgresql/version')
directories = {
'/var/lib/postgresql': {
'owner': 'postgres',
@ -14,6 +17,22 @@ directories = {
}
}
files = {
f"/etc/postgresql/{version}/main/conf.d/managed.conf": {
'content': '\n'.join(
f'{key} = {value}'
for key, value in sorted(node.metadata.get('postgresql/conf').items())
) + '\n',
'owner': 'postgres',
'group': 'postgres',
'needed_by': [
'svc_systemd:postgresql',
],
'triggers': [
'svc_systemd:postgresql:restart',
],
},
}
svc_systemd['postgresql'] = {
'needs': [

View file

@ -1,3 +1,6 @@
import builtins
root_password = repo.vault.password_for(f'{node.name} postgresql root')
defaults = {
@ -12,6 +15,7 @@ defaults = {
},
},
'postgresql': {
'conf': {},
'roles': {
'root': {
'password': root_password,
@ -24,6 +28,32 @@ defaults = {
}
@metadata_reactor.provides(
'postgresql/conf',
)
def conf(metadata):
conf = {}
def limit(value, min=float('-inf'), max=float('inf'), unit=None):
result = int(builtins.max([builtins.min([max, value]), min]))
return str(result) + unit if unit else result
ram = metadata.get('vm/ram', None)
if ram:
conf['max_connections'] = limit(ram/50, min=100)
conf['shared_buffers'] = limit(ram/20, min=128, unit='MB')
conf['work_mem'] = limit(ram/500, min=4, max=64, unit='MB')
conf['temp_buffers'] = limit(ram/500, min=8, max=64, unit='MB')
conf['effective_cache_size'] = limit(ram/3, min=4096, unit='MB')
conf['maintenance_work_mem'] = limit(ram/50, min=64, unit='MB')
return {
'postgresql': {
'conf': conf,
},
}
@metadata_reactor.provides(
'zfs/datasets',
)

View file

@ -83,6 +83,7 @@
'nextcloud': {
'hostname': 'cloud.sublimity.de',
'version': '24.0.2',
'instance_id': 'oci6dw1woodz',
},
'nextcloud-picsort': {
'ckn': {
@ -120,7 +121,8 @@
},
'vm': {
'cores': 16,
'ram': 32384,
'threads': 32,
'ram': 49152,
},
'wireguard': {
'my_ip': '172.30.0.2/32',
@ -135,7 +137,7 @@
},
},
'zfs': {
'zfs_arc_max_percent': 75,
'zfs_arc_max_percent': 80,
'storage_classes': {
'ssd': 'ssd',
},
@ -152,7 +154,7 @@
'/dev/disk/by-id/nvme-SAMSUNG_MZVL22T0HBLB-00B00_S677NF0RA01551-part3',
],
},
},
},
'datasets': {
'ssd/nextcloud-appdata': {
'mountpoint': '/var/lib/nextcloud/appdata_oci6dw1woodz',