Postgres migrationClickHouse Workshops

00 Setup

Prepare accounts, tools, credentials, and Terraform variables before provisioning.

Your computer
macOS terminal: Run workshop commands in Terminal using zsh or bash.

Choose macOS or Windows in the page header. Windows commands run inside Ubuntu on WSL 2, not PowerShell, unless the page explicitly says PowerShell.

Outcome

Prepare your AWS and ClickHouse Cloud accounts and install the workshop tools. Allow 30 to 45 minutes. This module ends with terraform validate; module 01 provisions the RDS instance.

Step 1 — Accounts and region

You need two accounts:

  • An AWS account in which you may create a DB instance, a DB parameter group, a DB subnet group and a security group. That is a broader permission set than a read-only or developer-sandbox role usually carries, which is what Step 6 checks.

  • A ClickHouse Cloud organization at clickhouse.cloud, and the ability to create an API key in it whose role may create services. Check your trial credits and billing terms before creating services and ClickPipes.

    Module 03 creates the Managed Postgres instance, and module 07 deletes it. Request an API key with service creation and deletion permissions before the session.

Put everything in one region. Use us-east-2 unless your trainer names another: ClickHouse Managed Postgres is in beta and its region list is narrower than RDS's, and a cross-region pair adds wide-area latency to every replication-lag number you measure in module 03. The RDS instance, the Managed Postgres instance and the ClickHouse service all go in the region you pick here.

Step 2 — Install the toolchain

Install Homebrew first if you do not have it, then:

brew tap hashicorp/tap
brew install hashicorp/tap/terraform
brew install libpq awscli python@3.12

Install Docker Desktop for Mac and start it. Docker only runs Grafana in this workshop; nothing else depends on it.

libpq is keg-only, so Homebrew does not link psql and pg_dump onto your PATH. Export it for this shell and for future ones:

export PATH="$(brew --prefix libpq)/bin:$PATH"
echo "export PATH=\"$(brew --prefix libpq)/bin:\$PATH\"" >> ~/.zprofile

An older Homebrew Postgres on PATH will break module 03

If you already have a versioned server formula installed, its client binaries can win the PATH race and give you a pg_dump older than the RDS server. A schema-only dump from a newer server with an older pg_dump does not degrade; it aborts. Check what you have and unlink it:

brew list --formula | grep '^postgresql@' || echo "no versioned postgresql formula installed"
brew unlink postgresql@14 2>/dev/null || true

Then confirm pg_dump --version reports 17 or newer in Step 4.

Install clickhousectl to create and delete the Managed Postgres instance:

curl https://clickhouse.com/cli | sh
export PATH="$HOME/.local/bin:$PATH"
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zprofile

Step 3 — Clone the workshop repository

cd ~
git clone https://github.com/ClickHouse/ClickHouse_Demos.git
cd ClickHouse_Demos
cd "$(git rev-parse --show-toplevel)/workshops/postgres_migration"
pwd

Every later module starts from this directory, and reaches it the same way: cd "$(git rev-parse --show-toplevel)/workshops/postgres_migration".

Step 4 — Verify the toolchain

Run all of these in the shell you will use for the rest of the workshop. On Windows that is the Ubuntu terminal.

terraform version
psql --version
pg_dump --version
docker version
docker compose version
python3 --version
aws --version
clickhousectl --version

What each line must show:

CommandRequired
terraform version1.6.0 or newer
psql --version17 or newer
pg_dump --version17 or newer, and never older than the server
docker versionboth a Client and a Server section
python3 --version3.11 or newer
aws --versionaws-cli/2.x
clickhousectl --versionany; module 03 creates the target instance with it

Check pg_dump separately from psql. For a version mismatch, follow Postgres client recovery.

Step 5 — Authenticate clickhousectl

Authenticate the CLI before module 03.

Create an API key in the ClickHouse Cloud console under your organization's API keys, with a role that may create services, then log in. The interactive form keeps the secret out of your shell history:

clickhousectl cloud auth login --interactive

Verify authentication and organization access. These checks do not prove that the key can create or delete services:

clickhousectl cloud auth status
clickhousectl cloud org list

clickhousectl writes project credentials to .clickhouse/ in the current directory, so run Cloud commands from the workshop directory and never commit that folder. The repository's .gitignore already excludes it; check before you push if you have added your own.

Step 6 — Prove your AWS permissions

Configure your AWS profile and check access to RDS and EC2. You also need permission to create the resources listed in Step 1. The read-only checks below do not verify those write permissions.

aws configure
aws configure get region
aws sts get-caller-identity
aws rds describe-db-parameter-groups --max-items 1 > /dev/null && echo "rds: ok"
aws ec2 describe-security-groups --max-items 1 > /dev/null && echo "ec2: ok"

Answer Default region name with the region from Step 1. The aws CLI does not read terraform.tfvars, so it needs its own copy.

Expected: us-east-2 from aws configure get region, your account and role from get-caller-identity, then rds: ok and ec2: ok.

Stop here if either probe prints AccessDenied or UnauthorizedOperation. Get the permissions before module 01 rather than debugging a partial apply; the escalation path and the exact actions to ask for are in Troubleshooting.

Step 7 — Fill in the Terraform variables

Every variable in terraform/variables.tf has a default except one. subscriber_cidrs has no default on purpose: it is the allowlist for port 5432, and a default would either be wrong or be 0.0.0.0/0.

cd "$(git rev-parse --show-toplevel)/workshops/postgres_migration/terraform"
printf 'region           = "us-east-2"\nsubscriber_cidrs = ["%s/32"]\n' \
  "$(curl -fsS https://checkip.amazonaws.com)" > terraform.tfvars
cat terraform.tfvars
terraform init
terraform validate

Expected: Terraform has been successfully initialized and Success! The configuration is valid. Do not run terraform apply yet.

terraform.tfvars is participant-specific and stays local. Never commit it, and never commit a terraform.tfstate file: the state contains the generated admin password.

Module 03 adds the ClickPipes egress addresses to subscriber_cidrs. Both your address and the pipe's addresses need access to RDS on port 5432.

Step 8 — What the Terraform encodes, and why

Read terraform/main.tf before you apply it in module 01. Three things in it are the RDS prerequisites for logical replication, and they are required together:

  1. rds.logical_replication = 1 in a custom DB parameter group, plus an instance reboot. It is a static parameter, so the parameter group carries apply_method = "pending-reboot" and the value does nothing until the instance restarts. That reboot is the workshop's first piece of planned downtime, and module 01 verifies it with SHOW wal_level returning logical.
  2. backup_retention_period >= 1. RDS only gives an instance long-term WAL retention when automated backups are on. The Terraform sets 1, the cheapest value that satisfies it.
  3. The rds_replication role, granted to the replication user. The admin user has rds_superuser, which is what lets it make the grant, but not rds_replication itself. sql/01_schema.sql performs the grant.

Check all three requirements before seeding the database. For recovery steps, see Replication troubleshooting.

Costs and cleanup

This workshop creates billable resources in your AWS account and ClickHouse Cloud organization. Costs depend on region, runtime, storage, data transfer, and your account's credits.

Check Amazon RDS pricing and ClickHouse Cloud pricing before provisioning. Do not assume a trial covers every resource.

Complete module 07 teardown, even if you stop the workshop early. Delete both ClickPipes before their source instances, and verify that their replication slots are removed.

Completion checks

  • terraform version, psql --version, pg_dump --version, docker version, python3 --version, aws --version and clickhousectl --version all meet the table in Step 4;
  • pg_dump --version reports 17 or newer;
  • clickhousectl cloud auth status shows saved credentials and clickhousectl cloud org list names your organization;
  • aws sts get-caller-identity names your account, and both permission probes print ok;
  • terraform validate reports the configuration is valid, with terraform.tfvars holding your region and your own address in subscriber_cidrs; and
  • On Windows, wsl --list --verbose shows Ubuntu at VERSION 2 and pwd in the checkout begins with /home/.

Next: module 01 provisions RDS, verifies logical replication, seeds the database, and records your baseline.

Di halaman ini

Track your progress?

Optional. We email a link to confirm your address; progress records once you open it.

Please use your work email address, not a personal one.

By continuing you accept the Terms.

ID