diff --git a/Untitled 3.md b/Untitled 3.md index 8c997c2..ebfd2d7 100644 --- a/Untitled 3.md +++ b/Untitled 3.md @@ -1,7 +1,105 @@ +# OpenStreetMap Database Summary and Operations Guide + +## Current Database State + +- Database name: `planet` +- User: `osmadmin` +- Content: Partial world data, including France, Italy, and possibly other European countries +- Notable points: Eiffel Tower (Paris), Colosseum (Rome), detailed data including small businesses + +## Connecting to the Database + +To connect to the database using psql: + +```bash +psql -d planet -U osmadmin +``` + +## Importing New Data + +### Single File Import + +To import a single .osm.pbf file: + +```bash +osm2pgsql -d planet -U osmadmin -a --slim --drop --hstore --multi-geometry -C 28000 -W --number-processes 8 /path/to/your/new_file.osm.pbf +``` + +Explanation of options: +- `-d planet`: Database name +- `-U osmadmin`: Database user +- `-a`: Append mode (adds to existing data) +- `--slim`: Memory-efficient mode for large imports +- `--drop`: Drops temporary tables after import +- `--hstore`: Stores all tags in an hstore column +- `--multi-geometry`: Allows for multi-polygon geometries +- `-C 28000`: Sets cache size to 28GB (adjust based on available RAM) +- `-W`: Uses disk for temporary storage +- `--number-processes 8`: Enables parallel processing (adjust based on CPU cores) + +### Batch Import Script + +For importing multiple files, create a shell script named `import_osm.sh`: + +```bash +#!/bin/bash +FILES="/home/ed/share/map/extract/pbf/*.osm.pbf" +for f in $FILES +do + echo "Processing $f" + osm2pgsql -d planet -U osmadmin -a --slim --drop --hstore --multi-geometry -C 28000 -W --number-processes 8 "$f" +done +echo "All files processed. Running VACUUM ANALYZE." +psql -d planet -U osmadmin -c "VACUUM ANALYZE;" +``` + +Make the script executable and run it: + +```bash +chmod +x import_osm.sh +./import_osm.sh +``` + +This script will process all .osm.pbf files in the specified directory and optimize the database afterward. + +## Post-Import Optimization + +After importing data, always run: + +```sql +VACUUM ANALYZE; +``` + +This optimizes the database for better query performance. + +## Useful Queries for Data Verification + +1. Count total points: + ```sql + SELECT COUNT(*) FROM planet_osm_point; + ``` + +2. Search for specific locations: + ```sql + SELECT osm_id, name, ST_AsText(ST_Transform(way, 4326)) AS lonlat_location + FROM planet_osm_point + WHERE name ILIKE '%eiffel%' + LIMIT 5; + ``` + +3. Check data extent: + ```sql + SELECT ST_AsText(ST_Envelope(ST_Collect(way))) AS bounding_box + FROM planet_osm_point; + ``` + +Remember to adjust file paths, database name, and user as necessary for your specific setup. ``` +planet=# \d planet_osm_point +                       Table "public.planet_osm_point"        Column       |         Type         | Collation | Nullable | Default