]> git.openstreetmap.org Git - nominatim.git/blob - utils/check_import_finished.php
Merge pull request #1918 from lonvia/remove-more-osmosis-init
[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_lookuppoint',
110     'idx_placex_geometry_reverse_lookuppolygon',
111     'idx_placex_geometry_reverse_placenode',
112     'idx_location_area_country_place_id',
113     'idx_osmline_parent_place_id',
114     'idx_osmline_parent_osm_id',
115     'idx_place_osm_unique',
116     'idx_postcode_id',
117     'idx_postcode_postcode'
118 );
119 if (!isReverseOnlyInstallation()) {
120     $aExpectedIndices = array_merge($aExpectedIndices, array(
121         // sql/indices_search.src.sql
122         'idx_search_name_nameaddress_vector',
123         'idx_search_name_name_vector',
124         'idx_search_name_centroid'
125     ));
126 }
127
128 foreach ($aExpectedIndices as $sExpectedIndex) {
129     echo "Checking index $sExpectedIndex ... ";
130     if ($oDB->indexExists($sExpectedIndex)) {
131         $print_success();
132     } else {
133         $print_fail();
134         echo <<< END
135         Hints:
136         * Run './utils/setup.php --create-search-indices --ignore-errors' to
137           create missing indices.
138
139 END;
140         exit(1);
141     }
142 }
143
144 echo 'Checking search indices are valid ... ';
145 $sSQL = <<< END
146     SELECT relname
147     FROM pg_class, pg_index
148     WHERE pg_index.indisvalid = false
149       AND pg_index.indexrelid = pg_class.oid;
150 END;
151 $aInvalid = $oDB->getCol($sSQL);
152 if (empty($aInvalid)) {
153     $print_success();
154 } else {
155     $print_fail();
156     echo <<< END
157     At least one index is invalid. That can happen, e.g. when index creation was
158     disrupted and later restarted. You should delete the affected indices and
159     run the index stage of setup again.
160     See the question 'Can a stopped/killed import process be resumed?' in the
161     troubleshooting guide.
162     Affected indices: 
163 END;
164     echo join(', ', $aInvalid) . "\n";
165     exit(1);
166 }
167
168
169
170 if (CONST_Use_US_Tiger_Data) {
171     echo 'Checking TIGER table exists ... ';
172     if ($oDB->tableExists('location_property_tiger')) {
173         $print_success();
174     } else {
175         $print_fail();
176         echo <<< END
177         Table 'location_property_tiger' does not exist. Run the TIGER data
178         import again.
179
180 END;
181         exit(1);
182     }
183 }
184
185
186
187
188 exit(0);