Skip to content

Commit ac4ed65

Browse files
authored
[clickpipes] Add FAQ section for Postgres CDC (#3006)
1 parent a142b5c commit ac4ed65

File tree

5 files changed

+119
-0
lines changed

5 files changed

+119
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
sidebar_label: ClickPipes for Postgres FAQ
3+
description: Frequently asked questions about ClickPipes for Postgres.
4+
slug: /en/integrations/clickpipes/postgres/faq
5+
sidebar_position: 2
6+
---
7+
8+
# ClickPipes for Postgres FAQ
9+
10+
### How does idling affect my Postgres CDC Clickpipe?
11+
12+
If your ClickHouse Cloud service is idling, your Postgres CDC clickpipe will continue to sync data, your service will wake-up at the next sync interval to handle the incoming data. Once the sync is finished and the idle period is reached, your service will go back to idling.
13+
14+
As an example, if your sync interval is set to 30 mins and your service idle time is set to 10 mins, Your service will wake-up every 30 mins and be active for 10 mins, then go back to idling.
15+
16+
17+
### How are TOAST columns handled in ClickPipes for Postgres?
18+
19+
Please refer to the [Handling TOAST Columns](./toast) page for more information.
20+
21+
22+
### How are generated columns handled in ClickPipes for Postgres?
23+
24+
Please refer to the [Postgres Generated Columns: Gotchas and Best Practices](./generated_columns) page for more information.
25+

docs/en/integrations/data-ingestion/clickpipes/postgres/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ Once the connection details are filled in, click on "Next".
134134

135135
Once you've moved data from Postgres to ClickHouse, the next obvious question is how to model your data in ClickHouse to make the most of it. Please refer to this page on [ClickHouse Data Modeling Tips for Postgres users](https://docs.peerdb.io/bestpractices/clickhouse_datamodeling) to help you model data in ClickHouse.
136136

137+
Also, please refer to the [ClickPipes for Postgres FAQ](./postgres/faq) for more information about common issues and how to resolve them.
138+
137139
:::info
138140

139141
[This](https://docs.peerdb.io/bestpractices/clickhouse_datamodeling) is especially important as ClickHouse differs from Postgres, and you might encounter some surprises. This guide helps address potential pitfalls and ensures you can take full advantage of ClickHouse.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
title: "Postgres Generated Columns: Gotchas and Best Practices"
3+
slug: /en/integrations/clickpipes/postgres/generated_columns
4+
---
5+
6+
When using PostgreSQL's generated columns in tables that are being replicated, there are some important considerations to keep in mind. These gotchas can affect the replication process and data consistency in your destination systems.
7+
8+
## The Problem with Generated Columns
9+
10+
1. **Not Published via pgoutput:** Generated columns are not published through the pgoutput logical replication plugin. This means that when you're replicating data from PostgreSQL to another system, the values of generated columns are not included in the replication stream.
11+
12+
2. **Issues with Primary Keys:** If a generated column is part of your primary key, it can cause deduplication problems on the destination. Since the generated column values are not replicated, the destination system won't have the necessary information to properly identify and deduplicate rows.
13+
14+
## Best Practices
15+
16+
To work around these limitations, consider the following best practices:
17+
18+
1. **Recreate Generated Columns on the Destination:** Instead of relying on the replication process to handle generated columns, it's recommended to recreate these columns on the destination using tools like dbt (data build tool) or other data transformation mechanisms.
19+
20+
2. **Avoid Using Generated Columns in Primary Keys:** When designing tables that will be replicated, it's best to avoid including generated columns as part of the primary key.
21+
22+
## Upcoming improvements to UI
23+
24+
In upcoming versions, we are planning to add a UI to help users with the following:
25+
26+
1. **Identify Tables with Generated Columns:** The UI will have a feature to identify tables that contain generated columns. This will help users understand which tables are affected by this issue.
27+
28+
2. **Documentation and Best Practices:** The UI will include best practices for using generated columns in replicated tables, including guidance on how to avoid common pitfalls.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
title: "ClickPipes for Postgres: Handling TOAST Columns"
3+
description: Learn how to handle TOAST columns when replicating data from PostgreSQL to ClickHouse.
4+
slug: /en/integrations/clickpipes/postgres/toast
5+
---
6+
7+
When replicating data from PostgreSQL to ClickHouse, it's important to understand the limitations and special considerations for TOAST (The Oversized-Attribute Storage Technique) columns. This guide will help you identify and properly handle TOAST columns in your replication process.
8+
9+
## What are TOAST columns in PostgreSQL?
10+
11+
TOAST (The Oversized-Attribute Storage Technique) is PostgreSQL's mechanism for handling large field values. When a row exceeds the maximum row size (typically 2KB, but this can vary depending on the PostgreSQL version and exact settings), PostgreSQL automatically moves large field values into a separate TOAST table, storing only a pointer in the main table.
12+
13+
It's important to note that during Change Data Capture (CDC), unchanged TOAST columns are not included in the replication stream. This can lead to incomplete data replication if not handled properly.
14+
15+
During the initial load (snapshot), all column values, including TOAST columns, will be replicated correctly regardless of their size. The limitations described in this guide primarily affect the ongoing CDC process after the initial load.
16+
17+
You can read more about TOAST and its implementation in PostgreSQL here: https://www.postgresql.org/docs/current/storage-toast.html
18+
19+
## Identifying TOAST columns in a table
20+
21+
To identify if a table has TOAST columns, you can use the following SQL query:
22+
23+
```sql
24+
SELECT a.attname, pg_catalog.format_type(a.atttypid, a.atttypmod) as data_type
25+
FROM pg_attribute a
26+
JOIN pg_class c ON a.attrelid = c.oid
27+
WHERE c.relname = 'your_table_name'
28+
AND a.attlen = -1
29+
AND a.attstorage != 'p'
30+
AND a.attnum > 0;
31+
```
32+
33+
This query will return the names and data types of columns that could potentially be TOASTed. However, it's important to note that this query only identifies columns that are eligible for TOAST storage based on their data type and storage attributes. To determine if these columns actually contain TOASTed data, you'll need to consider whether the values in these columns exceed the size. The actual TOASTing of data depends on the specific content stored in these columns.
34+
35+
## Ensuring proper handling of TOAST columns
36+
37+
To ensure that TOAST columns are handled correctly during replication, you should set the `REPLICA IDENTITY` of the table to `FULL`. This tells PostgreSQL to include the full old row in the WAL for UPDATE and DELETE operations, ensuring that all column values (including TOAST columns) are available for replication.
38+
39+
You can set the `REPLICA IDENTITY` to `FULL` using the following SQL command:
40+
41+
```sql
42+
ALTER TABLE your_table_name REPLICA IDENTITY FULL;
43+
```
44+
45+
Refer to [this blog post](https://xata.io/blog/replica-identity-full-performance) for performance considerations when setting `REPLICA IDENTITY FULL`.
46+
47+
## Replication behavior when REPLICA IDENTITY FULL is not set
48+
49+
If `REPLICA IDENTITY FULL` is not set for a table with TOAST columns, you may encounter the following issues when replicating to ClickHouse:
50+
51+
1. For INSERT operations, all columns (including TOAST columns) will be replicated correctly.
52+
53+
2. For UPDATE operations:
54+
- If a TOAST column is not modified, its value will appear as NULL or empty in ClickHouse.
55+
- If a TOAST column is modified, it will be replicated correctly.
56+
57+
3. For DELETE operations, TOAST column values will appear as NULL or empty in ClickHouse.
58+
59+
These behaviors can lead to data inconsistencies between your PostgreSQL source and ClickHouse destination. Therefore, it's crucial to set `REPLICA IDENTITY FULL` for tables with TOAST columns to ensure accurate and complete data replication.
60+
61+
## Conclusion
62+
63+
Properly handling TOAST columns is essential for maintaining data integrity when replicating from PostgreSQL to ClickHouse. By identifying TOAST columns and setting the appropriate `REPLICA IDENTITY`, you can ensure that your data is replicated accurately and completely.

sidebars.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,7 @@ const sidebars = {
603603
collapsible: true,
604604
items: [
605605
"en/integrations/data-ingestion/clickpipes/postgres/index",
606+
"en/integrations/data-ingestion/clickpipes/postgres/faq",
606607
{
607608
type: "category",
608609
label: "Source",

0 commit comments

Comments
 (0)