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: |
| 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 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: |
| 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 Komarek | 961b0b7 | 2017-04-16 11:39:41 +0200 | [diff] [blame] | 69 | users: |
| 70 | - name: 'username' |
Filip Pytloun | 26ebcc0 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 71 | password: 'password' |
| 72 | host: 'localhost' |
| 73 | rights: 'all privileges' |
| 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: |
| 90 | name: 'databasename' |
| 91 | encoding: 'UTF8' |
| 92 | locale: 'cs_CZ' |
Ales Komarek | 961b0b7 | 2017-04-16 11:39:41 +0200 | [diff] [blame] | 93 | users: |
| 94 | - name: 'username' |
Filip Pytloun | 26ebcc0 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 95 | password: 'password' |
| 96 | host: 'localhost' |
| 97 | createdb: true |
| 98 | rights: 'all privileges' |
| 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: |
| 115 | name: 'databasename' |
| 116 | encoding: 'UTF8' |
| 117 | locale: 'cs_CZ' |
Ales Komarek | 961b0b7 | 2017-04-16 11:39:41 +0200 | [diff] [blame] | 118 | users: |
| 119 | - name: 'username' |
Filip Pytloun | 26ebcc0 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 120 | password: 'password' |
| 121 | host: 'localhost' |
| 122 | createdb: true |
| 123 | rights: 'all privileges' |
| 124 | extension: |
| 125 | postgis_topology: |
Adam Tengler | b5792ca | 2017-02-13 14:31:23 +0100 | [diff] [blame] | 126 | enabled: true |
Filip Pytloun | 26ebcc0 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 127 | fuzzystrmatch: |
Adam Tengler | b5792ca | 2017-02-13 14:31:23 +0100 | [diff] [blame] | 128 | enabled: true |
Filip Pytloun | 26ebcc0 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 129 | postgis_tiger_geocoder: |
Adam Tengler | b5792ca | 2017-02-13 14:31:23 +0100 | [diff] [blame] | 130 | enabled: true |
Filip Pytloun | 26ebcc0 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 131 | postgis: |
Adam Tengler | b5792ca | 2017-02-13 14:31:23 +0100 | [diff] [blame] | 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 | |
Adam Tengler | b5792ca | 2017-02-13 14:31:23 +0100 | [diff] [blame] | 274 | |
| 275 | Sample usage |
| 276 | ============ |
Filip Pytloun | 26ebcc0 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 277 | |
| 278 | Init database cluster with given locale |
| 279 | |
Ales Komarek | 961b0b7 | 2017-04-16 11:39:41 +0200 | [diff] [blame] | 280 | .. code-block:: bash |
| 281 | |
Filip Pytloun | 26ebcc0 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 282 | sudo su - postgres -c "/usr/lib/postgresql/9.3/bin/initdb /var/lib/postgresql/9.3/main --locale=C" |
| 283 | |
| 284 | Convert PostgreSQL cluster from 9.1 to 9.3 |
| 285 | |
Ales Komarek | 961b0b7 | 2017-04-16 11:39:41 +0200 | [diff] [blame] | 286 | .. code-block:: bash |
| 287 | |
Filip Pytloun | 26ebcc0 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 288 | 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 | |
| 290 | Ubuntu on 14.04 on some machines won't create default cluster |
| 291 | |
Ales Komarek | 961b0b7 | 2017-04-16 11:39:41 +0200 | [diff] [blame] | 292 | .. code-block:: bash |
| 293 | |
Filip Pytloun | 26ebcc0 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 294 | sudo pg_createcluster 9.3 main --start |
| 295 | |
Ales Komarek | 961b0b7 | 2017-04-16 11:39:41 +0200 | [diff] [blame] | 296 | |
| 297 | More information |
| 298 | ================ |
Filip Pytloun | 26ebcc0 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 299 | |
| 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 Pytloun | 4afffd8 | 2017-02-02 13:02:03 +0100 | [diff] [blame] | 303 | * https://gist.github.com/ibussieres/11262268 - upgrade instructions for ubuntu |
Ales Komarek | 961b0b7 | 2017-04-16 11:39:41 +0200 | [diff] [blame] | 304 | |
| 305 | |
Filip Pytloun | 4afffd8 | 2017-02-02 13:02:03 +0100 | [diff] [blame] | 306 | Documentation and Bugs |
| 307 | ====================== |
| 308 | |
| 309 | To learn how to install and update salt-formulas, consult the documentation |
| 310 | available online at: |
| 311 | |
| 312 | http://salt-formulas.readthedocs.io/ |
| 313 | |
| 314 | In the unfortunate event that bugs are discovered, they should be reported to |
| 315 | the appropriate issue tracker. Use Github issue tracker for specific salt |
| 316 | formula: |
| 317 | |
| 318 | https://github.com/salt-formulas/salt-formula-postgresql/issues |
| 319 | |
| 320 | For feature requests, bug reports or blueprints affecting entire ecosystem, |
| 321 | use Launchpad salt-formulas project: |
| 322 | |
| 323 | https://launchpad.net/salt-formulas |
| 324 | |
| 325 | You can also join salt-formulas-users team and subscribe to mailing list: |
| 326 | |
| 327 | https://launchpad.net/~salt-formulas-users |
| 328 | |
| 329 | Developers wishing to work on the salt-formulas projects should always base |
| 330 | their work on master branch and submit pull request against specific formula. |
| 331 | |
| 332 | https://github.com/salt-formulas/salt-formula-postgresql |
| 333 | |
| 334 | Any questions or feedback is always welcome so feel free to join our IRC |
| 335 | channel: |
| 336 | |
| 337 | #salt-formulas @ irc.freenode.net |