3 This page describes database migrations necessary to update existing databases
4 to newer versions of Nominatim.
6 SQL statements should be executed from the PostgreSQL commandline. Execute
7 `psql nominatim` to enter command line mode.
11 ### Change order during indexing
13 When reindexing places during updates, there is now a different order used
14 which needs a different database index. Create it with the following SQL command:
17 CREATE INDEX idx_placex_pendingsector_rank_address
18 ON placex USING BTREE (rank_address, geometry_sector) where indexed_status > 0;
21 You can then drop the old index with:
24 DROP INDEX idx_placex_pendingsector
29 This index has been unused ever since the query using it was changed two years ago. Saves about 12GB on a planet installation.
32 DROP INDEX idx_placex_geometry_reverse_lookupPoint
35 ### Switching to dotenv
37 As part of the work changing the configuration format, the configuration for
38 the website is now using a separate configuration file. To create the
39 configuration file, run the following command after updating:
42 ./utils/setup.php --setup-website
47 ### New Wikipedia/Wikidata importance tables
49 The `wikipedia_*` tables have a new format that also includes references to
50 Wikidata. You need to update the computation functions and the tables as
53 * download the new Wikipedia tables as described in the import section
54 * reimport the tables: `./utils/setup.php --import-wikipedia-articles`
55 * update the functions: `./utils/setup.php --create-functions --enable-diff-updates`
56 * compute importance: `./utils/update.php --recompute-importance`
58 The last step takes about 10 hours on the full planet.
60 Remove one function (it will be recreated in the next step):
63 DROP FUNCTION create_country(hstore,character varying);
66 Finally, update all SQL functions:
69 ./utils/setup.php --create-functions --enable-diff-updates --create-partition-functions
74 ### Reorganisation of location_area_country table
76 The table `location_area_country` has been optimized. You need to switch to the
77 new format when you run updates. While updates are disabled, run the following
81 CREATE TABLE location_area_country_new AS
82 SELECT place_id, country_code, geometry FROM location_area_country;
83 DROP TABLE location_area_country;
84 ALTER TABLE location_area_country_new RENAME TO location_area_country;
85 CREATE INDEX idx_location_area_country_geometry ON location_area_country USING GIST (geometry);
86 CREATE INDEX idx_location_area_country_place_id ON location_area_country USING BTREE (place_id);
89 Finally, update all SQL functions:
92 ./utils/setup.php --create-functions --enable-diff-updates --create-partition-functions
97 ### New database connection string (DSN) format
99 Previously database connection setting (`CONST_Database_DSN` in `settings/*.php`) had the format
101 * (simple) `pgsql://@/nominatim`
102 * (complex) `pgsql://johndoe:secret@machine1.domain.com:1234/db1`
106 * (simple) `pgsql:dbname=nominatim`
107 * (complex) `pgsql:dbname=db1;host=machine1.domain.com;port=1234;user=johndoe;password=secret`
109 ### Natural Earth country boundaries no longer needed as fallback
112 DROP TABLE country_naturalearthdata;
115 Finally, update all SQL functions:
118 ./utils/setup.php --create-functions --enable-diff-updates --create-partition-functions
121 ### Configurable Address Levels
123 The new configurable address levels require a new table. Create it with the
127 ./utils/update.php --update-address-levels
132 ### New reverse algorithm
134 The reverse algorithm has changed and requires new indexes. Run the following
135 SQL statements to create the indexes:
138 CREATE INDEX idx_placex_geometry_reverse_lookupPoint
139 ON placex USING gist (geometry)
140 WHERE (name is not null or housenumber is not null or rank_address between 26 and 27)
141 AND class not in ('railway','tunnel','bridge','man_made')
142 AND rank_address >= 26 AND indexed_status = 0 AND linked_place_id is null;
143 CREATE INDEX idx_placex_geometry_reverse_lookupPolygon
144 ON placex USING gist (geometry)
145 WHERE St_GeometryType(geometry) in ('ST_Polygon', 'ST_MultiPolygon')
146 AND rank_address between 4 and 25 AND type != 'postcode'
147 AND name is not null AND indexed_status = 0 AND linked_place_id is null;
148 CREATE INDEX idx_placex_geometry_reverse_placeNode
149 ON placex USING gist (geometry)
150 WHERE osm_type = 'N' AND rank_search between 5 and 25
151 AND class = 'place' AND type != 'postcode'
152 AND name is not null AND indexed_status = 0 AND linked_place_id is null;
155 You also need to grant the website user access to the `country_osm_grid` table:
158 GRANT SELECT ON table country_osm_grid to "www-user";
161 Replace the `www-user` with the user name of your website server if necessary.
163 You can now drop the unused indexes:
166 DROP INDEX idx_placex_reverse_geometry;
169 Finally, update all SQL functions:
172 ./utils/setup.php --create-functions --enable-diff-updates --create-partition-functions
179 A new separate table for artificially computed postcode centroids was introduced.
180 Migration to the new format is possible but **not recommended**.
182 Create postcode table and indexes, running the following SQL statements:
185 CREATE TABLE location_postcode
186 (place_id BIGINT, parent_place_id BIGINT, rank_search SMALLINT,
187 rank_address SMALLINT, indexed_status SMALLINT, indexed_date TIMESTAMP,
188 country_code varchar(2), postcode TEXT,
189 geometry GEOMETRY(Geometry, 4326));
190 CREATE INDEX idx_postcode_geometry ON location_postcode USING GIST (geometry);
191 CREATE UNIQUE INDEX idx_postcode_id ON location_postcode USING BTREE (place_id);
192 CREATE INDEX idx_postcode_postcode ON location_postcode USING BTREE (postcode);
193 GRANT SELECT ON location_postcode TO "www-data";
194 drop type if exists nearfeaturecentr cascade;
195 create type nearfeaturecentr as (
198 rank_address smallint,
199 rank_search smallint,
207 Add postcode column to `location_area` tables with SQL statement:
210 ALTER TABLE location_area ADD COLUMN postcode TEXT;
213 Then reimport the functions:
216 ./utils/setup.php --create-functions --enable-diff-updates --create-partition-functions
219 Create appropriate triggers with SQL:
222 CREATE TRIGGER location_postcode_before_update BEFORE UPDATE ON location_postcode
223 FOR EACH ROW EXECUTE PROCEDURE postcode_update();
226 Finally populate the postcode table (will take a while):
229 ./utils/setup.php --calculate-postcodes --index --index-noanalyse
232 This will create a working database. You may also delete the old artificial
233 postcodes now. Note that this may be expensive and is not absolutely necessary.
234 The following SQL statement will remove them:
237 DELETE FROM place_addressline a USING placex p
238 WHERE a.address_place_id = p.place_id and p.osm_type = 'P';
239 ALTER TABLE placex DISABLE TRIGGER USER;
240 DELETE FROM placex WHERE osm_type = 'P';
241 ALTER TABLE placex ENABLE TRIGGER USER;