|
| 1 | +# PostgreSQL Sink |
| 2 | + |
| 3 | +The PostgreSQL sink writes parsed records into PostgreSQL tables. It builds `INSERT IGNORE` statements from `columns`, which is suitable for idempotent retry scenarios. It only accepts Record data (raw input is not supported). |
| 4 | + |
| 5 | +## Connector Definition |
| 6 | + |
| 7 | +Use the built-in template (located at `connectors/sink.d/50-mysql.toml`; PostgreSQL uses the same configuration set as MySQL): |
| 8 | + |
| 9 | +```toml |
| 10 | +[[connectors]] |
| 11 | +id = "postgresql_sink" |
| 12 | +type = "postgresql" |
| 13 | +allow_override = ["endpoint", "username", "password", "database", "table", "columns", "batch_size"] |
| 14 | + |
| 15 | +[connectors.params] |
| 16 | +endpoint = "localhost:5432" |
| 17 | +username = "postgres" |
| 18 | +password = "123456" |
| 19 | +database = "wparse" |
| 20 | +table = "nginx_logs" |
| 21 | +columns = ["sip", "timestamp", "http/request", "status", "size", "referer", "http/agent", "wp_event_id"] |
| 22 | +batch_size = 1024 |
| 23 | +``` |
| 24 | + |
| 25 | +## Parameters |
| 26 | + |
| 27 | +| Parameter | Type | Description | |
| 28 | +|------|------|------| |
| 29 | +| `endpoint` | string | PostgreSQL endpoint (`host:port`, required) | |
| 30 | +| `username` | string | Username (optional, default `postgres`) | |
| 31 | +| `password` | string | Password (optional) | |
| 32 | +| `database` | string | Target database (required) | |
| 33 | +| `table` | string | Target table name (required) | |
| 34 | +| `columns` | array | Column list that defines write order (required) | |
| 35 | +| `batch_size` | int | Batch insert size (optional) | |
| 36 | + |
| 37 | +## Configuration Example |
| 38 | + |
| 39 | +### Basic Usage |
| 40 | + |
| 41 | +```toml |
| 42 | +version = "2.0" |
| 43 | + |
| 44 | +[sink_group] |
| 45 | +name = "all" |
| 46 | +oml = ["/*"] |
| 47 | +batch_timeout_ms=5000 # Auto flush when batch size is not reached within this time window |
| 48 | +parallel = 8 |
| 49 | + |
| 50 | +[[sink_group.sinks]] |
| 51 | +name = "main" |
| 52 | +connect = "postgresql_sink" |
| 53 | + |
| 54 | +[sink_group.sinks.params] |
| 55 | +endpoint = "localhost:5432" |
| 56 | +username = "postgres" |
| 57 | +password = "123456" |
| 58 | +database = "wparse" |
| 59 | +table = "nginx_logs" |
| 60 | +columns = ["sip", "timestamp", "http/request", "status", "size", "referer", "http/agent", "wp_event_id"] |
| 61 | +batch_size = 1024 |
| 62 | +``` |
| 63 | + |
| 64 | +## Notes |
| 65 | + |
| 66 | +- Field names in `columns` must match OML output fields. Missing table columns are written as `NULL`. |
| 67 | +- You can override the connection string with `POSTGRESQL_URL` (format: `postgresql://user:pass@host:port/db`). |
| 68 | +- PostgreSQL uses the same configuration keys as MySQL. Only connector `type`, port, and connection details differ. |
0 commit comments