blob: 60738f8ae5a6eb247a14eb2f4944a7ee253c27a9 [file] [log] [blame]
Filip Pytloun26ebcc02015-10-06 16:28:32 +02001
Ales Komarek961b0b72017-04-16 11:39:41 +02002==================
3PostgreSQL Formula
4==================
Filip Pytloun26ebcc02015-10-06 16:28:32 +02005
Ales Komarek961b0b72017-04-16 11:39:41 +02006PostgreSQL, often simply Postgres, is an object-relational database management
7system available for many platforms including Linux, FreeBSD, Solaris,
8Microsoft Windows and Mac OS X. It is released under the PostgreSQL License,
9which is an MIT-style license, and is thus free and open source software.
10PostgreSQL is developed by the PostgreSQL Global Development Group, consisting
11of a handful of volunteers employed and supervised by companies such as Red
12Hat and EnterpriseDB.
Filip Pytloun26ebcc02015-10-06 16:28:32 +020013
Filip Pytloun26ebcc02015-10-06 16:28:32 +020014
15Sample pillars
16==============
17
Ales Komarek961b0b72017-04-16 11:39:41 +020018
19Single deployment
20-----------------
21
Filip Pytloun26ebcc02015-10-06 16:28:32 +020022Single database server with empty database
Filip Pytloun26ebcc02015-10-06 16:28:32 +020023
24.. code-block:: yaml
25
26 postgresql:
27 server:
28 enabled: true
29 version: 9.1
30 bind:
31 address: 127.0.0.1
32 port: 5432
33 protocol: tcp
34 clients:
35 - 127.0.0.1
36 database:
Filip Pytloun3f5f5a92017-05-25 10:54:59 +020037 databasename:
38 encoding: 'UTF8'
39 locale: 'cs_CZ'
40 users:
41 - name: 'username'
42 password: 'password'
43 host: 'localhost'
44 rights: 'all privileges'
Filip Pytloun26ebcc02015-10-06 16:28:32 +020045
Ales Komarek961b0b72017-04-16 11:39:41 +020046Single database server with initial data
Filip Pytloun26ebcc02015-10-06 16:28:32 +020047
48.. code-block:: yaml
49
50 postgresql:
51 server:
52 enabled: true
53 version: 9.1
54 bind:
55 - address: 127.0.0.1
56 port: 5432
57 protocol: tcp
58 clients:
59 - 127.0.0.1
60 database:
Filip Pytloun3f5f5a92017-05-25 10:54:59 +020061 databasename:
62 encoding: 'UTF8'
63 locale: 'cs_CZ'
64 initial_data:
65 engine: backupninja
66 source: backup.host
67 host: original-host-name
68 database: original-database-name
69 users:
70 - name: 'username'
71 password: 'password'
72 host: 'localhost'
73 rights: 'all privileges'
Filip Pytloun26ebcc02015-10-06 16:28:32 +020074
75User with createdb privileges
Filip Pytloun26ebcc02015-10-06 16:28:32 +020076
77.. code-block:: yaml
78
79 postgresql:
80 server:
81 enabled: true
82 version: 9.1
83 bind:
84 address: 127.0.0.1
85 port: 5432
86 protocol: tcp
87 clients:
88 - 127.0.0.1
89 database:
Filip Pytloun3f5f5a92017-05-25 10:54:59 +020090 databasename:
91 encoding: 'UTF8'
92 locale: 'cs_CZ'
93 users:
94 - name: 'username'
95 password: 'password'
96 host: 'localhost'
97 createdb: true
98 rights: 'all privileges'
Filip Pytloun26ebcc02015-10-06 16:28:32 +020099
Ales Komarek961b0b72017-04-16 11:39:41 +0200100Database extensions
Filip Pytloun26ebcc02015-10-06 16:28:32 +0200101
102.. code-block:: yaml
103
104 postgresql:
105 server:
106 enabled: true
107 version: 9.1
108 bind:
109 address: 127.0.0.1
110 port: 5432
111 protocol: tcp
112 clients:
113 - 127.0.0.1
114 database:
Filip Pytloun3f5f5a92017-05-25 10:54:59 +0200115 databasename:
116 encoding: 'UTF8'
117 locale: 'cs_CZ'
118 users:
119 - name: 'username'
120 password: 'password'
121 host: 'localhost'
122 createdb: true
123 rights: 'all privileges'
124 extension:
125 postgis_topology:
126 enabled: true
127 fuzzystrmatch:
128 enabled: true
129 postgis_tiger_geocoder:
130 enabled: true
131 postgis:
132 enabled: true
133 pkgs:
134 - postgresql-9.1-postgis-2.1
Filip Pytloun26ebcc02015-10-06 16:28:32 +0200135
Adam Tenglerb5792ca2017-02-13 14:31:23 +0100136
Ales Komarek961b0b72017-04-16 11:39:41 +0200137Master-slave cluster
138--------------------
Adam Tenglerb5792ca2017-02-13 14:31:23 +0100139
140Master node
Adam Tenglerb5792ca2017-02-13 14:31:23 +0100141
142.. code-block:: yaml
143
Ales Komarek961b0b72017-04-16 11:39:41 +0200144 postgresql:
145 server:
146 enabled: true
147 version: 9.6
148 bind:
149 address: 0.0.0.0
150 database:
151 mydb: ...
152 cluster:
153 enabled: true
154 role: master
155 mode: hot_standby
156 members:
157 - host: "172.16.10.101"
158 - host: "172.16.10.102"
159 - host: "172.16.10.103"
160 replication_user:
161 name: repuser
162 password: password
163 keepalived:
164 cluster:
165 enabled: True
166 instance:
167 VIP:
168 notify_action:
169 master:
170 - 'if [ -f /root/postgresql/flags/failover ]; then touch /var/lib/postgresql/${postgresql:server:version}/main/trigger; fi'
171 backup:
172 - 'if [ -f /root/postgresql/flags/failover ]; then service postgresql stop; fi'
173 fault:
174 - 'if [ -f /root/postgresql/flags/failover ]; then service postgresql stop; fi'
Adam Tenglerb5792ca2017-02-13 14:31:23 +0100175
Ales Komarek961b0b72017-04-16 11:39:41 +0200176Slave nodes
Adam Tenglerb5792ca2017-02-13 14:31:23 +0100177
178.. code-block:: yaml
179
Ales Komarek961b0b72017-04-16 11:39:41 +0200180 postgresql:
181 server:
182 enabled: true
183 version: 9.6
184 bind:
185 address: 0.0.0.0
186 cluster:
187 enabled: true
188 role: slave
189 mode: hot_standby
190 master:
191 host: "172.16.10.100"
192 port: 5432
193 user: repuser
194 password: password
195 keepalived:
196 cluster:
197 enabled: True
198 instance:
199 VIP:
200 notify_action:
201 master:
202 - 'if [ -f /root/postgresql/flags/failover ]; then touch /var/lib/postgresql/${postgresql:server:version}/main/trigger; fi'
203 backup:
204 - 'if [ -f /root/postgresql/flags/failover ]; then service postgresql stop; fi'
205 fault:
206 - 'if [ -f /root/postgresql/flags/failover ]; then service postgresql stop; fi'
207
208Multi-master cluster
209--------------------
Adam Tenglerb5792ca2017-02-13 14:31:23 +0100210
211Multi-master cluster with 2ndQuadrant bi-directional replication plugin
212
213Master node
Adam Tenglerb5792ca2017-02-13 14:31:23 +0100214
215.. code-block:: yaml
216
Ales Komarek961b0b72017-04-16 11:39:41 +0200217 postgresql:
218 server:
219 enabled: true
220 version: 9.4
221 bind:
222 address: 0.0.0.0
223 database:
224 mydb:
225 extension:
226 bdr:
227 enabled: true
228 btree_gist:
229 enabled: true
230 cluster:
231 enabled: true
232 mode: bdr
233 role: master
234 members:
235 - host: "172.16.10.101"
236 - host: "172.16.10.102"
237 - host: "172.16.10.101"
238 local: "172.16.10.101"
239 replication_user:
240 name: repuser
241 password: password
Adam Tenglerb5792ca2017-02-13 14:31:23 +0100242
243Slave node
Adam Tenglerb5792ca2017-02-13 14:31:23 +0100244
245.. code-block:: yaml
246
Ales Komarek961b0b72017-04-16 11:39:41 +0200247 postgresql:
248 server:
249 enabled: true
250 version: 9.4
251 bind:
252 address: 0.0.0.0
253 database:
254 mydb:
255 extension:
256 bdr:
257 enabled: true
258 btree_gist:
259 enabled: true
260 cluster:
261 enabled: true
262 mode: bdr
263 role: master
264 members:
265 - host: "172.16.10.101"
266 - host: "172.16.10.102"
267 - host: "172.16.10.101"
268 local: "172.16.10.102"
269 master: "172.16.10.101"
270 replication_user:
271 name: repuser
272 password: password
273
Filip Pytloun4808fbb2017-04-19 16:12:33 +0200274Client
275------
276
277.. code-block:: yaml
278
279 postgresql:
280 client:
281 server:
282 server01:
283 admin:
284 host: database.host
285 port: 5432
286 user: root
287 password: password
288 database:
289 mydb:
290 enabled: true
291 encoding: 'UTF8'
292 locale: 'en_US'
293 users:
294 - name: test
295 password: test
296 host: localhost
297 createdb: true
298 rights: all privileges
Volodymyr Stoikoe7debf12017-05-11 10:46:10 +0300299 init:
300 maintenance_db: mydb
301 queries:
302 - INSERT INTO login VALUES (11, 1) ;
303 - INSERT INTO device VALUES (1, 11, 42);
Filip Pytloun4808fbb2017-04-19 16:12:33 +0200304
Adam Tenglerb5792ca2017-02-13 14:31:23 +0100305
306Sample usage
307============
Filip Pytloun26ebcc02015-10-06 16:28:32 +0200308
309Init database cluster with given locale
310
Ales Komarek961b0b72017-04-16 11:39:41 +0200311.. code-block:: bash
312
Filip Pytloun26ebcc02015-10-06 16:28:32 +0200313 sudo su - postgres -c "/usr/lib/postgresql/9.3/bin/initdb /var/lib/postgresql/9.3/main --locale=C"
314
315Convert PostgreSQL cluster from 9.1 to 9.3
316
Ales Komarek961b0b72017-04-16 11:39:41 +0200317.. code-block:: bash
318
Filip Pytloun26ebcc02015-10-06 16:28:32 +0200319 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"'
320
321Ubuntu on 14.04 on some machines won't create default cluster
322
Ales Komarek961b0b72017-04-16 11:39:41 +0200323.. code-block:: bash
324
Filip Pytloun26ebcc02015-10-06 16:28:32 +0200325 sudo pg_createcluster 9.3 main --start
326
Ales Komarek961b0b72017-04-16 11:39:41 +0200327
328More information
329================
Filip Pytloun26ebcc02015-10-06 16:28:32 +0200330
331* http://www.postgresql.org/
332* http://www.postgresql.org/docs/9.1/interactive/index.html
333* http://momjian.us/main/writings/pgsql/hw_performance/
Filip Pytloun4afffd82017-02-02 13:02:03 +0100334* https://gist.github.com/ibussieres/11262268 - upgrade instructions for ubuntu
Ales Komarek961b0b72017-04-16 11:39:41 +0200335
336
Filip Pytloun4afffd82017-02-02 13:02:03 +0100337Documentation and Bugs
338======================
339
340To learn how to install and update salt-formulas, consult the documentation
341available online at:
342
343 http://salt-formulas.readthedocs.io/
344
345In the unfortunate event that bugs are discovered, they should be reported to
346the appropriate issue tracker. Use Github issue tracker for specific salt
347formula:
348
349 https://github.com/salt-formulas/salt-formula-postgresql/issues
350
351For feature requests, bug reports or blueprints affecting entire ecosystem,
352use Launchpad salt-formulas project:
353
354 https://launchpad.net/salt-formulas
355
356You can also join salt-formulas-users team and subscribe to mailing list:
357
358 https://launchpad.net/~salt-formulas-users
359
360Developers wishing to work on the salt-formulas projects should always base
361their work on master branch and submit pull request against specific formula.
362
363 https://github.com/salt-formulas/salt-formula-postgresql
364
365Any questions or feedback is always welcome so feel free to join our IRC
366channel:
367
368 #salt-formulas @ irc.freenode.net