2024-01-17 02:30:13 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# Setting up a synced OSM-server for quick layer access
  
						 
					
						
							
								
									
										
										
										
											2024-01-15 15:23:40 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-06-04 18:39:15 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								## Requirements
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Debian machine (e.g. Ubuntu)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								`apt install osmium-tool docker.io osm2pgsql`  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-07-05 23:45:10 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								## Tuning the database
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-07-15 01:51:31 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								## Setting up the SQL-server (only once):
  
						 
					
						
							
								
									
										
										
										
											2024-01-15 15:23:40 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-17 02:30:13 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-07-05 23:45:10 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								For performance, docker needs a specific config file. See https://osm2pgsql.org/doc/manual.html#tuning -the-postgresql-server
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								A suggested config file is:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								(On HDD, 180GB RAM)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								max_connections = 5000 # needed for OSM2PGSQL
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								shared_buffers = 2GB
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								work_mem = 200MB
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								maintenance_work_mem = 15GB
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								autovacuum_work_mem = 4GB
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								wal_level = minimal
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								checkpoint_timeout = 120min
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								max_wal_size = 20GB
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								checkpoint_completion_target = 0.9
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								max_wal_senders = 0
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								random_page_cost = 8.0
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Save this config file somewhere as "postgresql.conf"
							 
						 
					
						
							
								
									
										
										
										
											2024-01-15 15:23:40 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-07-05 23:45:10 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								-  Start the docker with: `docker run --name osm-cache-db -e POSTGRES_PASSWORD=password -e POSTGRES_USER=user -d -p 5444:5432 -v ~/data/pgsql/:/var/lib/postgresql/data -v postgresql.conf:/var/lib/postgresql/data/postgresql.conf postgis/postgis`  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								-  Now, change the config file. This can easily be done as the config file is mirrored to the host system at: 
						 
					
						
							
								
									
										
										
										
											2025-07-06 00:53:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								`~/data/pgsql/postgresql.conf` . Append this file with configuration above, e.g. with `cat posgresql.conf >> ~/data/pgsql/postgresql.conf`  
						 
					
						
							
								
									
										
										
										
											2025-07-05 23:45:10 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								-  Restart the db: `docker restart osm-cache-db`  
						 
					
						
							
								
									
										
										
										
											2024-01-17 02:30:13 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-29 01:46:40 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# Seeding the data
  
						 
					
						
							
								
									
										
										
										
											2024-07-15 01:51:31 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-29 01:46:40 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								>  The following steps are also automated in .forgejo/workflows/update_database.yml
  
						 
					
						
							
								
									
										
										
										
											2024-01-17 02:30:13 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## Importing data
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-23 22:03:22 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Install osm2pgsql (hint: compile from source is painless)
							 
						 
					
						
							
								
									
										
										
										
											2024-01-17 02:30:13 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-03-05 02:24:25 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Download the latest with:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								`nohup transmission-cli https://planet.osm.org/pbf/planet-latest.osm.pbf.torrent &>nohup_transmission.log &`  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								which will download the data to `~/Downloads` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								To seed the database:
							 
						 
					
						
							
								
									
										
										
										
											2024-01-17 02:30:13 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								````
							 
						 
					
						
							
								
									
										
										
										
											2024-07-15 01:51:31 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								nohup osm2pgsql -O flex -S build_db.lua -s --flat-nodes=import-help-file -d postgresql://user:password@localhost:5444/osm -poi < file > .osm.pbf >> seeddb.log
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# To see the progress
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								tail -f seeddb.log
							 
						 
					
						
							
								
									
										
										
										
											2024-01-17 02:30:13 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								````
							 
						 
					
						
							
								
									
										
										
										
											2024-01-23 22:03:22 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Storing properties to table '"public"."osm2pgsql_properties" takes about 25 minutes with planet.osm
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Belgium (~555mb) takes 15m
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								World (80GB) should take 15m*160 = 2400m = 40hr
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-02-15 17:39:59 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								73G Jan 23 00:22 planet-240115.osm.pbf: 2024-02-10 16:45:11  osm2pgsql took 871615s (242h 6m 55s; 10 days) overall on lain.local with RAID5 on 4 HDD disks, database is over 1Terrabyte (!)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Server specs
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Lenovo thinkserver RD350, Intel Xeon E5-2600, 2Rx4 PC3 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    11 watt powered off, 73 watt idle, ~100 watt when importing
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								HP ProLiant DL360 G7 (1U): 2Rx4 DDR3-memory (PC3)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    Intel Xeon X56**
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-02-19 15:38:46 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								## Updating data
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-03-05 02:24:25 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-02-19 15:38:46 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								`osm2pgsql-replication update -d postgresql://user:password@localhost:5444/osm-poi -- -O flex -S build_db.lua -s --flat-nodes=import-help-file`  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-17 02:30:13 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## Deploying a tile server
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-06-12 14:43:19 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								pg_tileserv can be downloaded here: https://github.com/CrunchyData/pg_tileserv
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								In the directory where it is downloaded (e.g. `~/data` ), run
							 
						 
					
						
							
								
									
										
										
										
											2024-01-23 22:03:22 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-13 14:41:28 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								First, look up the latest suitable database on https://mapcomplete.org/status
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-17 02:30:13 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								````
							 
						 
					
						
							
								
									
										
										
										
											2024-12-13 14:41:28 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								export DATABASE_URL=postgresql://user:password@localhost:5444/osm -poi.{date-of-suitable-database}
							 
						 
					
						
							
								
									
										
										
										
											2024-07-08 23:33:28 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								nohup ./pg_tileserv >> pg_tileserv.log & 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-17 02:30:13 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								````
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Tiles are available at: 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								````
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								map.addSource("drinking_water", {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								"type": "vector",
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								"tiles": ["http://127.0.0.2:7800/public.drinking_water/{z}/{x}/{y}.pbf"] // http://127.0.0.2:7800/public.drinking_water.json",
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								})
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								````
							 
						 
					
						
							
								
									
										
										
										
											2024-02-18 15:59:28 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-06-12 14:43:19 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# Starting the summary server
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								`npm run summary-server`  in the git repo 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-13 14:41:28 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# Connecting to the database
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Setup the SSH-tunnel:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								`ssh folky.me
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								ssh -L 5444:127.0.0.1:5444 lain`
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Open a second terminal:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								`ssh -L 5444:127.0.0.1:5444 folky.me`  ` 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Connect pgAdmin
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-02-18 15:59:28 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# Rebooting:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								-> Restart the docker container