Pre-conference Session Materials: GIS Data, Queries, and Performance
This post supports our full day pre-conference session, PostGIS and PostgreSQL: GIS Data, Queries, and Performance at PASS Data Community Summit 2023 on November 13.
Thank you everyone who participated! This page has been updated with the slide decks used during the session.
Downloads for session
The data, permissions script, and example SQL queries used through this session are available below.
Data downloads
Slides
The following downloads are the PDF versions of the slide decks. These printed with empty pages for some reason I was not able to quickly fix. Also note, there is no "02" slide deck. 🤷
SQL Query Files
- SQL 01 a
- SQL 01 b
- SQL 03 a - SRID
- SQL 03 b - Explain
- SQL 03 c - Hexes
- SQL 04 a prepare and route
- SQL 04 b routing multiple
Steps to load
The Demo Database (.sql.gz
above) can be loaded into the PgOSM Flex Docker
image. The following commands run the Docker container.
WARNING: This usage is not expected to support production workloads. This post does not go into those details.
The --cpus
and --memory
settings limit the container to the specs used for
timings throughout the SQL examples.
export POSTGRES_USER=postgres
export POSTGRES_PASSWORD=mysecretpassword
docker pull rustprooflabs/pgosm-flex:h3
docker run --name pgosm -d \
--cpus=1.2 --memory=1024m \
-v ~/pgosm-data:/app/output \
-v /etc/localtime:/etc/localtime:ro \
-e POSTGRES_PASSWORD=$POSTGRES_PASSWORD \
-p 5433:5432 -d rustprooflabs/pgosm-flex:h3 \
-c jit=off \
-c max_parallel_workers_per_gather=2 \
-c work_mem=10MB \
-c shared_preload_libraries='pg_stat_statements' \
-c track_io_timing=on \
-c shared_buffers=250MB \
-c max_wal_senders=0 -c wal_level=minimal \
-c max_wal_size=10GB \
-c checkpoint_timeout=300min \
-c checkpoint_completion_target=0.9 \
-c random_page_cost=1.1
The above command uses a special h3
image from PgOSM Flex to include the h3-pg
extension, not included in the standard image.
The normal PgOSM Flex Docker image should work for all but the H3 examples.
Prepare the database and load the data file.
psql -U postgres -d postgres -h localhost -p 5433 -c "CREATE DATABASE pass2023;"
Connect to pass2023
database.
psql -U postgres -d pass2023 -h localhost -p 5433
Run the following queries to setup the pgosm_flex
role with appropriate permissions.
Don't forget to change the Password in the
CREATE ROLE
query!
CREATE ROLE pgosm_flex WITH LOGIN PASSWORD 'mysecretpassword';
GRANT CREATE ON DATABASE pass2023 TO pgosm_flex;
GRANT CREATE ON SCHEMA public TO pgosm_flex;
CREATE ROLE dd_read WITH NOLOGIN;
CREATE ROLE convert_read WITH NOLOGIN;
CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
GRANT EXECUTE ON FUNCTION pg_stat_statements_reset TO pgosm_flex;
Exit psql using the \q
command.
Download the data. Use psql
to load to pass2023
database.
wget https://postgis-osm.nyc3.cdn.digitaloceanspaces.com/postgis-precon-pass-washington-osm.sql.gz
gunzip postgis-precon-pass-washington-osm.sql.gz
# 30 - 45 seconds
psql -U postgres -d pass2023 -h localhost -p 5433 \
-f postgis-precon-pass-washington-osm.sql
Setup permissions for PgDD and Convert extensions.
wget https://postgis-osm.nyc3.cdn.digitaloceanspaces.com/extension-pgosm-flex-perms.sql
psql -U postgres -d pass2023 -h localhost -p 5433 \
-f extension-pgosm-flex-perms.sql
Links
The links below are links from the slides and SQL in the order they appeared.
- eBook: Mastering PostGIS and OpenStreet Map
- RustProof Labs Blog
- RustProof Labs on Mastodon
- People, Postgres, Data Discord server
- Animation sourced from post
- Geometry viewer added to DBeaver (2019)
- PostGIS home page
- PgDD (GitHub)
- convert (GitHub)
- h3-pg (GitHub)
- PASS 2023 Session - PostgreSQL: Extensions Shape the Future
ST_Contains()
SQL 01
- PostGIS Operators
ST_Union()
ST_Envelope()
ST_DWithin()
- Comment on Address column
- PgOSM Flex Address Only Building
Slides
- PgOSM Flex Quick Start
- PgOSM Flex with External Postgres
- PgOSM Flex Common Customizations
- PgOSM Flex Layersets
- Load the Right Amount of OpenStreetMap Data
- PgOSM Flex for Production OpenStreetMap data
- RustProof Labs Blog: PgOSM Flex Category
- PostgresConf session: Intro to PostGIS and OpenStreetMap
- Ellipsoidal and Cartesian Coordinates Conversion
- GIST Introduction
- PostGIS Operators
SQL 02
Slides
Slides 03
- RustProof Labs' PostGIS Function Guide
- Accuracy of Geometry data in PostGIS
- SRID BBox on GitHub
- Find your Local SRID
SQL 03 SRIDs (no links)
Slides
SQL 03 Explain
- pgbench-tests
- Explain w/ cold cache
- Explain w/ hot cache
- ST_Subdivide all the things
- Use pgbench for A/B performance testing
Slides - Hexes
- Spatial Data Analysis With Hexagonal Grids
- MPDI: Empirical Study on Recognition of Spatial Patterns in Choropleth Maps Using Hexagonal Shaped Units
- PDF: Empirical Study on Recognition of Spatial Patterns in Choropleth Maps Using Hexagonal Shaped Units
- Stop Using Zip Codes for Geospatial Analysis
- The Trouble with Zip Codes: Solutions for Data Analysis and Mapping
- PostGIS Hexagons - Find missing Data
- H3 Indexes for PostGIS searches
ST_HexagonGrid()
- H3 intro in PostGIS post
- Postgres H3 v4 blog post
- H3: Uber’s Hexagonal Hierarchical Spatial Index
- H3 in Postgres
- h3geo.org
- h3-pg issue 130
SQL 03 Hexes
Slides 04 Routing
- Image from Mastering PostGIS and OpenStreetMap
- Routing Lines through polygons
- Route the Interesting Things post
- Route the Interesting Things - PostGIS Day 2022 - Recording
- OpenStreetMap Layer v Levels
- PgOSM Flex - Routing Instructions
- Shameless Plug: eBook Mastering PostGIS and OpenStreetMap
SQL 04 a - Routing (no links)
SQL 04 b - Routing (no links)
Slides
ST_MakePointM()
ST_DistanceCPA()
twCentroid()
- PostGIS Trajectory: Space plus Time
|=|
(smallest distance)nearestApproachInstant()
05
- TOAST
- Compression - large text
- Postgres 12 - partial decompression
shared_buffers
pg_prewarm
- Data sorted on disk can be faster
Summary
Need help with your PostgreSQL servers or databases? Contact us to start the conversation!