]> git.openstreetmap.org Git - nominatim.git/blob - docs/Migration.md
Merge remote-tracking branch 'upstream/master'
[nominatim.git] / docs / Migration.md
1 Database Migrations
2 ===================
3
4 This page describes database migrations necessary to update existing databases
5 to newer versions of Nominatim.
6
7 SQL statements should be executed from the postgres commandline. Execute
8 `psql nominiatim` to enter command line mode.
9
10 3.0.0
11 -----
12
13 ### Postcode Table
14
15 A new separate table for artificially computed postcode centroids was introduced.
16 Migration to the new format is possible but **not recommended**.
17
18  * create postcode table and indexes, running the following SQL statements:
19
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";
29
30  * add postcode column to location_area tables with SQL statement:
31
32        ALTER TABLE location_area ADD COLUMN postcode TEXT;
33
34  * reimport functions
35
36        ./utils/setup.php --create-functions --enable-diff-updates --create-partition-functions
37
38  * create appropriate triggers with SQL:
39
40        CREATE TRIGGER location_postcode_before_update BEFORE UPDATE ON location_postcode
41          FOR EACH ROW EXECUTE PROCEDURE postcode_update();
42
43  * populate postcode table (will take a while):
44
45        ./utils/setup.php --calculate-postcodes --index --index-noanalyse
46
47 This will create a working database. You may also delete the old artificial
48 postcodes now. Note that this may be expensive and is not absolutely necessary.
49 The following SQL statement will remove them:
50
51     DELETE FROM place_addressline a USING placex p
52      WHERE a.address_place_id = p.place_id and p.osm_type = 'P';
53     ALTER TABLE placex DISABLE TRIGGER USER;
54     DELETE FROM placex WHERE osm_type = 'P';
55     ALTER TABLE placex ENABLE TRIGGER USER;
56