PlanetScale for Postgres source setup guide
PlanetScale for Postgres is currently in early access.
Supported Postgres versions
ClickPipes supports Postgres version 12 and later.
Enable logical replication
-
To enable replication on your Postgres instance, we need to make sure that the following settings are set:
To check the same, you can run the following SQL command:
The output should be
logicalby default. If not, please log into the PlanetScale console and go toCluster configuration->Parametersand scroll down toWrite-ahead logto change it.
Changing this in the PlanetScale console WILL trigger a restart.
- Additionally, it is recommended to increase the setting
max_slot_wal_keep_sizefrom its default of 4GB. This is also done via the PlanetScale console by going toCluster configuration->Parametersand then scroll down toWrite-ahead log. To help determine the new value, please take a look here.
Creating a user with permissions and publication
Connect to your PlanetScale Postgres instance using the default postgres.<...> user and run the following commands:
-
Create a dedicated user for ClickPipes:
-
Grant schema-level, read-only access to the user you created in the previous step. The following example shows permissions for the
publicschema. Repeat these commands for each schema containing tables you want to replicate: -
Grant replication privileges to the user:
-
Create a publication with the tables you want to replicate. We strongly recommend only including the tables you need in the publication to avoid performance overhead.
NoteAny table included in the publication must either have a primary key defined or have its replica identity configured to
FULL. See the Postgres FAQs for guidance on scoping.-
To create a publication for specific tables:
-
To create a publication for all tables in a specific schema:
The
clickpipespublication will contain the set of change events generated from the specified tables, and will later be used to ingest the replication stream. -
Caveats
- To connect to PlanetScale Postgres, the current branch needs to be appended to the username created above. For example, if the created user was named
clickpipes_user, the actual user provided during the ClickPipe creation needs to beclickpipes_user.branchwherebranchrefers to the "id" of the current PlanetScale Postgres branch. To quickly determine this, you can refer to the username of thepostgresuser you used to create the user earlier, the part after the period would be the branch id. - Do not use the
PSBouncerport (currently6432) for CDC pipes connecting to PlanetScale Postgres, the normal port5432must be used. Either port may be used for initial-load only pipes. - Please ensure you're connecting only to the primary instance, connecting to replica instances is currently not supported.
What's next?
You can now create your ClickPipe and start ingesting data from your Postgres instance into ClickHouse Cloud. Make sure to note down the connection details you used while setting up your Postgres instance as you will need them during the ClickPipe creation process.