From 16b687d6bf62e954043ea1c470b770f5070ef8a7 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Wed, 9 Oct 2024 19:35:52 +0200 Subject: [PATCH 1/2] chore: gtfs-api: make query cost limit configurable --- .env | 4 +++- docker-compose.yml | 1 + etc/gtfs/postprocessing.d/40-postgrest-cost-limit.sql | 5 ++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.env b/.env index f063775..c7300c8 100644 --- a/.env +++ b/.env @@ -54,7 +54,7 @@ IPL_GTFS_DB_POSTGRES_DB=gtfs_importer IPL_GTFS_DB_POSTGRES_DB_PREFIX=gtfs # gtfs-importer variables -IPL_GTFS_IMPORTER_IMAGE=ghcr.io/mobidata-bw/postgis-gtfs-importer:v4-2024-10-03T22.54.08-d81cfdd +IPL_GTFS_IMPORTER_IMAGE=ghcr.io/mobidata-bw/postgis-gtfs-importer:v4-2024-10-09T19.12.35-d771aa4 IPL_GTFS_IMPORTER_GTFS_DOWNLOAD_URL=https://www.nvbw.de/fileadmin/user_upload/service/open_data/fahrplandaten_mit_liniennetz/bwgesamt.zip IPL_GTFS_IMPORTER_GTFS_DOWNLOAD_USER_AGENT=IPL (MobiData-BW) # This assumes, that the ipl platform is started in a directory `ipl` which's name becomes @@ -64,6 +64,8 @@ IPL_GTFS_IMPORTER_NETWORK=ipl_ipl # Which schema to import into within each GTFS-dataset-specific PostgreSQL DB. # Note: don't modify this without also adapting etc/gtfs/postprocessing.d/* accordingly. IPL_GTFS_IMPORTER_SCHEMA=api +# Cost (as calculated by the PostgreSQL query planner) limit to all queries that can be made via gtfs-api. +IPL_GTFS_API_COST_LIMIT=1000000 # `postgrest` role used by the gtfs-api service (PostgREST) IPL_GTFS_DB_POSTGREST_USER=postgrest diff --git a/docker-compose.yml b/docker-compose.yml index a874bb9..427f43e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -645,6 +645,7 @@ services: GTFS_TMP_DIR: /var/gtfs POSTGREST_USER: ${IPL_GTFS_DB_POSTGREST_USER:?missing/empty} POSTGREST_PASSWORD: ${IPL_GTFS_DB_POSTGREST_PASSWORD:?missing/empty} + POSTGREST_STATEMENT_COST_LIMIT: ${IPL_GTFS_API_COST_LIMIT:?missing/empty} gtfs-api-docs: networks: [ipl] diff --git a/etc/gtfs/postprocessing.d/40-postgrest-cost-limit.sql b/etc/gtfs/postprocessing.d/40-postgrest-cost-limit.sql index 915d6d4..30064b3 100644 --- a/etc/gtfs/postprocessing.d/40-postgrest-cost-limit.sql +++ b/etc/gtfs/postprocessing.d/40-postgrest-cost-limit.sql @@ -40,4 +40,7 @@ SELECT pg_temp._alter_db(current_database(), 'session_preload_libraries', 'plan_ -- [3] https://github.com/PostgREST/postgrest/issues/3045 -- Limit postgrest's & web_anon's queries by the query planner's estimated cost. -ALTER ROLE postgrest SET plan_filter.statement_cost_limit = 1000000.0; +-- Use $POSTGREST_STATEMENT_COST_LIMIT, fall back to 1000000. +\set cost_limit `echo -n "${POSTGREST_STATEMENT_COST_LIMIT:1000000}"` +-- https://stackoverflow.com/a/18730455/1072129 +ALTER ROLE postgrest SET plan_filter.statement_cost_limit = :'cost_limit'; From 25cd296aaa2f63564cd2af15c73897cdab2e2081 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Wed, 9 Oct 2024 23:39:29 +0200 Subject: [PATCH 2/2] chore: gtfs-api: increase default query cost limit to 3m --- .env | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.env b/.env index c7300c8..4f4fae2 100644 --- a/.env +++ b/.env @@ -65,7 +65,8 @@ IPL_GTFS_IMPORTER_NETWORK=ipl_ipl # Note: don't modify this without also adapting etc/gtfs/postprocessing.d/* accordingly. IPL_GTFS_IMPORTER_SCHEMA=api # Cost (as calculated by the PostgreSQL query planner) limit to all queries that can be made via gtfs-api. -IPL_GTFS_API_COST_LIMIT=1000000 +# 3.000.000 is roughly equivalent to 0.5s-15s. +IPL_GTFS_API_COST_LIMIT=3000000 # `postgrest` role used by the gtfs-api service (PostgREST) IPL_GTFS_DB_POSTGREST_USER=postgrest