Skip to content

Writing AIS messages to a Postgres Database

AIS-catcher -D url [setting value] ...

As per full release v0.45, there is functionality to write messages to a database (PostgreSQL). The setup is fairly flexible and can be tailored to the particular needs. First create an empty PostgreSQL database, e.g on an Ubuntu distribution (this might be different on your system):

sudo -u postgres createdb ais
Set up the necessary tables from the AIS-catcher directory:
sudo -u postgres psql ais < create.sql
The file create.sql is in the directory DBMS in the AIS-catcher source directory. If you installed via the install script for Ububtu/Debian/Raspberry Pi it can be found in the directory /etc/AIS-catcher/DBMS.

Make sure you build the latest version of AIS-catcher with this dependency:

sudo apt install libpq-dev

For writing to a PSQL database from AIS-catcher, ensure that the user running the program is set up for writing to a PSQL database or specify the user explicitly in the connection string.

Ensure that the Now AIS-catcher can write the received messages to the database:

AIS-catcher -D dbname=ais STATION_ID 17
or when more details, like username and password, are required:
AIS-catcher -D postgresql://[user[:password]@][netloc][:port][/dbname]
The STATION_ID setting is optional but will populate the entries in the database with the specified ID so multiple feeders can write to one database. There are a few settings for the new -D switch of which the first is the connection string that specifies the database. If you want to use a space in the string use quotation marks around the string. There are other settings that define how tables will be populated:

Table Description Settings Default
ais_vessel last received data per MMSI V on/off on
ais_message received messages with meta data MSGS on/off off
ais_nmea nmea sentences NMEA on/off off
ais_basestation basestation messsages from type 4 BS on/off off
ais_sar_position sar positions from type 9 SAR on/off off
ais_aton aton messages from type 21 ATON on/off off
ais_vessel_pos vessel position messages from type 1-3, 18, 19, 27 VP on/off off
ais_vessel_static vessel static data from type 5, 19 VS on/off off
ais_property specific key/value pairs with link to message fill with keys specified in the table ais_keys empty

From hereon it is fairly straightforward to pick up this data and start analysis. If the connection fails during the decoding, for whatever reason, the program will try to reconnect to the database every 2 seconds. The maximum number of failed connection attempts before the program terminates is set with MAX_FAILS (<1000) and is set on the command line. If MAX_FAILS is 1000 the program will not terminate if the connection fails.

I hope this is sufficient to get you experimenting! Unfortunately, the options cannot yet be set from the JSON configuration file which is work in progress.

Summary Settings

Key Type Default Description
CONN_STR string dbname=ais PostgreSQL connection string
STATION_ID integer 0 Station identifier
INTERVAL integer 10 Database write interval (5-1800 sec)
MAX_FAILS integer 10 Max failed connection attempts
Table Options
V boolean true Enable vessel table logging
MSGS boolean false Enable message table logging
NMEA boolean false Enable NMEA sentence logging
BS boolean false Enable basestation logging
SAR boolean false Enable SAR position logging
ATON boolean false Enable AtoN logging
VP boolean false Enable vessel position logging
VS boolean false Enable vessel static data logging