-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to update with osm2pgsql-replication? #211
Comments
Hi @MTRNord - It is good to see interest in the update process! Data updates do not work quite yet, but I have been looking at how to support that functionality. There is a discussion open (#167) related to this. A roadblock was recently removed with #182 but that was only part of the issue as you have found. I have not used My plan is to work through each of the post-processing SQL scripts and create a process to drop and recreate the necessary objects. For an immediate hack, if you are so motivated, here's what I think is involved but proceed with caution! You can drop the offending FK and see if that's all it needs for the refresh to work. I have not tested that yet, but see that's the only FK added. You may need to drop and/or recreate the PKs and indexes as well. I don't know enough about what osm2pgsql does under the hood for updates to know if those will cause problems or be auto-dropped somehow. You would also need to refresh the two materialized views ( If you happen to hack away on this, feel free to submit a PR to the |
Hi :) Yes I am very interested. I would love to use this to layer this, combined with the routing doc example, and gtfs and some other transportation data to get some postgres and rust based way to do efficient routing without having to do full graph rebuilds like using OpenTripPlanner which is very expensive to do. The script I am referencing is this one https://github.com/openstreetmap/osm2pgsql/blob/master/scripts/osm2pgsql-replication If i find some time I may try that but I am guessing I wont get to it currently. :) |
Initial test shows the FK on osm2pgsql --slim --output=flex --style=./run.lua -d $PGOSM_CONN ~/pgosm-data/district-of-columbia-2021-11-12.osm.pbf
lua ./run-sql.lua Dropping the constraint mentioned in the error ( TRUNCATE TABLE osm.place_polygon_nested; I created the
Truncated output.
Refresh materialized views and populate data back into REFRESH MATERIALIZED VIEW osm.vplace_polygon;
REFRESH MATERIALIZED VIEW osm.vplace_polygon_subdivide;
REFRESH MATERIALIZED VIEW osm.vpoi_all;
INSERT INTO osm.place_polygon_nested (osm_id, name, osm_type, admin_level, geom)
SELECT p.osm_id, p.name, p.osm_type,
COALESCE(p.admin_level::INT, 99) AS admin_level,
geom
FROM osm.vplace_polygon p
WHERE (p.boundary = 'administrative'
OR p.osm_type IN ('neighborhood', 'city', 'suburb', 'town', 'admin_level', 'locality')
)
AND p.name IS NOT NULL
;
Then optionally running the function to populate the nested data. CALL osm.build_nested_admin_polygons(); In a nutshell, this manual approach seems to work OK. Will need documentation for this manual process, then work out how to build into the Docker process. Resolving #194 will make this functionality in Docker far more attractive. |
Experimental support for using osm2pgsql-replication is in place for both Manual and Docker modes. Feedback welcome, I'm certain there are rough edges still. Further details (enhancements, bugs, etc) should open new tickets to address. Manual mode has procedures for where the process differs: https://github.com/rustprooflabs/pgosm-flex/blob/main/docs/APPEND-MODE.md Docker mode has a section on using Version 0.4.6. will be tagged and released soon. |
Hi - I've been experimenting with this recent feature, the append process you describe doesn't appear to work when using an external PG connection. Im running: DO $do$ BEGIN
IF EXISTS (SELECT FROM pg_catalog.pg_roles WHERE rolname = 'pgosm_flex') THEN
RAISE NOTICE 'Role pgosm_flex already exists. Skipping.'; ELSE
CREATE ROLE pgosm_flex LOGIN PASSWORD 'password';
END IF;
END $do$;
CREATE SCHEMA IF NOT EXISTS osm AUTHORIZATION pgosm_flex;
GRANT CREATE ON DATABASE database TO pgosm_flex; If I run without adding the below function to postgres I get an error that its missing, so: CREATE OR REPLACE PROCEDURE osm.append_data_start()
LANGUAGE plpgsql
AS $$
BEGIN
RAISE NOTICE 'Truncating table osm.place_polygon_nested;';
END $$;
CREATE OR REPLACE PROCEDURE osm.append_data_finish(skip_nested BOOLEAN = False)
LANGUAGE plpgsql
AS $$
BEGIN
REFRESH MATERIALIZED VIEW osm.vplace_polygon;
REFRESH MATERIALIZED VIEW osm.vplace_polygon_subdivide;
REFRESH MATERIALIZED VIEW osm.vpoi_all;
IF $1 = False THEN
RAISE NOTICE 'Populating nested place table';
CALL osm.populate_place_polygon_nested();
RAISE NOTICE 'Calculating nesting of place polygons';
CALL osm.build_nested_admin_polygons();
END IF;
END $$; then:
create container
then start data import
The above command produces the following error:
If I leave out the
I get:
Any suggestions? |
@newtracs Please open a new issue to report this as a bug. Make sure to include version number of PgOSM Flex used along with all other steps to reproduce. Thanks! |
Hi I set up the database using https://github.com/rustprooflabs/pgosm-flex/blob/main/docs/MANUAL-STEPS-RUN.md and wanted to run the update of data using the replication approach using the command:
osm2pgsql-replication update -d pgosm -U osmuser -- -O flex -S ./run.lua
.However doing that I get
ERROR: DB copy thread failed: Database error: ERROR: update or delete on table "place_polygon" violates foreign key constraint "fk_place_polygon_nested" on table "place_polygon_nested"
. So I wonder what is the correct way of updating the data regularly?The text was updated successfully, but these errors were encountered: