The Simplest Way to Make Cloud SQL and Elasticsearch Work Like They Should
Teams pair cloud sql and elasticsearch to keep transactions safe while running fast text searches. Your primary relational database stores core records, and a sync worker copies updates into search indexes. This setup splits heavy search queries away from your core transactional tables. Your web app writes data to the relational database first. Then a change capture job reads new rows and sends documents to the search cluster. Users get fast search results without putting extra load on your mai
Your coding agents run with your access.
Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.
Teams pair cloud sql and elasticsearch to keep transactions safe while running fast text searches. Your primary relational database stores core records, and a sync worker copies updates into search indexes.
This setup splits heavy search queries away from your core transactional tables. Your web app writes data to the relational database first. Then a change capture job reads new rows and sends documents to the search cluster. Users get fast search results without putting extra load on your main database.
How data and roles flow between cloud sql and elasticsearch
Moving data between cloud sql and elasticsearch starts with the right database roles. Cloud SQL for PostgreSQL is a managed service, so customers cannot create true superuser accounts. A system user named cloudsqladmin holds full superuser rights on the instance. Customers cannot change or delete these built-in system roles.
Instead, admins use the default postgres user or assign the cloudsqlsuperuser role. You must set a password for the default postgres user before you log in. It belongs to cloudsqlsuperuser and holds role creation, database creation, and login rights. Still, this default account does not start with replication or true superuser attributes.
To stream changes out of your tables, an admin with cloudsqlsuperuser rights creates a replication user. That role also lets you create replication publications, subscriptions, and required extensions. Your sync worker logs into the database with this dedicated replication user. It reads row changes and writes matching JSON documents into your search index using an API key.
Common failure modes in sync pipelines
Many teams take shortcuts when they first wire up their data pipeline. They often run the sync worker with the default postgres admin account. If an attacker steals those credentials, they can drop tables or create new roles. You should always create a separate user that only reads the tables needed for search.
Overly broad search keys cause another major risk in production. If the sync worker uses a cluster admin key, a bug could wipe out every index. Scope the search API key so it only writes to specific target indexes. Give your web app a separate key that only reads from those indexes.
Elasticsearch Security + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Shared accounts also ruin your audit trail during debugging or security reviews. Engineers often use the pipeline's database account or search key to run manual fixes. When five people share one login, your logs cannot show who ran a bad query. Every engineer and background job needs a distinct identity with narrow permissions.
Scoping network paths and sensitive fields
Network rules between your database, sync worker, and search cluster must stay tight. Keep all three systems on private networks rather than exposing public IP addresses. Set firewall rules so only the sync worker host can open replication sessions to the database. Allow only the sync worker and your app servers to reach the search cluster port.
You should also watch which columns travel from your tables into search documents. Search indexes rarely need sensitive fields like emails, phone numbers, card numbers, or national IDs. Leave those columns out of your replication publication whenever you can. When engineers query either datastore directly, data masking can rewrite matched fields in results.
Govern statements and responses across databases and APIs
Good config and scoped roles are needed setup. They do not check single queries in flight or mask sensitive fields in returned rows. Across Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, and internal HTTP endpoints, hoop.dev runs beside each supported service as an open-source proxy, a sidecar for your database or API.
First, hoop.dev guardrails block banned queries before they run. Then hoop.dev data masking rewrites matched sensitive values in responses in memory. The audit trail records every statement and verdict per resource. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.
Frequently asked questions
Can I use a true PostgreSQL superuser to set up replication in Cloud SQL?
No, customers cannot create or use accounts with true superuser attributes in this managed service. You use the cloudsqlsuperuser role instead, which lets you create replication users and publications.
Does the default postgres user in Cloud SQL have replication rights by default?
No, the default postgres user starts with role creation, database creation, and login rights. It belongs to cloudsqlsuperuser, so it can create a dedicated replication user for your sync pipeline.
How should I separate permissions for the sync worker and my web app?
Give the sync worker a database replication role and a write-only search key for specific indexes. Give your web app a standard database role for transactions and a read-only search key.
Short role checks help teams work fast. Simple rules make each review clear. Good logs keep every team safe. Scoped keys stop bad changes early.
Related guides
In this post