Skip to main content

Manual Page: osm2pgsql-replication(1)

Version 1.6.0

NAME
SYNOPSIS
DESCRIPTION
OPTIONS
OPTIONS ’osm2pgsql-replication init’
OPTIONS ’osm2pgsql-replication update’
OPTIONS ’osm2pgsql-replication status’


NAME

osm2pgsql-replication - osm2pgsql database updater

SYNOPSIS

osm2pgsql-replication [-h] {init,update,status} ...

DESCRIPTION

Update an osm2pgsql database with changes from a OSM replication server.

This tool initialises the updating process by looking at the import file
or the newest object in the database. The state is then saved in a table
in the database. Subsequent runs download newly available data and apply
it to the database.

See the help of the ’init’ and ’update’ command for more information on
how to use osm2pgsql-replication.

OPTIONS

Sub-commands
osm2pgsql-replication
init

Initialise the replication process.

osm2pgsql-replication update

Download newly available data and apply it to the database.

osm2pgsql-replication status

Print information about the current replication status, optionally as JSON.

OPTIONS ’osm2pgsql-replication init’

usage: osm2pgsql-replication init [-h] [-q] [-v] [-d DB] [-U NAME] [-H HOST]
[-P PORT] [-p PREFIX]
[--osm-file FILE | --server URL]

Initialise the replication process.

There are two ways to initialise the replication process: if you have imported
from a file that contains replication source information, then the
initialisation process can use this and set up replication from there.
Use the command ’%(prog)s --osm-file <filename>’ for this.

If the file has no replication information or you don’t have the initial
import file anymore then replication can be set up according to
the data found in the database. It checks the planet_osm_way table for the
newest way in the database and then queries the OSM API when the way was
created. The date is used as the start date for replication. In this mode
the minutely diffs from the OSM servers are used as a source. You can change
this with the ’--server’ parameter.
-q
, --quiet

Print only error messages

-v, --verbose

Increase verboseness of output

-d DB, --database DB

Name of PostgreSQL database to connect to or conninfo string

-U NAME, --username NAME

PostgreSQL user name

-H HOST, --host HOST

Database server host name or socket location

-P PORT, --port PORT

Database server port

-p PREFIX, --prefix PREFIX

Prefix for table names (default ’planet_osm’)

--osm-file FILE

Get replication information from the given file.

--server URL

Use replication server at the given URL (default: https://planet.openstreetmap.org/replication/minute)

OPTIONS ’osm2pgsql-replication update’

usage: osm2pgsql-replication update update [options] [-- param [param ...]]

Download newly available data and apply it to the database.

The data is downloaded in chunks of ’--max-diff-size’ MB. Each chunk is
saved in a temporary file and imported with osm2pgsql from there. The
temporary file is normally deleted afterwards unless you state an explicit
location with ’--diff-file’. Once the database is up to date with the
replication source, the update process exits with 0.

Any additional arguments to osm2pgsql need to be given after ’--’. Database
and the prefix parameter are handed through to osm2pgsql. They do not need
to be repeated. ’--append’ and ’--slim’ will always be added as well.

Use the ’--post-processing’ parameter to execute a script after osm2pgsql has
run successfully. If the updates consists of multiple runs because the
maximum size of downloaded data was reached, then the script is executed
each time that osm2pgsql has run. When the post-processing fails, then
the entire update run is considered a failure and the replication information
is not updated. That means that when ’update’ is run the next time it will
recommence with downloading the diffs again and reapplying them to the
database. This is usually safe. The script receives two parameters:
the sequence ID and timestamp of the last successful run. The timestamp
may be missing in the rare case that the replication service stops responding
after the updates have been downloaded.

param

Extra parameters to hand in to osm2pgsql.

--diff-file FILE

File to save changes before they are applied to osm2pgsql.

--max-diff-size MAX_DIFF_SIZE

Maximum data to load in MB (default: 500MB)

--osm2pgsql-cmd OSM2PGSQL_CMD

Path to osm2pgsql command (default: osm2pgsql)

--once

Run updates only once, even when more data is available.

--post-processing SCRIPT

Post-processing script to run after each execution of osm2pgsql.

-q, --quiet

Print only error messages

-v, --verbose

Increase verboseness of output

-d DB, --database DB

Name of PostgreSQL database to connect to or conninfo string

-U NAME, --username NAME

PostgreSQL user name

-H HOST, --host HOST

Database server host name or socket location

-P PORT, --port PORT

Database server port

-p PREFIX, --prefix PREFIX

Prefix for table names (default ’planet_osm’)

OPTIONS ’osm2pgsql-replication status’

usage: osm2pgsql-replication status [-h] [-q] [-v] [-d DB] [-U NAME] [-H HOST]
[-P PORT] [-p PREFIX] [--json]

Print information about the current replication status, optionally as JSON.

Sample output:

2021-08-17 15:20:28 [INFO]: Using replication service ’https://planet.openstreetmap.org/replication/minute’, which is at sequence 4675115 ( 2021-08-17T13:19:43Z )
2021-08-17 15:20:28 [INFO]: Replication server’s most recent data is <1 minute old
2021-08-17 15:20:28 [INFO]: Local database is 8288 sequences behind the server, i.e. 5 day(s) 20 hour(s) 58 minute(s)
2021-08-17 15:20:28 [INFO]: Local database’s most recent data is 5 day(s) 20 hour(s) 59 minute(s) old

With the ’--json’ option, the status is printed as a json object.

{
"server": {
"base_url": "https://planet.openstreetmap.org/replication/minute",
"sequence": 4675116,
"timestamp": "2021-08-17T13:20:43Z",
"age_sec": 27
},
"local": {
"sequence": 4666827,
"timestamp": "2021-08-11T16:21:09Z",
"age_sec": 507601
},
"status": 0
}

’status’ is 0 if there were no problems getting the status. 1 & 2 for
improperly set up replication. 3 for network issues. If status â  0, then
the ’error’ key is an error message (as string). ’status’ is used as the
exit code.

’server’ is the replication server’s current status. ’sequence’ is it’s
sequence number, ’timestamp’ the time of that, and ’age_sec’ the age of the
data in seconds.

’local’ is the status of your server.

--json

Output status as json.

-q, --quiet

Print only error messages

-v, --verbose

Increase verboseness of output

-d DB, --database DB

Name of PostgreSQL database to connect to or conninfo string

-U NAME, --username NAME

PostgreSQL user name

-H HOST, --host HOST

Database server host name or socket location

-P PORT, --port PORT

Database server port

-p PREFIX, --prefix PREFIX

Prefix for table names (default ’planet_osm’)