blob: 1a27053191aa9bddc2dafbd5742874e0294339a4 [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:
37 name: 'databasename'
38 encoding: 'UTF8'
39 locale: 'cs_CZ'
40 user:
41 name: 'username'
42 password: 'password'
43 host: 'localhost'
44 rights: 'all privileges'
45
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:
61 name: '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
Ales Komarek961b0b72017-04-16 11:39:41 +020069 users:
70 - name: 'username'
Filip Pytloun26ebcc02015-10-06 16:28:32 +020071 password: 'password'
72 host: 'localhost'
73 rights: 'all privileges'
74
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:
90 name: 'databasename'
91 encoding: 'UTF8'
92 locale: 'cs_CZ'
Ales Komarek961b0b72017-04-16 11:39:41 +020093 users:
94 - name: 'username'
Filip Pytloun26ebcc02015-10-06 16:28:32 +020095 password: 'password'
96 host: 'localhost'
97 createdb: true
98 rights: 'all privileges'
99
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:
115 name: 'databasename'
116 encoding: 'UTF8'
117 locale: 'cs_CZ'
Ales Komarek961b0b72017-04-16 11:39:41 +0200118 users:
119 - name: 'username'
Filip Pytloun26ebcc02015-10-06 16:28:32 +0200120 password: 'password'
121 host: 'localhost'
122 createdb: true
123 rights: 'all privileges'
124 extension:
125 postgis_topology:
Adam Tenglerb5792ca2017-02-13 14:31:23 +0100126 enabled: true
Filip Pytloun26ebcc02015-10-06 16:28:32 +0200127 fuzzystrmatch:
Adam Tenglerb5792ca2017-02-13 14:31:23 +0100128 enabled: true
Filip Pytloun26ebcc02015-10-06 16:28:32 +0200129 postgis_tiger_geocoder:
Adam Tenglerb5792ca2017-02-13 14:31:23 +0100130 enabled: true
Filip Pytloun26ebcc02015-10-06 16:28:32 +0200131 postgis:
Adam Tenglerb5792ca2017-02-13 14:31:23 +0100132 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
Adam Tenglerb5792ca2017-02-13 14:31:23 +0100274
275Sample usage
276============
Filip Pytloun26ebcc02015-10-06 16:28:32 +0200277
278Init database cluster with given locale
279
Ales Komarek961b0b72017-04-16 11:39:41 +0200280.. code-block:: bash
281
Filip Pytloun26ebcc02015-10-06 16:28:32 +0200282 sudo su - postgres -c "/usr/lib/postgresql/9.3/bin/initdb /var/lib/postgresql/9.3/main --locale=C"
283
284Convert PostgreSQL cluster from 9.1 to 9.3
285
Ales Komarek961b0b72017-04-16 11:39:41 +0200286.. code-block:: bash
287
Filip Pytloun26ebcc02015-10-06 16:28:32 +0200288 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"'
289
290Ubuntu on 14.04 on some machines won't create default cluster
291
Ales Komarek961b0b72017-04-16 11:39:41 +0200292.. code-block:: bash
293
Filip Pytloun26ebcc02015-10-06 16:28:32 +0200294 sudo pg_createcluster 9.3 main --start
295
Ales Komarek961b0b72017-04-16 11:39:41 +0200296
297More information
298================
Filip Pytloun26ebcc02015-10-06 16:28:32 +0200299
300* http://www.postgresql.org/
301* http://www.postgresql.org/docs/9.1/interactive/index.html
302* http://momjian.us/main/writings/pgsql/hw_performance/
Filip Pytloun4afffd82017-02-02 13:02:03 +0100303* https://gist.github.com/ibussieres/11262268 - upgrade instructions for ubuntu
Ales Komarek961b0b72017-04-16 11:39:41 +0200304
305
Filip Pytloun4afffd82017-02-02 13:02:03 +0100306Documentation and Bugs
307======================
308
309To learn how to install and update salt-formulas, consult the documentation
310available online at:
311
312 http://salt-formulas.readthedocs.io/
313
314In the unfortunate event that bugs are discovered, they should be reported to
315the appropriate issue tracker. Use Github issue tracker for specific salt
316formula:
317
318 https://github.com/salt-formulas/salt-formula-postgresql/issues
319
320For feature requests, bug reports or blueprints affecting entire ecosystem,
321use Launchpad salt-formulas project:
322
323 https://launchpad.net/salt-formulas
324
325You can also join salt-formulas-users team and subscribe to mailing list:
326
327 https://launchpad.net/~salt-formulas-users
328
329Developers wishing to work on the salt-formulas projects should always base
330their work on master branch and submit pull request against specific formula.
331
332 https://github.com/salt-formulas/salt-formula-postgresql
333
334Any questions or feedback is always welcome so feel free to join our IRC
335channel:
336
337 #salt-formulas @ irc.freenode.net