]> git.openstreetmap.org Git - nominatim.git/blobdiff - utils/check_import_finished.php
check_import_finished.php - reverse_only mode has less indices
[nominatim.git] / utils / check_import_finished.php
index 7828f5cff03de17103de1a867fb0c833df5ca8ca..b81cace1702d3af50392d7682d56c3f11fbbe9ba 100755 (executable)
@@ -20,6 +20,13 @@ $print_fail = function ($message = 'Failed') use ($term_colors) {
 $oDB = new Nominatim\DB;
 
 
+function isReverseOnlyInstallation()
+{
+    global $oDB;
+    return !$oDB->tableExists('search_name');
+}
+
+
 echo 'Checking database got created ... ';
 if ($oDB->databaseExists()) {
     $print_success();
@@ -107,13 +114,16 @@ $aExpectedIndices = array(
     'idx_osmline_parent_osm_id',
     'idx_place_osm_unique',
     'idx_postcode_id',
-    'idx_postcode_postcode',
-
-    // sql/indices_search.src.sql
-    'idx_search_name_nameaddress_vector',
-    'idx_search_name_name_vector',
-    'idx_search_name_centroid'
+    'idx_postcode_postcode'
 );
+if (!isReverseOnlyInstallation()) {
+    $aExpectedIndices = array_merge($aExpectedIndices, array(
+        // sql/indices_search.src.sql
+        'idx_search_name_nameaddress_vector',
+        'idx_search_name_name_vector',
+        'idx_search_name_centroid'
+    ));
+}
 
 foreach ($aExpectedIndices as $sExpectedIndex) {
     echo "Checking index $sExpectedIndex ... ";
@@ -130,6 +140,32 @@ END;
     }
 }
 
+echo 'Checking search indices are valid ... ';
+$sSQL = <<< END
+    SELECT relname
+    FROM pg_class, pg_index
+    WHERE pg_index.indisvalid = false
+      AND pg_index.indexrelid = pg_class.oid;
+END;
+$aInvalid = $oDB->getCol($sSQL);
+if (empty($aInvalid)) {
+    $print_success();
+} else {
+    $print_fail();
+    echo <<< END
+    At least one index is invalid. That can happen, e.g. when index creation was
+    disrupted and later restarted. You should delete the affected indices and
+    run the index stage of setup again.
+    See the question 'Can a stopped/killed import process be resumed?' in the
+    troubleshooting guide.
+    Affected indices: 
+END;
+    echo join(', ', $aInvalid) . "\n";
+    exit(1);
+}
+
+
+
 if (CONST_Use_US_Tiger_Data) {
     echo 'Checking TIGER table exists ... ';
     if ($oDB->tableExists('location_property_tiger')) {