mirror of
https://github.com/saltstack-formulas/postgres-formula.git
synced 2025-04-17 10:10:31 +00:00
Allow to specify a tablespace for a database
* Tablespaces have to be created before the databases * Add pillar examples * Add tests
This commit is contained in:
parent
87a9980729
commit
9719e2354e
3 changed files with 42 additions and 26 deletions
|
@ -47,6 +47,9 @@ postgres:
|
||||||
- ['local', 'db1', 'localUser']
|
- ['local', 'db1', 'localUser']
|
||||||
- ['host', 'db2', 'remoteUser', '123.123.0.0/24']
|
- ['host', 'db2', 'remoteUser', '123.123.0.0/24']
|
||||||
|
|
||||||
|
tablespaces:
|
||||||
|
my_space: /srv/my_tablespace
|
||||||
|
|
||||||
databases:
|
databases:
|
||||||
db1:
|
db1:
|
||||||
owner: 'localUser'
|
owner: 'localUser'
|
||||||
|
@ -68,9 +71,10 @@ postgres:
|
||||||
template: 'template0'
|
template: 'template0'
|
||||||
lc_ctype: 'C.UTF-8'
|
lc_ctype: 'C.UTF-8'
|
||||||
lc_collate: 'C.UTF-8'
|
lc_collate: 'C.UTF-8'
|
||||||
|
tablespace: 'my_space'
|
||||||
# optional extensions to enable on database
|
# optional extensions to enable on database
|
||||||
extensions:
|
# extensions:
|
||||||
postgis:
|
# postgis:
|
||||||
# backup extension defaults to .bak if postgresconf_backup is True.
|
# backup extension defaults to .bak if postgresconf_backup is True.
|
||||||
# Set to False to stop creation of backup on postgresql.conf changes.
|
# Set to False to stop creation of backup on postgresql.conf changes.
|
||||||
postgresconf_backup: True
|
postgresconf_backup: True
|
||||||
|
|
|
@ -112,6 +112,27 @@ postgresql-user-{{ name }}:
|
||||||
- service: postgresql-running
|
- service: postgresql-running
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
{% for name, directory in postgres.tablespaces.items() %}
|
||||||
|
postgresql-tablespace-dir-perms-{{ directory}}:
|
||||||
|
file.directory:
|
||||||
|
- name: {{ directory }}
|
||||||
|
- user: postgres
|
||||||
|
- group: postgres
|
||||||
|
- makedirs: True
|
||||||
|
- recurse:
|
||||||
|
- user
|
||||||
|
- group
|
||||||
|
|
||||||
|
postgresql-tablespace-{{ name }}:
|
||||||
|
postgres_tablespace.present:
|
||||||
|
- name: {{ name }}
|
||||||
|
- directory: {{ directory }}
|
||||||
|
- user: postgres
|
||||||
|
- require:
|
||||||
|
- service: postgresql-running
|
||||||
|
- file: postgresql-tablespace-dir-perms-{{ directory}}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
{% for name, db in postgres.databases.items() %}
|
{% for name, db in postgres.databases.items() %}
|
||||||
postgresql-db-{{ name }}:
|
postgresql-db-{{ name }}:
|
||||||
{% if db.get('ensure', 'present') == 'absent' %}
|
{% if db.get('ensure', 'present') == 'absent' %}
|
||||||
|
@ -126,6 +147,7 @@ postgresql-db-{{ name }}:
|
||||||
- lc_ctype: {{ db.get('lc_ctype', 'en_US.UTF8') }}
|
- lc_ctype: {{ db.get('lc_ctype', 'en_US.UTF8') }}
|
||||||
- lc_collate: {{ db.get('lc_collate', 'en_US.UTF8') }}
|
- lc_collate: {{ db.get('lc_collate', 'en_US.UTF8') }}
|
||||||
- template: {{ db.get('template', 'template0') }}
|
- template: {{ db.get('template', 'template0') }}
|
||||||
|
- tablespace: {{ db.get('tablespace', 'pg_default') }}
|
||||||
{% if db.get('owner') %}
|
{% if db.get('owner') %}
|
||||||
- owner: {{ db.get('owner') }}
|
- owner: {{ db.get('owner') }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -171,24 +193,3 @@ postgresql-ext-{{ ext }}-for-db-{{ name }}:
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
|
||||||
{% for name, directory in postgres.tablespaces.items() %}
|
|
||||||
postgresql-tablespace-dir-perms-{{ directory}}:
|
|
||||||
file.directory:
|
|
||||||
- name: {{ directory }}
|
|
||||||
- user: postgres
|
|
||||||
- group: postgres
|
|
||||||
- makedirs: True
|
|
||||||
- recurse:
|
|
||||||
- user
|
|
||||||
- group
|
|
||||||
|
|
||||||
postgresql-tablespace-{{ name }}:
|
|
||||||
postgres_tablespace.present:
|
|
||||||
- name: {{ name }}
|
|
||||||
- directory: {{ directory }}
|
|
||||||
- require:
|
|
||||||
- service: postgresql-running
|
|
||||||
- file: postgresql-tablespace-dir-perms-{{ directory}}
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,21 @@
|
||||||
require "serverspec"
|
require 'serverspec'
|
||||||
|
|
||||||
describe service("postgres") do
|
describe service('postgresql') do
|
||||||
it { should be_enabled }
|
it { should be_enabled }
|
||||||
it { should be_running }
|
it { should be_running }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe port("5432") do
|
describe port('5432') do
|
||||||
it { should be_listening }
|
it { should be_listening }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe file('/srv/my_tablespace') do
|
||||||
|
it { should be_directory }
|
||||||
|
it { should be_mode 700 }
|
||||||
|
it { should be_owned_by 'postgres' }
|
||||||
|
it { should be_grouped_into 'postgres' }
|
||||||
|
end
|
||||||
|
|
||||||
|
describe command('su - postgres -c "psql -qtc \"\l+ db2\""') do
|
||||||
|
its(:stdout) { should match(/db2.*localUser.*UTF8.*C.UTF-8.*C.UTF-8.*my_space/) }
|
||||||
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue