mode 0755
end
+directory "#{home_directory}/status" do
+ owner "nominatim"
+ group "postgres"
+ mode 0775
+end
+
template "/etc/logrotate.d/nominatim" do
source "logrotate.nominatim.erb"
owner "root"
end
end
-additional_scripts = %w(backup-nominatim clean-db-nominatim)
+additional_scripts = %w(backup-nominatim vacuum-db-nominatim)
additional_scripts.each do |fname|
template "/usr/local/bin/#{fname}" do
recursive true
end
-directory "/data/postgresql-archive" do
- owner "postgres"
- group "postgres"
- mode 0700
- only_if { node[:postgresql][:settings][:defaults][:archive_mode] == "on" }
-end
-
apache_site "nominatim.openstreetmap.org" do
template "apache.erb"
directory source_directory
database_cluster = node[:nominatim][:database][:cluster]
home_directory = data_bag_item("accounts", "nominatim")["home"]
+wal_archives = node[:rsyncd][:modules][:archive][:path]
+slaves = search(:node, 'role:nominatim-slave').map{ |result| result[:fqdn] }.join(' ')
+
git "#{home_directory}/nominatim" do
action :checkout
repository node[:nominatim][:repository]
password passwords["replication"]
replication true
end
+
+directory wal_archives do
+ owner "postgres"
+ group "postgres"
+ mode 0700
+ only_if { node[:postgresql][:settings][:defaults][:archive_mode] == "on" }
+end
+
+template "/usr/local/bin/clean-db-nominatim" do
+ source "clean-db-nominatim.erb"
+ owner "root"
+ group "root"
+ mode 0755
+ variables :archive_dir => wal_archives,
+ :update_stop_file => "{home_directory}/status/updates_disabled",
+ :streaming_clients => slaves
+ only_if { node[:postgresql][:settings][:defaults][:archive_mode] == "on" }
+end
+
+
psql -q -d nominatim -c "VACUUM ANALYSE search_name_${i}"
done
-<% if node[:postgresql][:settings][:defaults][:archive_mode] == "on" -%>
-
# Cleanup archive directory
-#find -L /data/postgresql-archive -mmin +1440 -print0 | xargs -0r rm
+oldest=`date +%s`
+
+for fl in <% @streaming_clients %>; do
+ lastupdate=`wget -O - -q http://$fl/last_update.php`
+ if [[ "$?" != "0" ]]; then
+ oldest=0
+ break
+ else
+ epoch=`date +%s -d "$lastupdate"`
+ if [[ "$epoch" -lt "$oldest" ]]; then
+ oldest=$epoch
+ fi
+ fi
+done
+
+
+if [[ "$oldest" != "0" ]]; then
+ now=`date +%s`
+ timeago=$(( ( $now - $oldest ) / 60 + 180 ))
+ if [[ "$timeago" -le "180" ]]; then
+ echo "Oldest is in the future, something is wrong."
+ exit(1)
+ fi
+
+ echo "find -L <%= @archive_dir %> -mmin +$timeago -print0 | xargs -0r rm"
+fi
+
+diskfree=`df --output=pcent <%= @archive_dir %> | tail -n 1 | sed s:[^0-9.]::g
-<% end -%>
+if [[ "$diskfree" -lt 10 ]]; then
+ echo "WAL archives running out of space. Stopping updates."
+ touch <%= @update_stop_file %>
+fi
<% if node[:nominatim][:enable_backup] -%>
00 3 1 * * nominatim /usr/local/bin/backup-nominatim
<% end -%>
-30 1 * * * postgres /usr/local/bin/clean-db-nominatim
+30 1 * * * postgres /usr/local/bin/vacuum-db-nominatim
DIR="$( cd "$( dirname "$0" )" && pwd )"
cd $DIR/..
-while true
+while [ ! -f "<%= @update_stop_file %>" ]
do
# Send output to the log (logrotatable)
exec >> /var/log/nominatim/update.log 2>&1
--- /dev/null
+#!/bin/bash
+#
+# DO NOT EDIT - This file is being maintained by Chef
+
+
+# Vaccum all tables with indices on integer arrays.
+# Agressive vacuuming seems to help against index bloat.
+psql -q -d nominatim -c 'VACUUM ANALYSE search_name'
+psql -q -d nominatim -c 'VACUUM ANALYSE search_name_country'
+
+for i in `seq 0 246`; do
+ psql -q -d nominatim -c "VACUUM ANALYSE search_name_${i}"
+done
+