Google Cloud Platform (GCP)
GCP is a cloud infrastructure platform.
Electric and GCP
You can use GCP to deploy any or all components of the Electric stack:
If you already run Postgres in GCP, then it's a great idea to also deploy Electric within the same network.
Need context?
See the Deployment guide for more details.
Deploy Postgres
GCP provides Postgres hosting via Cloud SQL or AlloyDB. Electric works with either. You need to configure them to enable logical replication and connect with the right user.
Cloud SQL
The default wal_level
is replica
. Change it to logical
by setting the cloudsql.logical_decoding
flag to on
.
Customise your instance on setup
You can set flags in the "Flags" panel of the "Customise your instance" section of the create database page in the console, when setting up your database.
Be careful to connect using the "Outgoing IP address", not the "Public IP address". You will also need to create a new database user with REPLICATION
. Log in using the default postgres
user and then run something like this, changing the username and database name as necessary:
CREATE ROLE electric WITH REPLICATION LOGIN PASSWORD '...';
GRANT ALL PRIVILEGES ON DATABASE "postgres" to electric;
You can then connect to Postgres from Electric as that user, which you can verify using e.g.:
docker run -it -e DATABASE_URL=postgresql://electric:YOUR_PASSWORD@YOUR_OUTGOING_IP/postgres electricsql/electric:latest
AlloyDB
For AlloyDB, the flag to enable logical replication is called alloydb.logical_decoding
.
Deploy Electric
GCP provides a wide range of container hosting. We recommend using Containers on Compute Engine or Google Kubernetes Engine (GKE).
For example, you can deploy Electric on a Container-Optimized OS with a Persistent Disk for storing Shape logs.
Don't use Cloud Run
We don't recommend that you use Cloud Run to deploy the Electric sync service because Cloud Run uses an in-memory filesystem and does not provide persistent file storage for Shape logs.
IPv6 support
If you're connecting to Postgres over IPv6, (for example, if you're connecting to Supabase Postgres) then you may need to enable IPv6 support and be on a Premium Network Tier.
Deploy your app
GCP provides a range of website hosting options. For example you can deploy a static app to Google Storage with Cloud Build.