PostgreSQL
Writes events to a PostgreSQL table. This is a reasonable choice if you already run PostgreSQL and your event volume is moderate. For high volume analytics it's recommended you use ClickHouse instead.
| Requires a postgresql datastore to supply the connection. |
Table Setup
Tilegroxy never issues DDL so you must create the table yourself before starting tilegroxy. This keeps the credentials tilegroxy uses free of schema privileges.
The following matches the default column names:
CREATE TABLE tilegroxy_analytics (
time TIMESTAMPTZ NOT NULL,
layer TEXT NOT NULL,
z INTEGER NOT NULL,
x INTEGER NOT NULL,
y INTEGER NOT NULL,
user_id TEXT,
extra JSONB
);
CREATE INDEX ON tilegroxy_analytics (layer, time);
The extra column receives everything selected via fields and extraFields as a JSON object. JSONB is used instead of dedicated columns so that changing which fields you collect doesn’t require a schema migration.
Tilegroxy does not expire events so this table grows unbounded. It is recommended you partition it by time and drop old partitions on a schedule.
Also accepts the batching parameters shared by every analytics module.
Example
-
YAML
-
JSON
datastores:
- name: postgresql
id: pg-analytics
host: localhost
user: tilegroxy
password: env.PGPASSWORD
database: analytics
analytics:
name: postgresql
datastore: pg-analytics
table: tilegroxy_analytics
fields:
- duration
- contenttype
extraFields:
environment: production
{
"datastores": [
{
"name": "postgresql",
"id": "pg-analytics",
"host": "localhost",
"user": "tilegroxy",
"password": "env.PGPASSWORD",
"database": "analytics"
}
],
"analytics": {
"name": "postgresql",
"datastore": "pg-analytics",
"table": "tilegroxy_analytics",
"fields": [
"duration",
"contenttype"
],
"extraFields": {
"environment": "production"
}
}
}
Configuration
| Parameter | Description | Type | Required | Default |
|---|---|---|---|---|
|
The ID of the datastore to use. The datastore must have a type of |
string |
Yes |
None |
|
The table to insert events into. May be schema qualified. Must be a plain identifier |
string |
Yes |
None |
|
An identifier for this destination, used in logs to attribute analytics messages |
string |
No |
postgresql |
|
Overrides for the default column names. Keys are the logical field names: time, layer, z, x, y, user_id, extra |
map[string]string |
No |
None |
|
Additional attributes to record. See Analytics |
string[] |
No |
None |
|
Arbitrary additional attributes. See Analytics |
map[string]string |
No |
None |