]> git.openstreetmap.org Git - chef.git/commitdiff
Add cookbook to install and configure TimescaleDB
authorTom Hughes <tom@compton.nu>
Thu, 14 Jan 2021 20:25:33 +0000 (20:25 +0000)
committerTom Hughes <tom@compton.nu>
Thu, 14 Jan 2021 20:27:03 +0000 (20:27 +0000)
.kitchen.yml
cookbooks/apt/recipes/default.rb
cookbooks/timescaledb/README.md [new file with mode: 0644]
cookbooks/timescaledb/attributes/default.rb [new file with mode: 0644]
cookbooks/timescaledb/metadata.rb [new file with mode: 0644]
cookbooks/timescaledb/recipes/default.rb [new file with mode: 0644]

index 854666cc6f144da828f0d82d36baea55a82d5ead..58a63e3b9871a41e73e3890723c812dd084a1e1a 100644 (file)
@@ -345,6 +345,9 @@ suites:
   - name: tilelog
     run_list:
       - recipe[tilelog::default]
+  - name: timescaledb
+    run_list:
+      - recipe[timescaledb::default]
   - name: tools
     run_list:
       - recipe[tools::default]
index 06b81b89819329a52755f5667a64b82c03949417..6ab6afb7ecaf793a2a64777e30ef812f71608e31 100644 (file)
@@ -182,6 +182,11 @@ apt_repository "grafana" do
   key "https://packages.grafana.com/gpg.key"
 end
 
+apt_repository "timescaledb" do
+  action repository_actions["timescaledb"]
+  uri "ppa:timescale/timescaledb-ppa"
+end
+
 package "unattended-upgrades"
 
 if Dir.exist?("/usr/share/unattended-upgrades")
diff --git a/cookbooks/timescaledb/README.md b/cookbooks/timescaledb/README.md
new file mode 100644 (file)
index 0000000..f37c32e
--- /dev/null
@@ -0,0 +1,3 @@
+# TimescaleDB Cookbook
+
+This cookbook configures TimescaleDB.
diff --git a/cookbooks/timescaledb/attributes/default.rb b/cookbooks/timescaledb/attributes/default.rb
new file mode 100644 (file)
index 0000000..7ce8642
--- /dev/null
@@ -0,0 +1,32 @@
+default[:timescaledb][:cluster] = "12/main"
+default[:timescaledb][:max_background_workers] = 8
+
+database_version = node[:timescaledb][:cluster].split("/").first
+
+default[:apt][:sources] |= ["timescaledb"]
+
+memory_gb = (node[:memory][:total].to_f / 1024 / 1024).ceil
+
+default[:postgresql][:versions] |= [database_version]
+default[:postgresql][:settings][database_version][:max_connections] = 500
+default[:postgresql][:settings][database_version][:shared_buffers] = "#{memory_gb / 4}GB"
+default[:postgresql][:settings][database_version][:work_mem] = "#{memory_gb * 128 / 50 / node[:cpu][:total]}MB"
+default[:postgresql][:settings][database_version][:maintenance_work_mem] = "2GB"
+default[:postgresql][:settings][database_version][:effective_io_concurrency] = "200"
+default[:postgresql][:settings][database_version][:max_worker_processes] = node[:cpu][:total] + node[:timescaledb][:max_background_workers] + 3
+default[:postgresql][:settings][database_version][:max_parallel_workers_per_gather] = node[:cpu][:total] / 2
+default[:postgresql][:settings][database_version][:max_parallel_workers] = node[:cpu][:total]
+default[:postgresql][:settings][database_version][:wal_buffers] = "16MB"
+default[:postgresql][:settings][database_version][:max_wal_size] = "1GB"
+default[:postgresql][:settings][database_version][:min_wal_size] = "512MB"
+default[:postgresql][:settings][database_version][:checkpoint_completion_target] = "0.9"
+default[:postgresql][:settings][database_version][:random_page_cost] = "1.1"
+default[:postgresql][:settings][database_version][:effective_cache_size] = "#{memory_gb * 3 / 4}GB"
+default[:postgresql][:settings][database_version][:default_statistics_target] = "500"
+default[:postgresql][:settings][database_version][:autovacuum_max_workers] = "10"
+default[:postgresql][:settings][database_version][:autovacuum_naptime] = "10"
+default_unless[:postgresql][:settings][database_version][:shared_preload_libraries] = []
+default[:postgresql][:settings][database_version][:shared_preload_libraries] |= ["timescaledb"]
+default[:postgresql][:settings][database_version][:max_locks_per_transaction] = "512"
+default_unless[:postgresql][:settings][database_version][:customized_options] = {}
+default[:postgresql][:settings][database_version][:customized_options]["timescaledb.max_background_workers"] = node[:timescaledb][:max_background_workers]
diff --git a/cookbooks/timescaledb/metadata.rb b/cookbooks/timescaledb/metadata.rb
new file mode 100644 (file)
index 0000000..9b8821a
--- /dev/null
@@ -0,0 +1,11 @@
+name              "timescaledb"
+maintainer        "OpenStreetMap Administrators"
+maintainer_email  "admins@openstreetmap.org"
+license           "Apache-2.0"
+description       "Installs and configures timescaledb"
+
+version           "1.0.0"
+supports          "ubuntu"
+depends           "apache"
+depends           "apt"
+depends           "postgresql"
diff --git a/cookbooks/timescaledb/recipes/default.rb b/cookbooks/timescaledb/recipes/default.rb
new file mode 100644 (file)
index 0000000..7b2defd
--- /dev/null
@@ -0,0 +1,27 @@
+#
+# Cookbook:: timescaledb
+# Recipe:: default
+#
+# Copyright:: 2021, OpenStreetMap Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+include_recipe "apt"
+
+package %w[
+  timescaledb-tools
+  timescaledb-2-postgresql-12
+]
+
+include_recipe "postgresql"