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 postgres commandline. Execute
7 `psql nominiatim` to enter command line mode.
11 ### New reverse algorithm
13 The reverse algorithm has changed and requires new indexes. Run the following
14 SQL statements to create the indexes:
17 CREATE INDEX idx_placex_geometry_reverse_lookupPoint
18 ON placex USING gist (geometry) {ts:search-index}
19 WHERE (name is not null or housenumber is not null or rank_address between 26 and 27)
20 AND class not in ('railway','tunnel','bridge','man_made')
21 AND rank_address >= 26 AND indexed_status = 0 AND linked_place_id is null;
22 CREATE INDEX idx_placex_geometry_reverse_lookupPolygon
23 ON placex USING gist (geometry) {ts:search-index}
24 WHERE St_GeometryType(geometry) in ('ST_Polygon', 'ST_MultiPolygon')
25 AND rank_address between 4 and 25 AND type != 'postcode'
26 AND name is not null AND indexed_status = 0 AND linked_place_id is null;
27 CREATE INDEX idx_placex_geometry_reverse_placeNode
28 ON placex USING gist (geometry) {ts:search-index}
29 WHERE osm_type = 'N' AND rank_search between 5 and 25
30 AND class = 'place' AND type != 'postcode'
31 AND name is not null AND indexed_status = 0 AND linked_place_id is null;
34 You also need to grant the website user access to the `country_osm_grid` table:
37 GRANT SELECT ON table country_osm_grid to "www-user";
40 Replace the `www-user` with the user name of your website server if necessary.
42 Finally, you can drop the now unused indexes:
45 DROP INDEX idx_placex_reverse_geometry;
52 A new separate table for artificially computed postcode centroids was introduced.
53 Migration to the new format is possible but **not recommended**.
55 Create postcode table and indexes, running the following SQL statements:
58 CREATE TABLE location_postcode
59 (place_id BIGINT, parent_place_id BIGINT, rank_search SMALLINT,
60 rank_address SMALLINT, indexed_status SMALLINT, indexed_date TIMESTAMP,
61 country_code varchar(2), postcode TEXT,
62 geometry GEOMETRY(Geometry, 4326));
63 CREATE INDEX idx_postcode_geometry ON location_postcode USING GIST (geometry);
64 CREATE UNIQUE INDEX idx_postcode_id ON location_postcode USING BTREE (place_id);
65 CREATE INDEX idx_postcode_postcode ON location_postcode USING BTREE (postcode);
66 GRANT SELECT ON location_postcode TO "www-data";
67 drop type if exists nearfeaturecentr cascade;
68 create type nearfeaturecentr as (
71 rank_address smallint,
80 Add postcode column to `location_area` tables with SQL statement:
83 ALTER TABLE location_area ADD COLUMN postcode TEXT;
86 Then reimport the functions:
89 ./utils/setup.php --create-functions --enable-diff-updates --create-partition-functions
92 Create appropriate triggers with SQL:
95 CREATE TRIGGER location_postcode_before_update BEFORE UPDATE ON location_postcode
96 FOR EACH ROW EXECUTE PROCEDURE postcode_update();
99 Finally populate the postcode table (will take a while):
102 ./utils/setup.php --calculate-postcodes --index --index-noanalyse
105 This will create a working database. You may also delete the old artificial
106 postcodes now. Note that this may be expensive and is not absolutely necessary.
107 The following SQL statement will remove them:
110 DELETE FROM place_addressline a USING placex p
111 WHERE a.address_place_id = p.place_id and p.osm_type = 'P';
112 ALTER TABLE placex DISABLE TRIGGER USER;
113 DELETE FROM placex WHERE osm_type = 'P';
114 ALTER TABLE placex ENABLE TRIGGER USER;