bundles/postgresql: improvements
All checks were successful
bundlewrap/pipeline/head This commit looks good

- support other postgresql versions
- manage configs using bw
This commit is contained in:
Franzi 2021-01-23 11:35:03 +01:00
parent 7f36516faa
commit a160e7cf46
Signed by: kunsi
GPG key ID: 12E3D2136B818350
5 changed files with 224 additions and 12 deletions

View file

@ -0,0 +1,8 @@
% for custom_rule in sorted(node.metadata.get('postgresql', {}).get('custom_rules', [])):
${custom_rule}
% endfor
local all postgres peer
local all all peer
host all all 127.0.0.1/32 md5
host all all ::1/128 md5
host all all all md5

View file

@ -0,0 +1,30 @@
data_directory = '/var/lib/postgresql/${version}/main'
hba_file = '/etc/postgresql/${version}/main/pg_hba.conf'
ident_file = '/etc/postgresql/${version}/main/pg_ident.conf'
external_pid_file = '/var/run/postgresql/${version}-main.pid'
% if version == '9.1':
unix_socket_directory = '/var/run/postgresql'
% else:
unix_socket_directories = '/var/run/postgresql'
% endif
port = 5432
listen_addresses = 'localhost'
max_connections = ${max_connections}
autovacuum_max_workers = ${autovacuum_max_workers}
maintenance_work_mem = ${maintenance_work_mem}MB
work_mem = ${work_mem}MB
shared_buffers = ${shared_buffers}MB
temp_buffers = ${temp_buffers}MB
log_destination = syslog
datestyle = 'iso, ymd'
timezone = 'localtime'
lc_messages = 'en_US.UTF-8'
lc_monetary = 'en_US.UTF-8'
lc_numeric = 'en_US.UTF-8'
lc_time = 'en_US.UTF-8'
default_text_search_config = 'pg_catalog.english'
% if slow_query_log_sec > 0:
log_min_duration_statement = ${slow_query_log_sec*1000}
% else:
log_min_duration_statement = -1
% endif

View file

@ -1,19 +1,56 @@
postgresql_version = node.metadata['postgresql']['version']
pkg_apt = {
'postgresql-11': {},
'postgresql-client-11': {},
'postgresql-server-dev-11': {},
'postgresql-common': {},
'postgresql-client-common': {},
'postgresql-{}'.format(postgresql_version): {},
'postgresql-client-{}'.format(postgresql_version): {},
'postgresql-server-dev-{}'.format(postgresql_version): {},
}
if node.has_bundle('zfs'):
pkg_apt['postgresql-11']['needs'] = {
'zfs_dataset:tank/postgresql',
}
pkg_apt['postgresql-client-11']['needs'] = {
'zfs_dataset:tank/postgresql',
}
pkg_apt['postgresql-server-dev-11']['needs'] = {
'zfs_dataset:tank/postgresql',
}
for pkgname, pkgconfig in pkg_apt.items():
pkg_apt[pkgname]['needs'] = {
'zfs_dataset:tank/postgresql',
}
directories = {
'/etc/postgresql': {
'owner': None,
'group': None,
'mode': None,
# Keeping old configs messes with cluster-auto-detection.
'purge': True,
},
# This is needed so the above purge does not remove the version
# currently installed.
'/etc/postgresql/{}'.format(postgresql_version): {
'owner': None,
'group': None,
'mode': None,
},
}
files = {
"/etc/postgresql/{}/main/pg_hba.conf".format(postgresql_version): {
'content_type': 'mako',
'owner': 'postgres',
'group': 'postgres',
'triggers': {
'svc_systemd:postgresql:restart',
},
},
"/etc/postgresql/{}/main/postgresql.conf".format(postgresql_version): {
'content_type': 'mako',
'context': node.metadata['postgresql'],
'owner': 'postgres',
'group': 'postgres',
'triggers': {
'svc_systemd:postgresql:restart',
},
},
}
postgres_roles = {
'root': {

View file

@ -13,6 +13,15 @@ defaults = {
},
},
},
'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,
},
}
if node.has_bundle('zfs'):
@ -23,3 +32,39 @@ if node.has_bundle('zfs'):
},
},
}
@metadata_reactor.provides(
'apt/repos/postgresql',
'postgresql/version',
)
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])
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,
},
}
else:
return {
'postgresql': {
'version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