Skip to content

Commit 476b602

Browse files
authored
Restore postgres infrastructure for local dev (#256)
* repair postgresql-primary state * upgrade to postgres 11 * fixup db/user creation via salt
1 parent a0efb3a commit 476b602

27 files changed

+222
-277
lines changed

Vagrantfile

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ SERVERS = [
1616
"mail",
1717
"moin",
1818
"planet",
19+
"postgresql",
1920
{:name => "postgresql-primary", :roles => ["postgresql", "postgresql-primary"]},
2021
{:name => "postgresql-replica", :roles => ["postgresql", "postgresql-replica"]},
2122
"pypy-web",

docs/services/postgresql.rst

+10-53
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
11
PostgreSQL
22
==========
33

4-
The Python Infrastructure offers PostgreSQL databases to services hosted in the
5-
Rackspace datacenter.
4+
The Python Infrastructure uses PostgreSQL databases to services hosted in the
5+
DigitalOcean datacenter.
66

7+
* Currently running hosted PostgreSQL 11 provided by DigitalOcean databases.
78

8-
* Currently running PostgreSQL 9.4
9-
10-
* Operates a 2 node cluster with a primary node configured with streaming
11-
replication to a replica node.
12-
13-
* Each node is running a 15 GB Rackspace Cloud Server.
14-
15-
* Each app node has pgbouncer running on it pooling connections.
9+
* App nodes have pgbouncer running on it pooling connections.
1610

1711
* The actual database user and password is only known to pgbouncer, each
1812
node will get a unique randomly generated password for the app to connect
1913
to pgbouncer.
2014

21-
* The primary node also backs up to Rackspace CloudFiles in the ORD region
22-
via WAL-E. A full backup is done once a week via a cronjob and WAL-E does
23-
WAL pushes to fill in between the full backups.
2415

16+
Local Tooling
17+
-------------
18+
19+
For roles which require postgresql, the ``postgresql-primary`` vagrant machine
20+
can be booted to provide similar infrastructure to the DigitalOcean hosted
21+
Postgres.
2522

2623

2724
Creating a New Database
@@ -80,43 +77,3 @@ Giving Applications Access
8077
},
8178
},
8279
}
83-
84-
85-
Application Integration
86-
-----------------------
87-
88-
The PostgreSQL has been configured to allow an application to integrate with it
89-
to get some advanced features.
90-
91-
92-
(A)synchronous Commit
93-
~~~~~~~~~~~~~~~~~~~~~
94-
95-
By default the PostgreSQL primary will ensure that each transaction is commited
96-
to persistent storage on the local disk before returning that a transaction
97-
has successfully been commited. However it will asynchronously replicate that
98-
transaction to the replicas. This means that if the primary server goes down
99-
in a way where the disk is not recoverable prior to replication occuring than
100-
that data will be lost.
101-
102-
Applications may optionally, on a per transaction basis, request that the
103-
primary server has either given the data to a replica server or that a replica
104-
server has also written that data to persistent storage.
105-
106-
This can be acchived by executing:
107-
108-
.. code-block:: plpgsql
109-
110-
-- Set the transaction so that a replica will have received the data, but
111-
-- not written the data out before the primary says the transaction is
112-
-- complete.
113-
SET LOCAL synchronous_commit TO remote_write;
114-
115-
-- Set the transaction so that a replica will have written the data to
116-
-- persistent storage before the primary says the transaction is complete.
117-
SET LOCAL synchronous_commit TO on;
118-
119-
Obviously each of these options will mean the write will fail if the primary
120-
cannot reach the replica server. These options can be used when ensuring data
121-
is saved is more important than uptime with the minimal risk the primary goes
122-
completely unrecoverable.

pillar/base/firewall/postgresql.sls

-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,3 @@
33
firewall:
44
postgresql:
55
port: 5432
6-
7-
fwmangle:
8-
postgresql-stunnel: -A OUTPUT -p tcp -m multiport --sports 5431 -j MARK --set-xmark 0x1/0xffffffff

pillar/base/postgresql/server.sls

+11-25
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,12 @@
11
postgresql:
2-
databases:
3-
codespeed-cpython:
4-
owner: "codespeed-cpython"
5-
cluster: "pg-nyc1-psf-io"
6-
codespeed-pypy:
7-
owner: "codespeed-pypy"
8-
cluster: "pg-nyc1-psf-io"
9-
roundup-cpython:
10-
owner: "roundup-cpython"
11-
cluster: pool-pg-nyc1-psf-io
12-
roundup-jython:
13-
owner: "roundup-jython"
14-
cluster: pg-nyc1-psf-io
15-
roundup-roundup:
16-
owner: "roundup-roundup"
17-
cluster: pg-nyc1-psf-io
18-
roundup-cpython_test:
19-
owner: "roundup-cpython_test"
20-
cluster: pg-nyc1-psf-io
21-
buildbot-master:
22-
owner: "buildbot-master"
23-
cluster: "pg-nyc1-psf-io"
24-
buildbot-master_test:
25-
owner: "buildbot-master_test"
26-
cluster: "pg-nyc1-psf-io"
2+
data_dir: /srv/postgresql/11/psf
3+
config_dir: /etc/postgresql/11/psf
4+
config_file: /etc/postgresql/11/psf/postgresql.conf
5+
hba_file: /etc/postgresql/11/psf/pg_hba.conf
6+
ident_file: /etc/postgresql/11/psf/pg_ident.conf
7+
pid_file: /var/run/postgresql/11-psf.pid
8+
recovery_file: /srv/postgresql/11/psf/recovery.conf
9+
10+
port: 5432
11+
max_connections: 100
12+
replicas: 1

pillar/base/tls.sls

+16-12
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ tls:
66
default: ECDH+AESGCM:ECDH+CHACHA20:ECDH+AES256:ECDH+AES128:!aNULL:!SHA1:!AESCCM
77

88
gen_certs:
9+
bootstrap.pypa.psf.io:
10+
roles:
11+
- web-pypa
12+
13+
buildbot-master.psf.io:
14+
roles:
15+
- buildbot
16+
17+
codespeed.psf.io:
18+
roles:
19+
- codespeed
20+
921
consul.psf.io:
1022
roles:
1123
- consul
@@ -26,17 +38,13 @@ tls:
2638
roles:
2739
- loadbalancer
2840

29-
codespeed.psf.io:
30-
roles:
31-
- codespeed
32-
33-
bootstrap.pypa.psf.io:
41+
moin.psf.io:
3442
roles:
35-
- web-pypa
43+
- moin
3644

37-
buildbot-master.psf.io:
45+
postgresql.psf.io:
3846
roles:
39-
- buildbot
47+
- postgresql
4048

4149
salt.psf.io:
4250
roles:
@@ -49,7 +57,3 @@ tls:
4957
pypy-web.psf.io:
5058
roles:
5159
- pypy-web
52-
53-
moin.psf.io:
54-
roles:
55-
- moin

pillar/dev/postgres/clusters.sls

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
postgresql-clusters:
2+
pg-vagrant-psf-io:
3+
host: postgresql-primary.vagrant.psf.io
4+
port: 5432
5+
sslmode: verify-ca
6+
ca_cert_pillar: 'tls:ca:PSF_CA'

pillar/dev/postgres/databases.sls

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
postgresql-databases:
2+
codespeed-cpython:
3+
owner: "codespeed-cpython"
4+
cluster: "pg-vagrant-psf-io"
5+
codespeed-pypy:
6+
owner: "codespeed-pypy"
7+
cluster: "pg-vagrant-psf-io"
8+
roundup-cpython:
9+
owner: "roundup-cpython"
10+
cluster: "pg-vagrant-psf-io"
11+
roundup-jython:
12+
owner: "roundup-jython"
13+
cluster: "pg-vagrant-psf-io"
14+
roundup-roundup:
15+
owner: "roundup-roundup"
16+
cluster: "pg-vagrant-psf-io"
17+
roundup-cpython_test:
18+
owner: "roundup-cpython_test"
19+
cluster: "pg-vagrant-psf-io"
20+
buildbot-master:
21+
owner: "buildbot-master"
22+
cluster: "pg-vagrant-psf-io"
23+
buildbot-master_test:
24+
owner: "buildbot-master_test"
25+
cluster: "pg-vagrant-psf-io"

pillar/dev/roles.sls

+12
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@ roles:
5050
pattern: "mail.vagrant.psf.io"
5151
purpose: ""
5252
contact: ""
53+
postgresql:
54+
pattern: "postgresql-*.vagrant.psf.io"
55+
purpose: ""
56+
contact: ""
57+
postgresql-primary:
58+
pattern: "postgresql-primary.vagrant.psf.io"
59+
purpose: ""
60+
contact: ""
61+
postgresql-replica:
62+
pattern: "postgresql-replica.vagrant.psf.io"
63+
purpose: ""
64+
contact: ""
5365
planet:
5466
pattern: "planet.vagrant.psf.io"
5567
purpose: ""
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
postgres-admin:
2+
pg-vagrant-psf-io:
3+
user: salt-master
4+
password: insecurepasswordlol
5+
database: defaultdb
+34-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,39 @@
11
postgresql-users:
2-
bugs-python: insecurepasswordlol
3-
monitoring: insecurepasswordlol
4-
pydotorg-prod: insecurepasswordlol
5-
pydotorg-staging: insecurepasswordlol
6-
pycon-prod: insecurepasswordlol
7-
pycon-staging: insecurepasswordlol
8-
speed-web: insecurepasswordlol
9-
testpypi: insecurepasswordlol
10-
discourse-user: insecurepasswordlol
2+
codespeed-cpython:
3+
cluster: pg-vagrant-psf-io
4+
dbname: codespeed-cpython
5+
password: insecurepasswordlol
6+
codespeed-pypy:
7+
cluster: pg-vagrant-psf-io
8+
dbname: codespeed-pypy
9+
password: insecurepasswordlol
10+
roundup-cpython:
11+
cluster: pg-vagrant-psf-io
12+
dbname: roundup-cpython
13+
password: insecurepasswordlol
14+
roundup-jython:
15+
cluster: pg-vagrant-psf-io
16+
dbname: roundup-jython
17+
password: insecurepasswordlol
18+
roundup-roundup:
19+
cluster: pg-vagrant-psf-io
20+
dbname: roundup-roundup
21+
password: insecurepasswordlol
22+
roundup-cpython_test:
23+
cluster: pg-vagrant-psf-io
24+
dbname: roundup-cpython_test
25+
password: insecurepasswordlol
26+
buildbot-master:
27+
cluster: pg-vagrant-psf-io
28+
dbname: buildbot-master
29+
password: insecurepasswordlol
30+
buildbot-master_test:
31+
cluster: pg-vagrant-psf-io
32+
dbname: buildbot-master_test
33+
password: insecurepasswordlol
1134

1235
postgresql-superusers:
13-
diamond: insecurepasswordlol
36+
salt-master:
37+
password: insecurepasswordlol
1438

1539
postgresql-replicator: insecurereplicatorpasswordlol

pillar/dev/secrets/postgresql-users/monitoring.sls

-2
This file was deleted.

pillar/dev/secrets/postgresql-users/speed-web.sls

-2
This file was deleted.

pillar/dev/secrets/postgresql-users/tracker.sls

-2
This file was deleted.

pillar/dev/top.sls

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ base:
77
- sudoers
88
- tls
99
- users
10+
- postgres.clusters
1011

1112
'backup-server':
1213
- match: nodegroup
@@ -69,9 +70,11 @@ base:
6970
- match: nodegroup
7071
- firewall.postgresql
7172
- postgresql.server
73+
- postgres.databases
7274

7375
'postgresql-primary':
7476
- match: nodegroup
77+
- secrets.postgresql-admin
7578
- secrets.postgresql-users.all
7679

7780
'postgresql-replica':

pillar/prod/postgres/databases.sls

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
postgresql-databases:
2+
codespeed-cpython:
3+
owner: "codespeed-cpython"
4+
cluster: "pg-nyc1-psf-io"
5+
codespeed-pypy:
6+
owner: "codespeed-pypy"
7+
cluster: "pg-nyc1-psf-io"
8+
roundup-cpython:
9+
owner: "roundup-cpython"
10+
cluster: pg-nyc1-psf-io
11+
roundup-jython:
12+
owner: "roundup-jython"
13+
cluster: pg-nyc1-psf-io
14+
roundup-roundup:
15+
owner: "roundup-roundup"
16+
cluster: pg-nyc1-psf-io
17+
roundup-cpython_test:
18+
owner: "roundup-cpython_test"
19+
cluster: pg-nyc1-psf-io
20+
buildbot-master:
21+
owner: "buildbot-master"
22+
cluster: "pg-nyc1-psf-io"
23+
buildbot-master_test:
24+
owner: "buildbot-master_test"
25+
cluster: "pg-nyc1-psf-io"

pillar/prod/top.sls

+1-2
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@ base:
107107
'salt-master':
108108
- match: nodegroup
109109
- firewall.salt
110-
- secrets.dyn
110+
- postgres.databases
111111
- secrets.aws
112112
- secrets.postgresql-admin
113-
- postgresql.server
114113
- secrets.postgresql-users.all

salt/base/salt.sls

-28
Original file line numberDiff line numberDiff line change
@@ -114,31 +114,3 @@ salt-minion:
114114
- restart: True
115115
- watch:
116116
- file: /etc/salt/minion.d/mine.conf
117-
118-
{% if 'postgresql-admin' in pillar %}
119-
{% set postgresql = salt["pillar.get"]("postgresql", {}) %}
120-
{% for user, settings in salt["pillar.get"]("postgresql-users", {}).items() %}
121-
{{ user }}-user:
122-
postgres_user.present:
123-
- name: {{ user }}
124-
- password: {{ settings['password'] }}
125-
- refresh_password: True
126-
- db_host: {{ pillar['postgresql-clusters'][settings['cluster']]['host'] }}
127-
- db_port: {{ pillar['postgresql-clusters'][settings['cluster']]['port'] }}
128-
- db_user: {{ pillar['postgresql-admin'][settings['cluster']]['user'] }}
129-
- db_password: {{ pillar['postgresql-admin'][settings['cluster']]['password'] }}
130-
{% endfor %}
131-
132-
{% for database, settings in postgresql.get("databases", {}).items() %}
133-
{{ database }}-database:
134-
postgres_database.present:
135-
- name: {{ database }}
136-
- owner: {{ settings['owner'] }}
137-
- db_host: {{ pillar['postgresql-clusters'][settings['cluster']]['host'] }}
138-
- db_port: {{ pillar['postgresql-clusters'][settings['cluster']]['port'] }}
139-
- db_user: {{ pillar['postgresql-admin'][settings['cluster']]['user'] }}
140-
- db_password: {{ pillar['postgresql-admin'][settings['cluster']]['password'] }}
141-
- require:
142-
- postgres_user: {{ settings['owner'] }}-user
143-
{% endfor %}
144-
{% endif %}

0 commit comments

Comments
 (0)