ClickHouse/docs/en/engines/table-engines/integrations/materialized-postgresql.md

47 lines
1.5 KiB
Markdown
Raw Normal View History

2021-04-11 20:26:59 +00:00
---
toc_priority: 12
toc_title: MaterializedPostgreSQL
2021-04-11 20:26:59 +00:00
---
2021-06-27 19:09:17 +00:00
# MaterializedPostgreSQL {#materialize-postgresql}
2021-04-11 20:26:59 +00:00
## Creating a Table {#creating-a-table}
2021-05-04 10:43:21 +00:00
``` sql
2021-05-13 07:36:40 +00:00
CREATE TABLE test.postgresql_replica (key UInt64, value UInt64)
2021-06-27 19:09:17 +00:00
ENGINE = MaterializedPostgreSQL('postgres1:5432', 'postgres_database', 'postgresql_replica', 'postgres_user', 'postgres_password')
2021-05-04 10:43:21 +00:00
PRIMARY KEY key;
```
2021-04-11 20:26:59 +00:00
## Requirements {#requirements}
2021-05-04 10:43:21 +00:00
- Setting `wal_level`to `logical` and `max_replication_slots` to at least `2` in the postgresql config file.
2021-07-01 17:52:21 +00:00
- A table with engine `MaterializedPostgreSQL` must have a primary key - the same as a replica identity index (default: primary key) of a postgres table (See [details on replica identity index](../../database-engines/materialized-postgresql.md#requirements)).
2021-04-11 20:26:59 +00:00
- Only database `Atomic` is allowed.
2021-05-04 10:43:21 +00:00
## Virtual columns {#creating-a-table}
2021-05-13 07:36:40 +00:00
- `_version` (`UInt64`)
2021-05-04 10:43:21 +00:00
2021-05-13 07:36:40 +00:00
- `_sign` (`Int8`)
These columns do not need to be added, when table is created. They are always accessible in `SELECT` query.
`_version` column equals `LSN` position in `WAL`, so it might be used to check how up-to-date replication is.
2021-05-04 10:43:21 +00:00
``` sql
2021-05-13 07:36:40 +00:00
CREATE TABLE test.postgresql_replica (key UInt64, value UInt64)
2021-06-27 19:09:17 +00:00
ENGINE = MaterializedPostgreSQL('postgres1:5432', 'postgres_database', 'postgresql_replica', 'postgres_user', 'postgres_password')
2021-05-04 10:43:21 +00:00
PRIMARY KEY key;
2021-05-13 07:36:40 +00:00
SELECT key, value, _version FROM test.postgresql_replica;
2021-05-04 10:43:21 +00:00
```
2021-06-27 19:09:17 +00:00
2021-07-01 08:20:13 +00:00
## Warning {#warning}
2021-06-27 19:09:17 +00:00
2021-07-01 08:20:13 +00:00
1. **TOAST** values convertion is not supported. Default value for the data type will be used.