2021-01-23 10:35:03 +00:00
|
|
|
postgresql_version = node.metadata['postgresql']['version']
|
|
|
|
|
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): {},
|
|
|
|
'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-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',
|
|
|
|
'context': node.metadata['postgresql'],
|
|
|
|
'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
|
|
|
|
2021-02-13 07:56:35 +00:00
|
|
|
# FIXME currently we do not have a mechanism to use snapshot-backups of
|
|
|
|
# zfs datasets.
|
2021-02-13 08:04:59 +00:00
|
|
|
if node.has_bundle('backup-client'): # and not node.has_bundle('zfs'):
|
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',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
svc_systemd = {
|
|
|
|
'postgresql': {
|
|
|
|
'needs': {
|
|
|
|
'pkg_apt:postgresql-11',
|
|
|
|
},
|
2020-08-21 14:21:46 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-04-04 16:28:38 +00:00
|
|
|
postgres_dbs = {}
|
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():
|
2020-04-04 16:28:38 +00:00
|
|
|
postgres_dbs[database] = {
|
2020-04-04 15:53:59 +00:00
|
|
|
'owner': config['owner'],
|
2020-08-29 19:30:12 +00:00
|
|
|
'needs': {
|
2020-10-31 09:30:48 +00:00
|
|
|
'postgres_role:',
|
2020-08-29 19:30:12 +00:00
|
|
|
'svc_systemd:postgresql',
|
|
|
|
},
|
2020-04-04 15:53:59 +00:00
|
|
|
}
|