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