3 require_once(CONST_LibDir.'/init-cmd.php');
5 loadSettings(getcwd());
13 $print_success = function ($message = 'OK') use ($term_colors) {
14 echo $term_colors['green'].$message.$term_colors['normal']."\n";
17 $print_fail = function ($message = 'Failed') use ($term_colors) {
18 echo $term_colors['red'].$message.$term_colors['normal']."\n";
22 $oDB = new Nominatim\DB;
25 function isReverseOnlyInstallation()
28 return !$oDB->tableExists('search_name');
31 // Check (guess) if the setup.php included --drop
32 function isNoUpdateInstallation()
35 return $oDB->tableExists('placex') && !$oDB->tableExists('planet_osm_rels') ;
39 echo 'Checking database got created ... ';
40 if ($oDB->checkConnection()) {
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
55 echo 'Checking nominatim.so module installed ... ';
56 $sStandardWord = $oDB->getOne("SELECT make_standard_name('a')");
57 if ($sStandardWord === 'a') {
62 The Postgresql extension nominatim.so was not found in the database.
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?
73 if (!isNoUpdateInstallation()) {
74 echo 'Checking place table ... ';
75 if ($oDB->tableExists('place')) {
80 * The import didn't finish.
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
87 * osm2pgsql killed by other scripts, for consuming to much memory
95 echo 'Checking indexing status ... ';
96 $iUnindexed = $oDB->getOne('SELECT count(*) FROM placex WHERE indexed_status > 0');
97 if ($iUnindexed == 0) {
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.
110 echo "Search index creation\n";
111 $aExpectedIndices = array(
112 // sql/indices.src.sql
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',
123 'idx_postcode_postcode'
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'
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',
141 foreach ($aExpectedIndices as $sExpectedIndex) {
142 echo "Checking index $sExpectedIndex ... ";
143 if ($oDB->indexExists($sExpectedIndex)) {
149 * Run './utils/setup.php --create-search-indices --ignore-errors' to
150 create missing indices.
157 echo 'Checking search indices are valid ... ';
160 FROM pg_class, pg_index
161 WHERE pg_index.indisvalid = false
162 AND pg_index.indexrelid = pg_class.oid;
164 $aInvalid = $oDB->getCol($sSQL);
165 if (empty($aInvalid)) {
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.
177 echo join(', ', $aInvalid) . "\n";
183 if (getSettingBool('USE_US_TIGER_DATA')) {
184 echo 'Checking TIGER table exists ... ';
185 if ($oDB->tableExists('location_property_tiger')) {
190 Table 'location_property_tiger' does not exist. Run the TIGER data