X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/74f5929c2a66e6678b4e3f8da865d7539895296f..ca11fc90e6e646335045e087f03d824236c798f2:/utils/setup.php?ds=sidebyside diff --git a/utils/setup.php b/utils/setup.php index 8cbb2978..f8da1970 100755 --- a/utils/setup.php +++ b/utils/setup.php @@ -24,13 +24,14 @@ array('enable-debug-statements', '', 0, 1, 0, 0, 'bool', 'Include debug warning statements in pgsql commands'), array('create-minimal-tables', '', 0, 1, 0, 0, 'bool', 'Create minimal main tables'), array('create-tables', '', 0, 1, 0, 0, 'bool', 'Create main tables'), - array('create-partitions', '', 0, 1, 0, 0, 'bool', 'Create required partition tables and triggers'), + array('create-partition-tables', '', 0, 1, 0, 0, 'bool', 'Create required partition tables'), + array('create-partition-functions', '', 0, 1, 0, 0, 'bool', 'Create required partition triggers'), array('import-wikipedia-articles', '', 0, 1, 0, 0, 'bool', 'Import wikipedia article dump'), array('load-data', '', 0, 1, 0, 0, 'bool', 'Copy data to live tables from import table'), array('disable-token-precalc', '', 0, 1, 0, 0, 'bool', 'Disable name precalculation (EXPERT)'), array('import-tiger-data', '', 0, 1, 0, 0, 'bool', 'Import tiger data (not included in \'all\')'), array('calculate-postcodes', '', 0, 1, 0, 0, 'bool', 'Calculate postcode centroids'), - array('create-roads', '', 0, 1, 0, 0, 'bool', 'Calculate postcode centroids'), + array('create-roads', '', 0, 1, 0, 0, 'bool', ''), array('osmosis-init', '', 0, 1, 0, 0, 'bool', 'Generate default osmosis configuration'), array('index', '', 0, 1, 0, 0, 'bool', 'Index the data'), array('index-noanalyse', '', 0, 1, 0, 0, 'bool', 'Do not perform analyse operations during index (EXPERT)'), @@ -95,7 +96,7 @@ { fail('database already exists ('.CONST_Database_DSN.')'); } - passthru('createdb -E UTF-8 '.$aDSNInfo['database']); + passthruCheckReturn('createdb -E UTF-8 -p '.$aDSNInfo['port'].' '.$aDSNInfo['database']); } if ($aCMDResult['setup-db'] || $aCMDResult['all']) @@ -105,7 +106,16 @@ // TODO: path detection, detection memory, etc. $oDB =& getDB(); - passthru('createlang plpgsql '.$aDSNInfo['database']); + + $sVersionString = $oDB->getOne('select version()'); + preg_match('#PostgreSQL ([0-9]+)[.]([0-9]+)[.]([0-9]+) #', $sVersionString, $aMatches); + if (CONST_Postgresql_Version != $aMatches[1].'.'.$aMatches[2]) + { + echo "ERROR: PostgreSQL version is not correct. Expected ".CONST_Postgresql_Version." found ".$aMatches[1].'.'.$aMatches[2]."\n"; + exit; + } + + passthru('createlang plpgsql -p '.$aDSNInfo['port'].' '.$aDSNInfo['database']); $pgver = (float) CONST_Postgresql_Version; if ($pgver < 9.1) { pgsqlRunScriptFile(CONST_Path_Postgresql_Contrib.'/hstore.sql'); @@ -113,7 +123,16 @@ } else { pgsqlRunScript('CREATE EXTENSION hstore'); } + pgsqlRunScriptFile(CONST_Path_Postgresql_Postgis.'/postgis.sql'); + $sVersionString = $oDB->getOne('select postgis_full_version()'); + preg_match('#POSTGIS="([0-9]+)[.]([0-9]+)[.]([0-9]+)( r([0-9]+))?"#', $sVersionString, $aMatches); + if (CONST_Postgis_Version != $aMatches[1].'.'.$aMatches[2]) + { + echo "ERROR: PostGIS version is not correct. Expected ".CONST_Postgis_Version." found ".$aMatches[1].'.'.$aMatches[2]."\n"; + exit; + } + pgsqlRunScriptFile(CONST_Path_Postgresql_Postgis.'/spatial_ref_sys.sql'); pgsqlRunScriptFile(CONST_BasePath.'/data/country_name.sql'); pgsqlRunScriptFile(CONST_BasePath.'/data/country_naturalearthdata.sql'); @@ -136,8 +155,10 @@ echo "Please download and build osm2pgsql.\nIf it is already installed, check the path in your local settings (settings/local.php) file.\n"; fail("osm2pgsql not found in '$osm2pgsql'"); } + $osm2pgsql .= ' --tablespace-slim-index ssd --tablespace-main-index ssd --tablespace-main-data ssd --tablespace-slim-data data'; $osm2pgsql .= ' -lsc -O gazetteer --hstore'; - $osm2pgsql .= ' -C '.$iCacheMemory; + $osm2pgsql .= ' -C 16000'; + $osm2pgsql .= ' -P '.$aDSNInfo['port']; $osm2pgsql .= ' -d '.$aDSNInfo['database'].' '.$aCMDResult['osm-file']; passthruCheckReturn($osm2pgsql); @@ -203,9 +224,38 @@ pgsqlRunScript($sTemplate); } - if ($aCMDResult['create-partitions'] || $aCMDResult['all']) + if ($aCMDResult['create-partition-tables'] || $aCMDResult['all']) + { + echo "Partition Tables\n"; + $bDidSomething = true; + $oDB =& getDB(); + $sSQL = 'select partition from country_name order by country_code'; + $aPartitions = $oDB->getCol($sSQL); + if (PEAR::isError($aPartitions)) + { + fail($aPartitions->getMessage()); + } + $aPartitions[] = 0; + + $sTemplate = file_get_contents(CONST_BasePath.'/sql/partition-tables.src.sql'); + preg_match_all('#^-- start(.*?)^-- end#ms', $sTemplate, $aMatches, PREG_SET_ORDER); + foreach($aMatches as $aMatch) + { + $sResult = ''; + foreach($aPartitions as $sPartitionName) + { + $sResult .= str_replace('-partition-', $sPartitionName, $aMatch[1]); + } + $sTemplate = str_replace($aMatch[0], $sResult, $sTemplate); + } + + pgsqlRunScript($sTemplate); + } + + + if ($aCMDResult['create-partition-functions'] || $aCMDResult['all']) { - echo "Partitions\n"; + echo "Partition Functions\n"; $bDidSomething = true; $oDB =& getDB(); $sSQL = 'select partition from country_name order by country_code'; @@ -216,7 +266,7 @@ } $aPartitions[] = 0; - $sTemplate = file_get_contents(CONST_BasePath.'/sql/partitions.src.sql'); + $sTemplate = file_get_contents(CONST_BasePath.'/sql/partition-functions.src.sql'); preg_match_all('#^-- start(.*?)^-- end#ms', $sTemplate, $aMatches, PREG_SET_ORDER); foreach($aMatches as $aMatch) { @@ -432,7 +482,7 @@ $sSQL .= "select 'P',nextval('seq_postcodes'),'place','postcode',postcode,calculated_country_code,"; $sSQL .= "ST_SetSRID(ST_Point(x,y),4326) as geometry from (select calculated_country_code,postcode,"; $sSQL .= "avg(st_x(st_centroid(geometry))) as x,avg(st_y(st_centroid(geometry))) as y "; - $sSQL .= "from placex where postcode is not null group by calculated_country_code,postcode) as x"; + $sSQL .= "from placex where postcode is not null and calculated_country_code not in ('ie') group by calculated_country_code,postcode) as x"; if (!pg_query($oDB->connection, $sSQL)) fail(pg_last_error($oDB->connection)); $sSQL = "insert into placex (osm_type,osm_id,class,type,postcode,calculated_country_code,geometry) "; @@ -446,7 +496,11 @@ $bDidSomething = true; $oDB =& getDB(); - if (!file_exists(CONST_Osmosis_Binary)) fail("please download osmosis"); + if (!file_exists(CONST_Osmosis_Binary)) + { + echo "Please download osmosis.\nIf it is already installed, check the path in your local settings (settings/local.php) file.\n"; + fail("osmosis not found in '".CONST_Osmosis_Binary."'"); + } if (file_exists(CONST_BasePath.'/settings/configuration.txt')) { echo "settings/configuration.txt already exists\n"; @@ -454,8 +508,9 @@ else { passthru(CONST_Osmosis_Binary.' --read-replication-interval-init '.CONST_BasePath.'/settings'); - // server layout changed afer license change, fix path to minutely diffs - passthru("sed -i 's:minute-replicate:replication/minute:' ".CONST_BasePath.'/settings/configuration.txt'); + // update osmosis configuration.txt with our settings + passthru("sed -i 's!baseUrl=.*!baseUrl=".CONST_Replication_Url."!' ".CONST_BasePath.'/settings/configuration.txt'); + passthru("sed -i 's:maxInterval = .*:maxInterval = ".CONST_Replication_MaxInterval.":' ".CONST_BasePath.'/settings/configuration.txt'); } // Find the last node in the DB @@ -468,10 +523,12 @@ $iLastNodeTimestamp = strtotime($aLastNodeDate[1]) - (3*60*60); - // Search for the correct state file - uses file timestamps - $sRepURL = 'http://planet.openstreetmap.org/replication/minute/'; - $sRep = file_get_contents($sRepURL); - preg_match_all('#([0-9]{3}/) *(([0-9]{2})-([A-z]{3})-([0-9]{4}) ([0-9]{2}):([0-9]{2}))#', $sRep, $aRepMatches, PREG_SET_ORDER); + // Search for the correct state file - uses file timestamps so need to sort by date descending + $sRepURL = CONST_Replication_Url."/"; + $sRep = file_get_contents($sRepURL."?C=M;O=D"); + // download.geofabrik.de: 000/26-Feb-2013 11:53 + // planet.openstreetmap.org: 273/ 22-Mar-2013 07:41 - + preg_match_all('#([0-9]{3}/).*(([0-9]{2})-([A-z]{3})-([0-9]{4}) ([0-9]{2}):([0-9]{2}))#', $sRep, $aRepMatches, PREG_SET_ORDER); $aPrevRepMatch = false; foreach($aRepMatches as $aRepMatch) { @@ -481,8 +538,8 @@ if ($aPrevRepMatch) $aRepMatch = $aPrevRepMatch; $sRepURL .= $aRepMatch[1]; - $sRep = file_get_contents($sRepURL); - preg_match_all('#([0-9]{3}/) *(([0-9]{2})-([A-z]{3})-([0-9]{4}) ([0-9]{2}):([0-9]{2}))#', $sRep, $aRepMatches, PREG_SET_ORDER); + $sRep = file_get_contents($sRepURL."?C=M;O=D"); + preg_match_all('#([0-9]{3}/).*(([0-9]{2})-([A-z]{3})-([0-9]{4}) ([0-9]{2}):([0-9]{2}))#', $sRep, $aRepMatches, PREG_SET_ORDER); $aPrevRepMatch = false; foreach($aRepMatches as $aRepMatch) { @@ -492,8 +549,8 @@ if ($aPrevRepMatch) $aRepMatch = $aPrevRepMatch; $sRepURL .= $aRepMatch[1]; - $sRep = file_get_contents($sRepURL); - preg_match_all('#([0-9]{3}).state.txt *(([0-9]{2})-([A-z]{3})-([0-9]{4}) ([0-9]{2}):([0-9]{2}))#', $sRep, $aRepMatches, PREG_SET_ORDER); + $sRep = file_get_contents($sRepURL."?C=M;O=D"); + preg_match_all('#([0-9]{3}).state.txt.*(([0-9]{2})-([A-z]{3})-([0-9]{4}) ([0-9]{2}):([0-9]{2}))#', $sRep, $aRepMatches, PREG_SET_ORDER); $aPrevRepMatch = false; foreach($aRepMatches as $aRepMatch) { @@ -518,7 +575,7 @@ $bDidSomething = true; $sOutputFile = ''; if (isset($aCMDResult['index-output'])) $sOutputFile = ' -F '.$aCMDResult['index-output']; - $sBaseCmd = CONST_BasePath.'/nominatim/nominatim -i -d '.$aDSNInfo['database'].' -t '.$iInstances.$sOutputFile; + $sBaseCmd = CONST_BasePath.'/nominatim/nominatim -i -d '.$aDSNInfo['database'].' -P '.$aDSNInfo['port'].' -t '.$iInstances.$sOutputFile; passthruCheckReturn($sBaseCmd.' -R 4'); if (!$aCMDResult['index-noanalyse']) pgsqlRunScript('ANALYSE'); passthruCheckReturn($sBaseCmd.' -r 5 -R 25'); @@ -568,6 +625,9 @@ @symlink(CONST_BasePath.'/website/reverse.php', $sTargetDir.'/reverse.php'); @symlink(CONST_BasePath.'/website/search.php', $sTargetDir.'/search.php'); @symlink(CONST_BasePath.'/website/search.php', $sTargetDir.'/index.php'); + @symlink(CONST_BasePath.'/website/deletable.php', $sTargetDir.'/deletable.php'); + @symlink(CONST_BasePath.'/website/polygons.php', $sTargetDir.'/polygons.php'); + @symlink(CONST_BasePath.'/website/status.php', $sTargetDir.'/status.php'); @symlink(CONST_BasePath.'/website/images', $sTargetDir.'/images'); @symlink(CONST_BasePath.'/website/js', $sTargetDir.'/js'); @symlink(CONST_BasePath.'/website/css', $sTargetDir.'/css');