]> git.openstreetmap.org Git - chef.git/blob - cookbooks/nominatim/templates/default/clean-db-nominatim.erb
92b731a986a6a2f2dafb9a56b8efd334521a7690
[chef.git] / cookbooks / nominatim / templates / default / clean-db-nominatim.erb
1 #!/bin/bash
2 #
3 # DO NOT EDIT - This file is being maintained by Chef
4
5
6 # Vaccum all tables with indices on integer arrays.
7 # Agressive vacuuming seems to help against index bloat.
8 psql -q -d nominatim -c 'VACUUM ANALYSE search_name'
9 psql -q -d nominatim -c 'VACUUM ANALYSE search_name_country'
10
11 for i in `seq 0 246`; do
12   psql -q -d nominatim -c "VACUUM ANALYSE search_name_${i}"
13 done
14
15 # Cleanup archive directory
16 oldest=`date +%s`
17
18 for fl in <% @streaming_clients %>; do
19   lastupdate=`wget -O - -q http://${fl}.openstreetmap.org/last_update.php`
20   if [[ "$?" != "0" ]]; then
21     oldest=0
22     break
23   else
24     epoch=`date +%s -d "$lastupdate"`
25     if [[ "$epoch" -lt "$oldest" ]]; then
26         oldest=$epoch
27     fi
28   fi
29 done
30
31
32 if [[ "$oldest" != "0" ]]; then
33     now=`date +%s`
34     timeago=$(( ( $now - $oldest ) / 60 + 180 ))
35     if [[ "$timeago" -le "180" ]]; then
36         echo "Oldest is in the future, something is wrong."
37         exit(1)
38     fi
39
40     echo "find -L <%= @archive_dir %> -mmin +$timeago -print0 | xargs -0r rm"
41 fi
42
43 diskfree=`df --output=pcent <%= @archive_dir %> | tail -n 1 | sed s:[^0-9.]::g
44
45 if [[ "$diskfree" -lt 10 ]]; then
46     echo "WAL archives running out of space. Stopping updates."
47     touch <%= @update_stop_file %>
48 fi