Fixed readme, allow conditional database names
diff --git a/README.rst b/README.rst
index d7e2dd8..1a27053 100644
--- a/README.rst
+++ b/README.rst
@@ -1,22 +1,25 @@
-==========
-PostgreSQL
-==========
+==================
+PostgreSQL Formula
+==================
-PostgreSQL, often simply Postgres, is an object-relational database management system available for many platforms including Linux, FreeBSD, Solaris, Microsoft Windows and Mac OS X. It is released under the PostgreSQL License, which is an MIT-style license, and is thus free and open source software. PostgreSQL is developed by the PostgreSQL Global Development Group, consisting of a handful of volunteers employed and supervised by companies such as Red Hat and EnterpriseDB.
+PostgreSQL, often simply Postgres, is an object-relational database management
+system available for many platforms including Linux, FreeBSD, Solaris,
+Microsoft Windows and Mac OS X. It is released under the PostgreSQL License,
+which is an MIT-style license, and is thus free and open source software.
+PostgreSQL is developed by the PostgreSQL Global Development Group, consisting
+of a handful of volunteers employed and supervised by companies such as Red
+Hat and EnterpriseDB.
-Support
-=======
-
-* required by: [redmine](../master/redmine)
-* service versions: 9.1
-* operating systems: Ubuntu 12.04
Sample pillars
==============
+
+Single deployment
+-----------------
+
Single database server with empty database
-------------------------------------------
.. code-block:: yaml
@@ -40,8 +43,7 @@
host: 'localhost'
rights: 'all privileges'
-Single database server with prepopulated database
--------------------------------------------------
+Single database server with initial data
.. code-block:: yaml
@@ -64,14 +66,13 @@
source: backup.host
host: original-host-name
database: original-database-name
- user:
- name: 'username'
+ users:
+ - name: 'username'
password: 'password'
host: 'localhost'
rights: 'all privileges'
User with createdb privileges
------------------------------
.. code-block:: yaml
@@ -89,16 +90,14 @@
name: 'databasename'
encoding: 'UTF8'
locale: 'cs_CZ'
- user:
- name: 'username'
+ users:
+ - name: 'username'
password: 'password'
host: 'localhost'
createdb: true
rights: 'all privileges'
-
-PostgreSQL extensions
----------------------
+Database extensions
.. code-block:: yaml
@@ -116,8 +115,8 @@
name: 'databasename'
encoding: 'UTF8'
locale: 'cs_CZ'
- user:
- name: 'username'
+ users:
+ - name: 'username'
password: 'password'
host: 'localhost'
createdb: true
@@ -134,170 +133,176 @@
pkgs:
- postgresql-9.1-postgis-2.1
-Cluster
-=======
-Basic streaming replication.
+Master-slave cluster
+--------------------
Master node
------------
.. code-block:: yaml
- postgresql:
- server:
- enabled: true
- version: 9.6
- bind:
- address: 0.0.0.0
- database:
- mydb: ...
- cluster:
- enabled: true
- role: master
- mode: hot_standby
- members:
- - host: "172.16.10.101"
- - host: "172.16.10.102"
- - host: "172.16.10.103"
- replication_user:
- name: repuser
- password: password
- keepalived:
- cluster:
- enabled: True
- instance:
- VIP:
- notify_action:
- master:
- - 'if [ -f /root/postgresql/flags/failover ]; then touch /var/lib/postgresql/${postgresql:server:version}/main/trigger; fi'
- backup:
- - 'if [ -f /root/postgresql/flags/failover ]; then service postgresql stop; fi'
- fault:
- - 'if [ -f /root/postgresql/flags/failover ]; then service postgresql stop; fi'
+ postgresql:
+ server:
+ enabled: true
+ version: 9.6
+ bind:
+ address: 0.0.0.0
+ database:
+ mydb: ...
+ cluster:
+ enabled: true
+ role: master
+ mode: hot_standby
+ members:
+ - host: "172.16.10.101"
+ - host: "172.16.10.102"
+ - host: "172.16.10.103"
+ replication_user:
+ name: repuser
+ password: password
+ keepalived:
+ cluster:
+ enabled: True
+ instance:
+ VIP:
+ notify_action:
+ master:
+ - 'if [ -f /root/postgresql/flags/failover ]; then touch /var/lib/postgresql/${postgresql:server:version}/main/trigger; fi'
+ backup:
+ - 'if [ -f /root/postgresql/flags/failover ]; then service postgresql stop; fi'
+ fault:
+ - 'if [ -f /root/postgresql/flags/failover ]; then service postgresql stop; fi'
-Slave node
-----------
+Slave nodes
.. code-block:: yaml
- postgresql:
- server:
- enabled: true
- version: 9.6
- bind:
- address: 0.0.0.0
- cluster:
- enabled: true
- role: slave
- mode: hot_standby
- master:
- host: "172.16.10.100"
- port: 5432
- user: repuser
- password: password
- keepalived:
- cluster:
- enabled: True
- instance:
- VIP:
- notify_action:
- master:
- - 'if [ -f /root/postgresql/flags/failover ]; then touch /var/lib/postgresql/${postgresql:server:version}/main/trigger; fi'
- backup:
- - 'if [ -f /root/postgresql/flags/failover ]; then service postgresql stop; fi'
- fault:
- - 'if [ -f /root/postgresql/flags/failover ]; then service postgresql stop; fi'
+ postgresql:
+ server:
+ enabled: true
+ version: 9.6
+ bind:
+ address: 0.0.0.0
+ cluster:
+ enabled: true
+ role: slave
+ mode: hot_standby
+ master:
+ host: "172.16.10.100"
+ port: 5432
+ user: repuser
+ password: password
+ keepalived:
+ cluster:
+ enabled: True
+ instance:
+ VIP:
+ notify_action:
+ master:
+ - 'if [ -f /root/postgresql/flags/failover ]; then touch /var/lib/postgresql/${postgresql:server:version}/main/trigger; fi'
+ backup:
+ - 'if [ -f /root/postgresql/flags/failover ]; then service postgresql stop; fi'
+ fault:
+ - 'if [ -f /root/postgresql/flags/failover ]; then service postgresql stop; fi'
+
+Multi-master cluster
+--------------------
Multi-master cluster with 2ndQuadrant bi-directional replication plugin
Master node
------------
.. code-block:: yaml
- postgresql:
- server:
- enabled: true
- version: 9.4
- bind:
- address: 0.0.0.0
- database:
- mydb:
- extension:
- bdr:
- enabled: true
- btree_gist:
- enabled: true
- ...
- cluster:
- enabled: true
- mode: bdr
- role: master
- members:
- - host: "172.16.10.101"
- - host: "172.16.10.102"
- - host: "172.16.10.101"
- local: "172.16.10.101"
- replication_user:
- name: repuser
- password: password
+ postgresql:
+ server:
+ enabled: true
+ version: 9.4
+ bind:
+ address: 0.0.0.0
+ database:
+ mydb:
+ extension:
+ bdr:
+ enabled: true
+ btree_gist:
+ enabled: true
+ cluster:
+ enabled: true
+ mode: bdr
+ role: master
+ members:
+ - host: "172.16.10.101"
+ - host: "172.16.10.102"
+ - host: "172.16.10.101"
+ local: "172.16.10.101"
+ replication_user:
+ name: repuser
+ password: password
Slave node
-----------
.. code-block:: yaml
- postgresql:
- server:
- enabled: true
- version: 9.4
- bind:
- address: 0.0.0.0
- database:
- mydb:
- extension:
- bdr:
- enabled: true
- btree_gist:
- enabled: true
- ...
- cluster:
- enabled: true
- mode: bdr
- role: master
- members:
- - host: "172.16.10.101"
- - host: "172.16.10.102"
- - host: "172.16.10.101"
- local: "172.16.10.102"
- master: "172.16.10.101"
- replication_user:
- name: repuser
- password: password
+ postgresql:
+ server:
+ enabled: true
+ version: 9.4
+ bind:
+ address: 0.0.0.0
+ database:
+ mydb:
+ extension:
+ bdr:
+ enabled: true
+ btree_gist:
+ enabled: true
+ cluster:
+ enabled: true
+ mode: bdr
+ role: master
+ members:
+ - host: "172.16.10.101"
+ - host: "172.16.10.102"
+ - host: "172.16.10.101"
+ local: "172.16.10.102"
+ master: "172.16.10.101"
+ replication_user:
+ name: repuser
+ password: password
+
Sample usage
============
Init database cluster with given locale
+.. code-block:: bash
+
sudo su - postgres -c "/usr/lib/postgresql/9.3/bin/initdb /var/lib/postgresql/9.3/main --locale=C"
Convert PostgreSQL cluster from 9.1 to 9.3
+.. code-block:: bash
+
sudo su - postgres -c '/usr/lib/postgresql/9.3/bin/pg_upgrade -b /usr/lib/postgresql/9.1/bin -B /usr/lib/postgresql/9.3/bin -d /var/lib/postgresql/9.1/main/ -D /var/lib/postgresql/9.3/main/ -O "-c config_file=/etc/postgresql/9.3/main/postgresql.conf" -o "-c config_file=/etc/postgresql/9.1/main/postgresql.conf"'
Ubuntu on 14.04 on some machines won't create default cluster
+.. code-block:: bash
+
sudo pg_createcluster 9.3 main --start
-Read more
-=========
+
+More information
+================
* http://www.postgresql.org/
* http://www.postgresql.org/docs/9.1/interactive/index.html
* http://momjian.us/main/writings/pgsql/hw_performance/
* https://gist.github.com/ibussieres/11262268 - upgrade instructions for ubuntu
+
+
Documentation and Bugs
======================
diff --git a/postgresql/server.sls b/postgresql/server.sls
index 497e2f2..883a787 100644
--- a/postgresql/server.sls
+++ b/postgresql/server.sls
@@ -82,7 +82,7 @@
postgresql_database_{{ database_name }}:
postgres_database.present:
- - name: {{ database_name }}
+ - name: {{ database.get('name', database_name) }}
- encoding: {{ database.encoding }}
- user: postgres
- template: template0