]> git.openstreetmap.org Git - nominatim.git/blob - utils/check_import_finished.php
5ec99b81eb2a8164251a12b1888cdc4b0e50ceb5
[nominatim.git] / utils / check_import_finished.php
1 <?php
2
3 require_once(CONST_BasePath.'/lib/init-cmd.php');
4
5 $term_colors = array(
6                 'green' => "\033[92m",
7                 'red' => "\x1B[31m",
8                 'normal' => "\033[0m"
9 );
10
11 $print_success = function ($message = 'OK') use ($term_colors) {
12     echo $term_colors['green'].$message.$term_colors['normal']."\n";
13 };
14
15 $print_fail = function ($message = 'Failed') use ($term_colors) {
16     echo $term_colors['red'].$message.$term_colors['normal']."\n";
17 };
18
19
20 $oDB = new Nominatim\DB;
21
22
23 function isReverseOnlyInstallation()
24 {
25     global $oDB;
26     return !$oDB->tableExists('search_name');
27 }
28
29
30 echo 'Checking database got created ... ';
31 if ($oDB->checkConnection()) {
32     $print_success();
33 } else {
34     $print_fail();
35     echo <<< END
36     Hints:
37     * Is the database server started?
38     * Check the CONST_Database_DSN variable in build/settings/local.php
39     * Try connecting to the database with the same settings
40
41 END;
42     exit(1);
43 }
44
45
46 echo 'Checking nominatim.so module installed ... ';
47 $sStandardWord = $oDB->getOne("SELECT make_standard_name('a')");
48 if ($sStandardWord === 'a') {
49     $print_success();
50 } else {
51     $print_fail();
52     echo <<< END
53     The Postgresql extension nominatim.so was not found in the database.
54     Hints:
55     * Check the output of the CMmake/make installation step
56     * Does nominatim.so exist?
57     * Does nominatim.so exist on the database server?
58     * Can nominatim.so be accessed by the database user?
59
60 END;
61     exit(1);
62 }
63
64 echo 'Checking place table ... ';
65 if ($oDB->tableExists('place')) {
66     $print_success();
67 } else {
68     $print_fail();
69     echo <<< END
70     * The import didn't finish.
71     Hints:
72     * Check the output of the utils/setup.php you ran.
73     Usually the osm2pgsql step failed. Check for errors related to
74     * the file you imported not containing any places
75     * harddrive full
76     * out of memory (RAM)
77     * osm2pgsql killed by other scripts, for consuming to much memory
78
79 END;
80     exit(1);
81 }
82
83
84
85 echo 'Checking indexing status ... ';
86 $iUnindexed = $oDB->getOne('SELECT count(*) FROM placex WHERE indexed_status > 0');
87 if ($iUnindexed == 0) {
88     $print_success();
89 } else {
90     $print_fail();
91     echo <<< END
92     The indexing didn't finish. There is still $iUnindexed places. See the
93     question 'Can a stopped/killed import process be resumed?' in the
94     troubleshooting guide.
95
96 END;
97     exit(1);
98 }
99
100 echo "Search index creation\n";
101 $aExpectedIndices = array(
102     // sql/indices.src.sql
103     'idx_word_word_id',
104     'idx_place_addressline_address_place_id',
105     'idx_placex_rank_search',
106     'idx_placex_rank_address',
107     'idx_placex_pendingsector',
108     'idx_placex_parent_place_id',
109     'idx_placex_geometry_reverse_lookuppolygon',
110     'idx_placex_geometry_reverse_placenode',
111     'idx_location_area_country_place_id',
112     'idx_osmline_parent_place_id',
113     'idx_osmline_parent_osm_id',
114     'idx_place_osm_unique',
115     'idx_postcode_id',
116     'idx_postcode_postcode'
117 );
118 if (!isReverseOnlyInstallation()) {
119     $aExpectedIndices = array_merge($aExpectedIndices, array(
120         // sql/indices_search.src.sql
121         'idx_search_name_nameaddress_vector',
122         'idx_search_name_name_vector',
123         'idx_search_name_centroid'
124     ));
125 }
126
127 foreach ($aExpectedIndices as $sExpectedIndex) {
128     echo "Checking index $sExpectedIndex ... ";
129     if ($oDB->indexExists($sExpectedIndex)) {
130         $print_success();
131     } else {
132         $print_fail();
133         echo <<< END
134         Hints:
135         * Run './utils/setup.php --create-search-indices --ignore-errors' to
136           create missing indices.
137
138 END;
139         exit(1);
140     }
141 }
142
143 echo 'Checking search indices are valid ... ';
144 $sSQL = <<< END
145     SELECT relname
146     FROM pg_class, pg_index
147     WHERE pg_index.indisvalid = false
148       AND pg_index.indexrelid = pg_class.oid;
149 END;
150 $aInvalid = $oDB->getCol($sSQL);
151 if (empty($aInvalid)) {
152     $print_success();
153 } else {
154     $print_fail();
155     echo <<< END
156     At least one index is invalid. That can happen, e.g. when index creation was
157     disrupted and later restarted. You should delete the affected indices and
158     run the index stage of setup again.
159     See the question 'Can a stopped/killed import process be resumed?' in the
160     troubleshooting guide.
161     Affected indices: 
162 END;
163     echo join(', ', $aInvalid) . "\n";
164     exit(1);
165 }
166
167
168
169 if (CONST_Use_US_Tiger_Data) {
170     echo 'Checking TIGER table exists ... ';
171     if ($oDB->tableExists('location_property_tiger')) {
172         $print_success();
173     } else {
174         $print_fail();
175         echo <<< END
176         Table 'location_property_tiger' does not exist. Run the TIGER data
177         import again.
178
179 END;
180         exit(1);
181     }
182 }
183
184
185
186
187 exit(0);