Filip Pytloun | 26ebcc0 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 1 | |
Ales Komarek | 961b0b7 | 2017-04-16 11:39:41 +0200 | [diff] [blame] | 2 | ================== |
| 3 | PostgreSQL Formula |
| 4 | ================== |
Filip Pytloun | 26ebcc0 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 5 | |
Ales Komarek | 961b0b7 | 2017-04-16 11:39:41 +0200 | [diff] [blame] | 6 | PostgreSQL, often simply Postgres, is an object-relational database management |
| 7 | system available for many platforms including Linux, FreeBSD, Solaris, |
| 8 | Microsoft Windows and Mac OS X. It is released under the PostgreSQL License, |
| 9 | which is an MIT-style license, and is thus free and open source software. |
| 10 | PostgreSQL is developed by the PostgreSQL Global Development Group, consisting |
| 11 | of a handful of volunteers employed and supervised by companies such as Red |
| 12 | Hat and EnterpriseDB. |
Filip Pytloun | 26ebcc0 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 13 | |
Filip Pytloun | 26ebcc0 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 14 | |
| 15 | Sample pillars |
| 16 | ============== |
| 17 | |
Ales Komarek | 961b0b7 | 2017-04-16 11:39:41 +0200 | [diff] [blame] | 18 | |
| 19 | Single deployment |
| 20 | ----------------- |
| 21 | |
Filip Pytloun | 26ebcc0 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 22 | Single database server with empty database |
Filip Pytloun | 26ebcc0 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 23 | |
| 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 Pytloun | 3f5f5a9 | 2017-05-25 10:54:59 +0200 | [diff] [blame] | 37 | databasename: |
| 38 | encoding: 'UTF8' |
| 39 | locale: 'cs_CZ' |
| 40 | users: |
| 41 | - name: 'username' |
| 42 | password: 'password' |
| 43 | host: 'localhost' |
| 44 | rights: 'all privileges' |
Filip Pytloun | 26ebcc0 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 45 | |
Ales Komarek | 961b0b7 | 2017-04-16 11:39:41 +0200 | [diff] [blame] | 46 | Single database server with initial data |
Filip Pytloun | 26ebcc0 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 47 | |
| 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 Pytloun | 3f5f5a9 | 2017-05-25 10:54:59 +0200 | [diff] [blame] | 61 | 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 Pytloun | 26ebcc0 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 74 | |
| 75 | User with createdb privileges |
Filip Pytloun | 26ebcc0 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 76 | |
| 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 Pytloun | 3f5f5a9 | 2017-05-25 10:54:59 +0200 | [diff] [blame] | 90 | 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 Pytloun | 26ebcc0 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 99 | |
Ales Komarek | 961b0b7 | 2017-04-16 11:39:41 +0200 | [diff] [blame] | 100 | Database extensions |
Filip Pytloun | 26ebcc0 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 101 | |
| 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 Pytloun | 3f5f5a9 | 2017-05-25 10:54:59 +0200 | [diff] [blame] | 115 | 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 Pytloun | 26ebcc0 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 135 | |
Adam Tengler | b5792ca | 2017-02-13 14:31:23 +0100 | [diff] [blame] | 136 | |
Ales Komarek | 961b0b7 | 2017-04-16 11:39:41 +0200 | [diff] [blame] | 137 | Master-slave cluster |
| 138 | -------------------- |
Adam Tengler | b5792ca | 2017-02-13 14:31:23 +0100 | [diff] [blame] | 139 | |
| 140 | Master node |
Adam Tengler | b5792ca | 2017-02-13 14:31:23 +0100 | [diff] [blame] | 141 | |
| 142 | .. code-block:: yaml |
| 143 | |
Ales Komarek | 961b0b7 | 2017-04-16 11:39:41 +0200 | [diff] [blame] | 144 | 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 Tengler | b5792ca | 2017-02-13 14:31:23 +0100 | [diff] [blame] | 175 | |
Ales Komarek | 961b0b7 | 2017-04-16 11:39:41 +0200 | [diff] [blame] | 176 | Slave nodes |
Adam Tengler | b5792ca | 2017-02-13 14:31:23 +0100 | [diff] [blame] | 177 | |
| 178 | .. code-block:: yaml |
| 179 | |
Ales Komarek | 961b0b7 | 2017-04-16 11:39:41 +0200 | [diff] [blame] | 180 | 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 | |
| 208 | Multi-master cluster |
| 209 | -------------------- |
Adam Tengler | b5792ca | 2017-02-13 14:31:23 +0100 | [diff] [blame] | 210 | |
| 211 | Multi-master cluster with 2ndQuadrant bi-directional replication plugin |
| 212 | |
| 213 | Master node |
Adam Tengler | b5792ca | 2017-02-13 14:31:23 +0100 | [diff] [blame] | 214 | |
| 215 | .. code-block:: yaml |
| 216 | |
Ales Komarek | 961b0b7 | 2017-04-16 11:39:41 +0200 | [diff] [blame] | 217 | 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 Tengler | b5792ca | 2017-02-13 14:31:23 +0100 | [diff] [blame] | 242 | |
| 243 | Slave node |
Adam Tengler | b5792ca | 2017-02-13 14:31:23 +0100 | [diff] [blame] | 244 | |
| 245 | .. code-block:: yaml |
| 246 | |
Ales Komarek | 961b0b7 | 2017-04-16 11:39:41 +0200 | [diff] [blame] | 247 | 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 Pytloun | 4808fbb | 2017-04-19 16:12:33 +0200 | [diff] [blame] | 274 | Client |
| 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 Stoiko | e7debf1 | 2017-05-11 10:46:10 +0300 | [diff] [blame] | 299 | init: |
| 300 | maintenance_db: mydb |
| 301 | queries: |
| 302 | - INSERT INTO login VALUES (11, 1) ; |
| 303 | - INSERT INTO device VALUES (1, 11, 42); |
Filip Pytloun | 4808fbb | 2017-04-19 16:12:33 +0200 | [diff] [blame] | 304 | |
Adam Tengler | b5792ca | 2017-02-13 14:31:23 +0100 | [diff] [blame] | 305 | |
| 306 | Sample usage |
| 307 | ============ |
Filip Pytloun | 26ebcc0 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 308 | |
| 309 | Init database cluster with given locale |
| 310 | |
Ales Komarek | 961b0b7 | 2017-04-16 11:39:41 +0200 | [diff] [blame] | 311 | .. code-block:: bash |
| 312 | |
Filip Pytloun | 26ebcc0 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 313 | sudo su - postgres -c "/usr/lib/postgresql/9.3/bin/initdb /var/lib/postgresql/9.3/main --locale=C" |
| 314 | |
| 315 | Convert PostgreSQL cluster from 9.1 to 9.3 |
| 316 | |
Ales Komarek | 961b0b7 | 2017-04-16 11:39:41 +0200 | [diff] [blame] | 317 | .. code-block:: bash |
| 318 | |
Filip Pytloun | 26ebcc0 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 319 | 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 | |
| 321 | Ubuntu on 14.04 on some machines won't create default cluster |
| 322 | |
Ales Komarek | 961b0b7 | 2017-04-16 11:39:41 +0200 | [diff] [blame] | 323 | .. code-block:: bash |
| 324 | |
Filip Pytloun | 26ebcc0 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 325 | sudo pg_createcluster 9.3 main --start |
| 326 | |
Ales Komarek | 961b0b7 | 2017-04-16 11:39:41 +0200 | [diff] [blame] | 327 | |
| 328 | More information |
| 329 | ================ |
Filip Pytloun | 26ebcc0 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 330 | |
| 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 Pytloun | 4afffd8 | 2017-02-02 13:02:03 +0100 | [diff] [blame] | 334 | * https://gist.github.com/ibussieres/11262268 - upgrade instructions for ubuntu |
Ales Komarek | 961b0b7 | 2017-04-16 11:39:41 +0200 | [diff] [blame] | 335 | |
| 336 | |
Filip Pytloun | 4afffd8 | 2017-02-02 13:02:03 +0100 | [diff] [blame] | 337 | Documentation and Bugs |
| 338 | ====================== |
| 339 | |
| 340 | To learn how to install and update salt-formulas, consult the documentation |
| 341 | available online at: |
| 342 | |
| 343 | http://salt-formulas.readthedocs.io/ |
| 344 | |
| 345 | In the unfortunate event that bugs are discovered, they should be reported to |
| 346 | the appropriate issue tracker. Use Github issue tracker for specific salt |
| 347 | formula: |
| 348 | |
| 349 | https://github.com/salt-formulas/salt-formula-postgresql/issues |
| 350 | |
| 351 | For feature requests, bug reports or blueprints affecting entire ecosystem, |
| 352 | use Launchpad salt-formulas project: |
| 353 | |
| 354 | https://launchpad.net/salt-formulas |
| 355 | |
| 356 | You can also join salt-formulas-users team and subscribe to mailing list: |
| 357 | |
| 358 | https://launchpad.net/~salt-formulas-users |
| 359 | |
| 360 | Developers wishing to work on the salt-formulas projects should always base |
| 361 | their work on master branch and submit pull request against specific formula. |
| 362 | |
| 363 | https://github.com/salt-formulas/salt-formula-postgresql |
| 364 | |
| 365 | Any questions or feedback is always welcome so feel free to join our IRC |
| 366 | channel: |
| 367 | |
| 368 | #salt-formulas @ irc.freenode.net |