How to insert data from PostgreSQL
We recommend reading this guide to learn best practices on inserting data to ClickHouse to optimize for insert performance.
For bulk loading data from PostgreSQL, users can use:
- using
PeerDB by ClickHouse
, an ETL tool specifically designed for PostgreSQL database replication to both self-hosted ClickHouse and ClickHouse Cloud. To get started, create an account on PeerDB Cloud and refer to the documentation for setup instructions. - The Postgres table function to read data directly. This is typically appropriate if batch replication based on a known watermark, e.g., timestamp, is sufficient or if it's a one-off migration. This approach can scale to tens of millions of rows. Users looking to migrate larger datasets should consider multiple requests, each dealing with a chunk of the data. Staging tables can be used for each chunk prior to its partitions being moved to a final table. This allows failed requests to be retried. For further details on this bulk-loading strategy, see here.
- Data can be exported from Postgres in CSV format. This can then be inserted into ClickHouse from either local files or via object storage using table functions.