5 # Copyright:: 2011, OpenStreetMap Foundation
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # https://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
20 include_recipe "db::base"
22 passwords = data_bag_item("db", "passwords")
24 postgresql_user "tomh" do
25 cluster node[:db][:cluster]
29 postgresql_user "matt" do
30 cluster node[:db][:cluster]
34 postgresql_user "openstreetmap" do
35 cluster node[:db][:cluster]
36 password passwords["openstreetmap"]
39 postgresql_user "rails" do
40 cluster node[:db][:cluster]
41 password passwords["rails"]
44 postgresql_user "cgimap" do
45 cluster node[:db][:cluster]
46 password passwords["cgimap"]
49 postgresql_user "planetdump" do
50 cluster node[:db][:cluster]
51 password passwords["planetdump"]
54 postgresql_user "planetdiff" do
55 cluster node[:db][:cluster]
56 password passwords["planetdiff"]
60 postgresql_user "backup" do
61 cluster node[:db][:cluster]
62 password passwords["backup"]
65 postgresql_user "replication" do
66 cluster node[:db][:cluster]
67 password passwords["replication"]
71 postgresql_database "openstreetmap" do
72 cluster node[:db][:cluster]
76 postgresql_extension "btree_gist" do
77 cluster node[:db][:cluster]
78 database "openstreetmap"
79 only_if { node[:postgresql][:clusters][node[:db][:cluster]] && node[:postgresql][:clusters][node[:db][:cluster]][:version] >= 9.0 }
82 CGIMAP_PERMISSIONS = {
83 "changeset_comments" => [:select],
84 "changeset_tags" => [:select],
85 "changesets" => [:select, :update],
86 "current_node_tags" => [:select, :insert, :delete],
87 "current_nodes" => [:select, :insert, :update],
88 "current_nodes_id_seq" => [:update],
89 "current_relation_members" => [:select, :insert, :delete],
90 "current_relation_tags" => [:select, :insert, :delete],
91 "current_relations" => [:select, :insert, :update],
92 "current_relations_id_seq" => [:update],
93 "current_way_nodes" => [:select, :insert, :delete],
94 "current_way_tags" => [:select, :insert, :delete],
95 "current_ways" => [:select, :insert, :update],
96 "current_ways_id_seq" => [:update],
97 "issues" => [:select],
98 "node_tags" => [:select, :insert],
99 "nodes" => [:select, :insert],
100 "oauth_access_grants" => [:select],
101 "oauth_access_tokens" => [:select],
102 "oauth_applications" => [:select],
103 "relation_members" => [:select, :insert],
104 "relation_tags" => [:select, :insert],
105 "relations" => [:select, :insert],
106 "reports" => [:select],
107 "user_blocks" => [:select],
108 "user_roles" => [:select],
109 "users" => [:select],
110 "way_nodes" => [:select, :insert],
111 "way_tags" => [:select, :insert],
112 "ways" => [:select, :insert]
115 PLANETDUMP_PERMISSIONS = {
116 "note_comments" => :select,
121 PLANETDIFF_PERMISSIONS = {
122 "changeset_comments" => :select,
123 "changeset_tags" => :select,
124 "changesets" => :select,
125 "node_tags" => :select,
127 "relation_members" => :select,
128 "relation_tags" => :select,
129 "relations" => :select,
131 "way_nodes" => :select,
132 "way_tags" => :select,
136 PROMETHEUS_PERMISSIONS = {
137 "delayed_jobs" => :select
142 active_storage_attachments
144 active_storage_variant_records
149 changesets_subscribers
152 current_relation_members
153 current_relation_tags
161 diary_entry_subscriptions
178 oauth_openid_requests
194 postgresql_table table do
195 cluster node[:db][:cluster]
196 database "openstreetmap"
197 owner "openstreetmap"
198 permissions "openstreetmap" => [:all],
199 "rails" => [:select, :insert, :update, :delete],
200 "cgimap" => CGIMAP_PERMISSIONS[table],
201 "planetdump" => PLANETDUMP_PERMISSIONS[table],
202 "planetdiff" => PLANETDIFF_PERMISSIONS[table],
203 "prometheus" => PROMETHEUS_PERMISSIONS[table],
204 "backup" => [:select]
210 active_storage_attachments_id_seq
211 active_storage_blobs_id_seq
212 active_storage_variant_records_id_seq
213 changeset_comments_id_seq
216 current_relations_id_seq
219 diary_comments_id_seq
224 issue_comments_id_seq
229 oauth_access_grants_id_seq
230 oauth_access_tokens_id_seq
231 oauth_applications_id_seq
232 oauth_openid_requests_id_seq
240 postgresql_sequence sequence do
241 cluster node[:db][:cluster]
242 database "openstreetmap"
243 owner "openstreetmap"
244 permissions "openstreetmap" => [:all],
246 "cgimap" => CGIMAP_PERMISSIONS[sequence],
247 "backup" => [:select]
251 cookbook_file "/usr/local/share/monthly-reindex.sql" do
257 systemd_service "monthly-reindex" do
258 description "Monthly database reindex"
259 exec_start "/usr/bin/psql -f /usr/local/share/monthly-reindex.sql openstreetmap"
262 restrict_address_families "AF_UNIX"
266 systemd_timer "monthly-reindex" do
267 description "Monthly database reindex"
268 on_calendar "Sun *-*-1..7 02:00"
271 service "monthly-reindex.timer" do
272 action [:enable, :start]
275 cookbook_file "/usr/local/share/yearly-reindex.sql" do
281 systemd_service "yearly-reindex" do
282 description "Yearly database reindex"
283 exec_start "/usr/bin/psql -f /usr/local/share/yearly-reindex.sql openstreetmap"
286 restrict_address_families "AF_UNIX"
290 systemd_timer "yearly-reindex" do
291 description "Yearly database reindex"
292 on_calendar "Thu *-1-8..14 02:00"
295 service "yearly-reindex.timer" do
296 action [:enable, :start]
299 template "/etc/prometheus/exporters/sql_rails.collector.yml" do
300 source "sql_rails.yml.erb"