4 This page describes database migrations necessary to update existing databases
5 to newer versions of Nominatim.
7 SQL statements should be executed from the postgres commandline. Execute
8 `psql nominiatim` to enter command line mode.
14 A new separate table for artificially computed postcode centroids was introduced.
15 Migration to the new format is possible but **not recommended**.
17 Create postcode table and indexes, running the following SQL statements:
20 CREATE TABLE location_postcode
21 (place_id BIGINT, parent_place_id BIGINT, rank_search SMALLINT,
22 rank_address SMALLINT, indexed_status SMALLINT, indexed_date TIMESTAMP,
23 country_code varchar(2), postcode TEXT,
24 geometry GEOMETRY(Geometry, 4326));
25 CREATE INDEX idx_postcode_geometry ON location_postcode USING GIST (geometry);
26 CREATE UNIQUE INDEX idx_postcode_id ON location_postcode USING BTREE (place_id);
27 CREATE INDEX idx_postcode_postcode ON location_postcode USING BTREE (postcode);
28 GRANT SELECT ON location_postcode TO "www-data";
31 Add postcode column to `location_area` tables with SQL statement:
34 ALTER TABLE location_area ADD COLUMN postcode TEXT;
37 Then reimport the functions:
40 ./utils/setup.php --create-functions --enable-diff-updates --create-partition-functions
43 Create appropriate triggers with SQL:
46 CREATE TRIGGER location_postcode_before_update BEFORE UPDATE ON location_postcode
47 FOR EACH ROW EXECUTE PROCEDURE postcode_update();
50 Finally populate the postcode table (will take a while):
53 ./utils/setup.php --calculate-postcodes --index --index-noanalyse
56 This will create a working database. You may also delete the old artificial
57 postcodes now. Note that this may be expensive and is not absolutely necessary.
58 The following SQL statement will remove them:
61 DELETE FROM place_addressline a USING placex p
62 WHERE a.address_place_id = p.place_id and p.osm_type = 'P';
63 ALTER TABLE placex DISABLE TRIGGER USER;
64 DELETE FROM placex WHERE osm_type = 'P';
65 ALTER TABLE placex ENABLE TRIGGER USER;