2023-07-14 04:33:59 +00:00
|
|
|
postgresql_version = int(node.metadata.get('postgresql/version'))
|
2021-01-23 10:35:03 +00:00
|
|
|
|
2020-08-21 14:21:46 +00:00
|
|
|
pkg_apt = {
|
2021-01-23 10:35:03 +00:00
|
|
|
'postgresql-common': {},
|
|
|
|
'postgresql-client-common': {},
|
|
|
|
'postgresql-{}'.format(postgresql_version): {},
|
|
|
|
'postgresql-client-{}'.format(postgresql_version): {},
|
2021-07-02 14:15:31 +00:00
|
|
|
'postgresql-server-dev-{}'.format(postgresql_version): {}
|
2020-08-21 14:21:46 +00:00
|
|
|
}
|
|
|
|
|
2020-08-29 19:30:12 +00:00
|
|
|
if node.has_bundle('zfs'):
|
2021-01-23 10:35:03 +00:00
|
|
|
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.
|
2021-02-20 15:50:38 +00:00
|
|
|
'/etc/postgresql/{}/main'.format(postgresql_version): {
|
|
|
|
'owner': 'postgres',
|
|
|
|
'group': 'postgres',
|
|
|
|
'mode': '0755',
|
2021-05-14 18:06:42 +00:00
|
|
|
'needs': {f'pkg_apt:{i}' for i in pkg_apt.keys()},
|
2021-01-23 10:35:03 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
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',
|
2023-07-14 04:33:59 +00:00
|
|
|
'context': node.metadata.get('postgresql'),
|
2021-01-23 10:35:03 +00:00
|
|
|
'owner': 'postgres',
|
|
|
|
'group': 'postgres',
|
2021-01-23 11:06:38 +00:00
|
|
|
'needs': {
|
|
|
|
# postgresql won't start if the configured locale isn't available
|
|
|
|
'action:locale-gen',
|
|
|
|
} if node.has_bundle('basic') else set(),
|
2021-01-23 10:35:03 +00:00
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:postgresql:restart',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2020-08-29 19:30:12 +00:00
|
|
|
|
2024-10-28 15:55:10 +00:00
|
|
|
if node.has_bundle('backup-client'):
|
2021-02-13 07:56:35 +00:00
|
|
|
files['/etc/backup-pre-hooks.d/90-postgresql-dump-all'] = {
|
|
|
|
'source': 'backup-pre-hook',
|
|
|
|
'content_type': 'mako',
|
|
|
|
'context': {
|
2021-02-18 17:12:25 +00:00
|
|
|
'databases': node.metadata.get('postgresql/databases', {}).keys(),
|
2021-02-13 07:56:35 +00:00
|
|
|
},
|
|
|
|
'mode': '0700',
|
|
|
|
}
|
|
|
|
directories['/var/tmp/postgresdumps'] = {}
|
|
|
|
|
2020-08-21 14:21:46 +00:00
|
|
|
postgres_roles = {
|
|
|
|
'root': {
|
|
|
|
'password': repo.vault.password_for('{} postgresql root'.format(node.name)),
|
|
|
|
'superuser': True,
|
2020-08-29 19:30:12 +00:00
|
|
|
'needs': {
|
|
|
|
'svc_systemd:postgresql',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-03-28 07:39:08 +00:00
|
|
|
restart_deps = {
|
|
|
|
f'file:/etc/postgresql/{postgresql_version}/main/pg_hba.conf',
|
|
|
|
f'file:/etc/postgresql/{postgresql_version}/main/postgresql.conf',
|
|
|
|
*{f'pkg_apt:{i}' for i in pkg_apt.keys()},
|
|
|
|
}
|
|
|
|
|
2020-08-29 19:30:12 +00:00
|
|
|
svc_systemd = {
|
|
|
|
'postgresql': {
|
2021-03-28 07:39:08 +00:00
|
|
|
'needs': restart_deps,
|
2021-06-29 12:23:51 +00:00
|
|
|
'triggers': {
|
|
|
|
'action:postgresql_wait_after_restart',
|
|
|
|
},
|
2020-08-21 14:21:46 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-06-29 12:23:51 +00:00
|
|
|
actions = {
|
|
|
|
'postgresql_wait_after_restart': {
|
|
|
|
# postgresql doesn't accept connections immediately after restarting
|
|
|
|
'command': 'sleep 10',
|
|
|
|
'triggered': True,
|
|
|
|
'before': {
|
|
|
|
'postgres_role:',
|
|
|
|
'postgres_db:',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2020-04-04 15:53:59 +00:00
|
|
|
|
2021-02-18 17:12:25 +00:00
|
|
|
for user, config in node.metadata.get('postgresql/roles', {}).items():
|
2020-04-04 15:53:59 +00:00
|
|
|
postgres_roles[user] = {
|
|
|
|
'password': config['password'],
|
2020-08-29 19:30:12 +00:00
|
|
|
'needs': {
|
|
|
|
'svc_systemd:postgresql',
|
|
|
|
},
|
2020-04-04 15:53:59 +00:00
|
|
|
}
|
|
|
|
|
2021-02-18 17:12:25 +00:00
|
|
|
for database, config in node.metadata.get('postgresql/databases', {}).items():
|
2021-05-14 18:06:42 +00:00
|
|
|
postgres_dbs[database] = config
|