22
FOSSGIS 2020 PostGIS 3 ist da! PostGIS 3 Dr. Marco Hugentobler Sourcepole AG, Zürich www.sourcepole.ch https://twitter.com/sourcepole

PostGIS 3 - pretalx · 2020. 3. 23. · FOSSGIS 2020 PostGIS > Räumlich Erweiterung für PostgreSQL > Projekt wurde 2000 von der Firma Refractions Research gegründet > Seit 2012

  • Upload
    others

  • View
    8

  • Download
    0

Embed Size (px)

Citation preview

Page 1: PostGIS 3 - pretalx · 2020. 3. 23. · FOSSGIS 2020 PostGIS > Räumlich Erweiterung für PostgreSQL > Projekt wurde 2000 von der Firma Refractions Research gegründet > Seit 2012

FOSSGIS 2020

PostGIS 3 ist da!

PostGIS 3

Dr. Marco HugentoblerSourcepole AG, Zürichwww.sourcepole.chhttps://twitter.com/sourcepole

Page 2: PostGIS 3 - pretalx · 2020. 3. 23. · FOSSGIS 2020 PostGIS > Räumlich Erweiterung für PostgreSQL > Projekt wurde 2000 von der Firma Refractions Research gegründet > Seit 2012

FOSSGIS 2020

PostGIS3

> Folien Felix Kunde: https://slides.com/fxku/postgis-v3

> Vortrag Paul Ramsey PostGIS day 2019: https://www.youtube.com/watch?v=SeshcN92yF4

Page 3: PostGIS 3 - pretalx · 2020. 3. 23. · FOSSGIS 2020 PostGIS > Räumlich Erweiterung für PostgreSQL > Projekt wurde 2000 von der Firma Refractions Research gegründet > Seit 2012

FOSSGIS 2020

PostGIS

> Räumlich Erweiterung für PostgreSQL

> Projekt wurde 2000 von der Firma Refractions Research gegründet

> Seit 2012 Mitglied von OSGeo

> Versionsgeschichte:> 0.1 2001> 1.0 2005> 2.0 2012> 3.0 20. Oktober 2019> Aktuell: 3.0.1

> Versionsnummern: major.minor.patch

Page 4: PostGIS 3 - pretalx · 2020. 3. 23. · FOSSGIS 2020 PostGIS > Räumlich Erweiterung für PostgreSQL > Projekt wurde 2000 von der Firma Refractions Research gegründet > Seit 2012

FOSSGIS 2020

PostgreSQL + GIS = PostGIS

> Geometry-Typ

> Geography-Typ

> Räumliche Funktionen

> Räumliche Indices

> Raster

> Topology

Page 5: PostGIS 3 - pretalx · 2020. 3. 23. · FOSSGIS 2020 PostGIS > Räumlich Erweiterung für PostgreSQL > Projekt wurde 2000 von der Firma Refractions Research gegründet > Seit 2012

FOSSGIS 2020

Geometry

> ISO-SQL/MM> POINT / MULTIPOINT> LINESTRING / MULTILINESTRING> POLYGON / MULTIPOLYGON> CIRCULARARC / COMPOUNDCURVE /

CURVEPOLYGON / MULTICURVE / MULTISURFACE> GEOMETRYCOLLECTION

> Alle Typen auch mit z- und m-Koordinate

> Import/Export in WKB/WKT/GML/JSON

> Koordinatensystem (srid)

Page 6: PostGIS 3 - pretalx · 2020. 3. 23. · FOSSGIS 2020 PostGIS > Räumlich Erweiterung für PostgreSQL > Projekt wurde 2000 von der Firma Refractions Research gegründet > Seit 2012

FOSSGIS 2020

Geography

> Objekte in einem geodätischen Koordinatensystem (aber keine Kreisbögen)

> Wird von weniger Funktionen unterstützt als Geometry

> Funktionen berücksichtigen Ellipsoid, Datumsgrenze und Pole

Page 7: PostGIS 3 - pretalx · 2020. 3. 23. · FOSSGIS 2020 PostGIS > Räumlich Erweiterung für PostgreSQL > Projekt wurde 2000 von der Firma Refractions Research gegründet > Seit 2012

FOSSGIS 2020

Räumliche Funktionen

> Import / Export

> Geometrieoperationen> ST_INTERSECTS, ST_CONTAINS, ST_TOUCHES,

ST_UNION, ST_SIMPLIFY, ST_BUFFER, ST_AREA, ST_DISTANCE, …

Page 8: PostGIS 3 - pretalx · 2020. 3. 23. · FOSSGIS 2020 PostGIS > Räumlich Erweiterung für PostgreSQL > Projekt wurde 2000 von der Firma Refractions Research gegründet > Seit 2012

FOSSGIS 2020

Räumliche Indices

> Schnelle räumliche Suche, ohne alle Objekte anzuschauen

> Verschiedene Indextypen:> GIST> BRIN> SPGIST

Page 9: PostGIS 3 - pretalx · 2020. 3. 23. · FOSSGIS 2020 PostGIS > Räumlich Erweiterung für PostgreSQL > Projekt wurde 2000 von der Firma Refractions Research gegründet > Seit 2012

FOSSGIS 2020

Was ist neu in PostGIS 3?> Raster ist separate Extension

(postgis_raster)> ALTER EXTENSION postgis UPDATE TO '3.0.0'> SELECT postgis_extensions_upgrade()

> Neues Geometrieformat> kompakter> 2.x Readerfunktion weiter verfügbar (kein

hard upgrade nötig)

> RäumlicheFunktionen können mit Geometrycollections umgehen

Page 10: PostGIS 3 - pretalx · 2020. 3. 23. · FOSSGIS 2020 PostGIS > Räumlich Erweiterung für PostgreSQL > Projekt wurde 2000 von der Firma Refractions Research gegründet > Seit 2012

FOSSGIS 2020

Was ist neu in PostGIS3?

> Verbessertes ST_AsGeoJSON

> Bessere Unterstützung für parallele Abfragen

> Unterstützt Proj6

Page 11: PostGIS 3 - pretalx · 2020. 3. 23. · FOSSGIS 2020 PostGIS > Räumlich Erweiterung für PostgreSQL > Projekt wurde 2000 von der Firma Refractions Research gegründet > Seit 2012

FOSSGIS 2020

Proj6

> Version 6 der PROJ-Bibliothek im März 2019 herausgekommen

> In PROJ4: Datumstransformationen gehen per default über WGS84

> PROJ6 hat bessere Defaulttransformationen, z.B. CH03 CH95 → CH95 über NTV2-grid anstatt towgs84

Page 12: PostGIS 3 - pretalx · 2020. 3. 23. · FOSSGIS 2020 PostGIS > Räumlich Erweiterung für PostgreSQL > Projekt wurde 2000 von der Firma Refractions Research gegründet > Seit 2012

FOSSGIS 2020

Was gibt es nicht mehr in PostGIS 3?

> Kein Support mehr für PostgreSQL < 9.5

> Kein Support mehr für GEOS < 3.6, empfohlen wird GEOS >= 3.7

> ST_AsGeoJSON, ST_AsKML haben keine Versionsparameter mehr

Page 13: PostGIS 3 - pretalx · 2020. 3. 23. · FOSSGIS 2020 PostGIS > Räumlich Erweiterung für PostgreSQL > Projekt wurde 2000 von der Firma Refractions Research gegründet > Seit 2012

FOSSGIS 2020

Parallele Abfragen

> PostgreSQL < 9.6 : Alle Abfragen können nur in einem Thread ausgeführt werden

> Seit 9.6: parallele Abfragen auf mehreren CPU cores

> Der Query-Planner entscheidet, wann Abfragen paralellisiert werden

> Beeinflussen des Planners mit den Variablen max_worker_processes, max_parallel_workers, max_parallel_workers_per_gather

> Beste Parallelisierung mit PostgreSQL12 und PostGIS 3

Page 14: PostGIS 3 - pretalx · 2020. 3. 23. · FOSSGIS 2020 PostGIS > Räumlich Erweiterung für PostgreSQL > Projekt wurde 2000 von der Firma Refractions Research gegründet > Seit 2012

FOSSGIS 2020

Beispiel 1: sequential scan

> SELECT ST_BUFFER( geometrie, 50 ) FROM stadt_zuerich.av_bo_boflaeche

Page 15: PostGIS 3 - pretalx · 2020. 3. 23. · FOSSGIS 2020 PostGIS > Räumlich Erweiterung für PostgreSQL > Projekt wurde 2000 von der Firma Refractions Research gegründet > Seit 2012

FOSSGIS 2020

PostgreSQL10 / PostGIS 2.4

geodaten=# SET max_parallel_workers_per_gather = 4; EXPLAIN ANALYZE SELECT ST_BUFFER( geometrie, 50 ) from geoz.av_bo_boflaeche_a;

------------------------------------------------------------------------------------------

Seq Scan on av_bo_boflaeche_a (cost=0.00..9458.04 rows=101203 width=32) (actual time=5.118..42591.548 rows=101203 loops=1)

Planning time: 0.129 ms

Execution time: 42601.467 ms

Page 16: PostGIS 3 - pretalx · 2020. 3. 23. · FOSSGIS 2020 PostGIS > Räumlich Erweiterung für PostgreSQL > Projekt wurde 2000 von der Firma Refractions Research gegründet > Seit 2012

FOSSGIS 2020

PostgreSQL12 / PostGIS 3.0

geodaten=# SET max_parallel_workers_per_gather = 4; EXPLAIN ANALYZE SELECT ST_BUFFER( geometrie, 50 ) from stadt_zuerich.av_bo_boflaeche_a;

-------------------------------------------------------------------------------------------

Gather (cost=1000.00..1073558.98 rows=101203 width=32) (actual time=2.002..16170.393 rows=101203 loops=1)

Workers Planned: 2

Workers Launched: 2

-> Parallel Seq Scan on av_bo_boflaeche_a (cost=0.00..1062438.68 rows=42168 width=32) (actual time=0.970..16106.396 rows=33734

loops=3)

Planning Time: 0.103 ms

Execution Time: 16175.804 ms

Page 17: PostGIS 3 - pretalx · 2020. 3. 23. · FOSSGIS 2020 PostGIS > Räumlich Erweiterung für PostgreSQL > Projekt wurde 2000 von der Firma Refractions Research gegründet > Seit 2012

FOSSGIS 2020

Beispiel 2: spatial join

> SELECT a.strassenname, a.hausnummer, l.nummer FROM glarus_mopublic.hadr a JOIN glarus_mopublic.resf l ON ST_CONTAINS( l.geom, a.geom );

Page 18: PostGIS 3 - pretalx · 2020. 3. 23. · FOSSGIS 2020 PostGIS > Räumlich Erweiterung für PostgreSQL > Projekt wurde 2000 von der Firma Refractions Research gegründet > Seit 2012

FOSSGIS 2020

PostgreSQL10 / PostGIS 2.4geodaten=# EXPLAIN ANALYZE SELECT a.strassenname, a.hausnummer, l.nummer FROM glarus_mopublic.hadr a JOIN glarus_mopublic.resf l ON

ST_CONTAINS( l.geom, a.geom );

Gather (cost=1000.27..92545.08 rows=146506 width=18) (actual time=0.796..405.400 rows=18073 loops=1) -> Nested Loop (cost=0.28..76894.48 rows=86180 width=18) (actual

time=0.194..395.991 rows=9036 loops=2)

-> Parallel Seq Scan on resf l (cost=0.00..2019.05 rows=14305 width=657) (actual time=0.007..2.302 rows=12160 loops=2)

-> Index Scan using sidx_hadr_geom on hadr a (cost=0.28..5.17 rows=6 width=46) (actual time=0.024..0.032 rows=1 loops=24319)

Index Cond: (l.geom ~ geom)

Filter: _st_contains(l.geom, geom)

Rows Removed by Filter: 3

Planning time: 2.510 ms

Execution time: 406.205 ms

Page 19: PostGIS 3 - pretalx · 2020. 3. 23. · FOSSGIS 2020 PostGIS > Räumlich Erweiterung für PostgreSQL > Projekt wurde 2000 von der Firma Refractions Research gegründet > Seit 2012

FOSSGIS 2020

PostgreSQL 12 / PostGIS 3.0geodaten=# EXPLAIN ANALYZE SELECT a.strassenname, a.hausnummer, l.nummer FROM glarus_mopublic.hadr a JOIN glarus_mopublic.resf l ON

ST_CONTAINS( l.geom, a.geom );

-------------------------------------------------------------------------------------------

Gather (cost=1000.27..6751759.25 rows=3015390 width=18) (actual time=0.719..423.535 rows=18073 loops=1)

Workers Planned: 1

Workers Launched: 1

-> Nested Loop (cost=0.28..6449220.25 rows=1773759 width=18) (actual time=0.191..416.068 rows=9036 loops=2)

-> Parallel Seq Scan on resf l (cost=0.00..2023.05 rows=14305 width=657) (actual time=0.016..2.390 rows=12160 loops=2)

-> Index Scan using hadr_sindex on hadr a (cost=0.28..450.68 rows=2 width=46) (actual time=0.025..0.033 rows=1 loops=24319)

Index Cond: (geom @ l.geom)

Filter: st_contains(l.geom, geom)

Planning Time: 1.659 ms

Execution Time: 424.254 ms

Page 20: PostGIS 3 - pretalx · 2020. 3. 23. · FOSSGIS 2020 PostGIS > Räumlich Erweiterung für PostgreSQL > Projekt wurde 2000 von der Firma Refractions Research gegründet > Seit 2012

FOSSGIS 2020

Spatial Join Adressen Zürich

> Paralleler query plan (zwei Threads) mit PostgreSQL 10 und PostgreSQL 12

Page 21: PostGIS 3 - pretalx · 2020. 3. 23. · FOSSGIS 2020 PostGIS > Räumlich Erweiterung für PostgreSQL > Projekt wurde 2000 von der Firma Refractions Research gegründet > Seit 2012

FOSSGIS 2020

Upgrade zu PostGIS3

> Soft upgrade> Neue Version parallel installieren (z.B.

postgis-2.4.s0 und postgis-3.so in /usr/lib/postgres/<version>/lib)

> ALTER EXTENSION postgis UPDATE TO “3.0.0”;

> Hard upgrade (nötig, wenn sich die interne Repräsentation der Objekte ändert)> Dump der Datenbank im custom-Format> Neuinstallation von PostGIS in einer neuen DB> Restore des Dumps mit

utils/postgis_restore.pl

> Upgrade von 2.4.3 auf 3.0.0 hat bei mir mit soft upgrade funktioniert

Page 22: PostGIS 3 - pretalx · 2020. 3. 23. · FOSSGIS 2020 PostGIS > Räumlich Erweiterung für PostgreSQL > Projekt wurde 2000 von der Firma Refractions Research gegründet > Seit 2012

FOSSGIS 2020

PostGIS 3 ist da!

Vielen Dank für die Aufmerksamkeit

Marco Hugentoblermarco.hugentobler @ s o u r c e p o l e . c h