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.
13 A new separate table for artificially computed postcode centroids was introduced.
14 Migration to the new format is possible but **not recommended**.
16 Create postcode table and indexes, running the following SQL statements:
19 CREATE TABLE location_postcode
20 (place_id BIGINT, parent_place_id BIGINT, rank_search SMALLINT,
21 rank_address SMALLINT, indexed_status SMALLINT, indexed_date TIMESTAMP,
22 country_code varchar(2), postcode TEXT,
23 geometry GEOMETRY(Geometry, 4326));
24 CREATE INDEX idx_postcode_geometry ON location_postcode USING GIST (geometry);
25 CREATE UNIQUE INDEX idx_postcode_id ON location_postcode USING BTREE (place_id);
26 CREATE INDEX idx_postcode_postcode ON location_postcode USING BTREE (postcode);
27 GRANT SELECT ON location_postcode TO "www-data";
28 drop type if exists nearfeaturecentr cascade;
29 create type nearfeaturecentr as (
32 rank_address smallint,
41 Add postcode column to `location_area` tables with SQL statement:
44 ALTER TABLE location_area ADD COLUMN postcode TEXT;
47 Then reimport the functions:
50 ./utils/setup.php --create-functions --enable-diff-updates --create-partition-functions
53 Create appropriate triggers with SQL:
56 CREATE TRIGGER location_postcode_before_update BEFORE UPDATE ON location_postcode
57 FOR EACH ROW EXECUTE PROCEDURE postcode_update();
60 Finally populate the postcode table (will take a while):
63 ./utils/setup.php --calculate-postcodes --index --index-noanalyse
66 This will create a working database. You may also delete the old artificial
67 postcodes now. Note that this may be expensive and is not absolutely necessary.
68 The following SQL statement will remove them:
71 DELETE FROM place_addressline a USING placex p
72 WHERE a.address_place_id = p.place_id and p.osm_type = 'P';
73 ALTER TABLE placex DISABLE TRIGGER USER;
74 DELETE FROM placex WHERE osm_type = 'P';
75 ALTER TABLE placex ENABLE TRIGGER USER;