776cab65534782ed50de637ad37205ee595fbed7
[chef.git] / cookbooks / timescaledb / recipes / default.rb
1 #
2 # Cookbook:: timescaledb
3 # Recipe:: default
4 #
5 # Copyright:: 2021, OpenStreetMap Foundation
6 #
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
10 #
11 #     https://www.apache.org/licenses/LICENSE-2.0
12 #
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.
18 #
19
20 include_recipe "apt"
21
22 database_version = node[:timescaledb][:database_version]
23
24 package %W[
25   timescaledb-tools
26   timescaledb-2-postgresql-#{database_version}
27 ]
28
29 memory_gb = (node[:memory][:total].to_f / 1024 / 1024).ceil
30
31 node.default_unless[:postgresql][:versions] = []
32 node.default[:postgresql][:versions] |= [database_version]
33 node.default[:postgresql][:monitor_tables] = false
34 node.default[:postgresql][:settings][database_version][:max_connections] = 500
35 node.default[:postgresql][:settings][database_version][:shared_buffers] = "#{memory_gb / 4}GB"
36 node.default[:postgresql][:settings][database_version][:work_mem] = "#{memory_gb * 128 / 50 / node[:cpu][:total]}MB"
37 node.default[:postgresql][:settings][database_version][:maintenance_work_mem] = "2GB"
38 node.default[:postgresql][:settings][database_version][:effective_io_concurrency] = "200"
39 node.default[:postgresql][:settings][database_version][:max_worker_processes] = node[:cpu][:total] + node[:timescaledb][:max_background_workers] + 3
40 node.default[:postgresql][:settings][database_version][:max_parallel_workers_per_gather] = node[:cpu][:total] / 2
41 node.default[:postgresql][:settings][database_version][:max_parallel_workers] = node[:cpu][:total]
42 node.default[:postgresql][:settings][database_version][:wal_buffers] = "16MB"
43 node.default[:postgresql][:settings][database_version][:max_wal_size] = "1GB"
44 node.default[:postgresql][:settings][database_version][:min_wal_size] = "512MB"
45 node.default[:postgresql][:settings][database_version][:checkpoint_completion_target] = "0.9"
46 node.default[:postgresql][:settings][database_version][:random_page_cost] = "1.1"
47 node.default[:postgresql][:settings][database_version][:effective_cache_size] = "#{memory_gb * 3 / 4}GB"
48 node.default[:postgresql][:settings][database_version][:default_statistics_target] = "500"
49 node.default[:postgresql][:settings][database_version][:autovacuum_max_workers] = "10"
50 node.default[:postgresql][:settings][database_version][:autovacuum_naptime] = "10"
51 node.default_unless[:postgresql][:settings][database_version][:shared_preload_libraries] = []
52 node.default[:postgresql][:settings][database_version][:shared_preload_libraries] |= ["timescaledb"]
53 node.default[:postgresql][:settings][database_version][:max_locks_per_transaction] = "512"
54 node.default_unless[:postgresql][:settings][database_version][:customized_options] = {}
55 node.default[:postgresql][:settings][database_version][:customized_options]["timescaledb.max_background_workers"] = node[:timescaledb][:max_background_workers]
56
57 include_recipe "postgresql"