← Back to list

Migrating to Postgres? Don’t Leave Your Cell-Level Encryption Behind

When planning a database migration to PostgreSQL, most teams focus heavily on schema conversions, query tuning, and minimizing application…

Assaf Fraenkel in Google Cloud - Community · 2026-05-29 04:32 · 0 claps · 6.2 min read
#postgresql #database-security #database-migration #google-cloud-platform #data
Open on Medium ↗
Wiki topics: 🔒 · Cybersecurity ⏱️ · Productivity

Migrating to Postgres? Don’t Leave Your Cell-Level Encryption Behind

When planning a database migration to PostgreSQL, most teams focus heavily on schema conversions, query tuning, and minimizing application downtime. However, if you are moving workloads from legacy engines like SQL Server or Oracle, a massive architectural trap awaits: how you protect your most sensitive data.

While standard encryption mechanisms secure data at rest across entire storage volumes, Cell-Level Encryption (CLE) — also known as Column-Level Encryption — provides surgical, cryptographic precision for highly sensitive data points. It acts as a targeted defense mechanism for your crown jewels, such as Social Security Numbers, Credit Card PANs, or medical records. By shifting the security boundary, CLE ensures that even if an attacker or a rogue administrator gains access to the active database, your most critical data remains completely unreadable without specific cryptographic keys.

But here is the catch when migrating to PostgreSQL: Postgres handles this fundamentally differently than legacy engines.

Unlike platforms that provide native engine-level wrappers, PostgreSQL shifts the encryption boundary squarely to the query or application layer, typically leveraging extensions like pgcrypto. Because the encryption happens at this level, it fundamentally changes how the database interacts with your data. If you don’t plan for this architectural shift, you risk breaking your system. Implementing CLE in Postgres requires careful query rewrites, introduces unique performance overheads, and drastically alters your indexing strategies — typically limiting you to exact-match queries while throwing out range searches (>,<) or wildcard searches (LIKE) on encrypted columns.

As organizations adopt cloud-native and Zero Trust architectures, leaving your column-level protection behind or botching its implementation isn’t an option. Based on the core architectures outlined in “Cell-Level — DB Encryption for Migration scenarios,” let’s dive into how CLE operates across different database engines, and map out exactly how you can successfully transition your cryptographic security into a modern PostgreSQL environment.

The Starting Point: Source Database Architectures

To successfully transition your security model, you must first understand the mechanics of the system you are migrating away from. If you are moving workloads out of SQL Server or Oracle, your existing cell-level encryption is likely deeply intertwined with those engines’ native features. Let’s dissect how these traditional platforms handle encryption under the hood so you can map their specific behaviors to your new PostgreSQL environment.

SQL Server

CLE in legacy SQL Server relies on native Transact-SQL functions, while modern implementations favor client-side frameworks like Always Encrypted.

How it works:

It uses SQL Server’s internal cryptographic functions to encrypt specific pieces of data within a table.

  • Legacy Approach: You use Transact-SQL functions (like ENCRYPTBYKEYand DECRYPTBYKEY) combined with symmetric keys, asymmetric keys, or certificates. Because the encryption happens at the query level, application or query changes are required.
  • Modern deployments: These utilize Always Encrypted, where the client application’s SQL driver silently encrypts and decrypts the targeted columns in memory before sending the payload to the database.

Typical Usage Scenario: Granular data protection and strict least-privilege. You use this when you only need to encrypt highly sensitive data points in a database that contains mostly non-sensitive data, and you want to prevent unauthorized users (including sysadmins and DBAs querying the active database) from seeing the plaintext data.

Oracle

Oracle offers two distinct architectural paths for cell-level security: native engine-level encryption (via the Oracle Advanced Security license) and manual, programmatic encryption (via the DBMS_CRYPTOpackage).

How it works:

  1. Native Column Encryption: A single Table Key is used to encrypt all designated columns within that specific table. This Table Key is then wrapped (encrypted) by the database Master Encryption Key (MEK) and stored securely in an external keystore.
  2. Programmatic Encryption (DBMS_CRYPTO): Developers use the DBMS_CRYPTOPL/SQL package to manually encrypt and decrypt individual cells using custom logic. Because these symmetric keys are built directly into the application’s database calls, the keys remain strictly within the application layer and are never exposed to the database engine.

Typical Usage Scenario: Preventing DBA data snooping. This strategy is heavily utilized in environments with strict regulatory compliance where highly privileged IT staff must maintain database structures and performance, but are explicitly barred from viewing actual PII or financial records.

The Security Catch: Because native column encryption is entirely transparent to database users with high-level SELECTprivileges, achieving true separation of duties requires pairing it with Oracle Database Vault.

The Alternative: If you utilize the DBMS_CRYPTOframework instead, this separation is achieved natively because the database engine never holds the decryption keys in the first place.

CLE in Managed Cloud (PaaS/DBaaS)

In a managed cloud environment, CLE remains firmly the responsibility of the customer’s database developers and security architects, focusing entirely on key management.

The cloud’s primary value-add for CLE is the integration of centralized Key Management Services (KMS). Instead of storing the Column Master Keys inside the database itself (where they are vulnerable to local SQL injection or local administrator compromise), cloud platforms allow organizations to anchor CLE trust in an external, highly available KMS. This enforces strict Separation of Duties: the application authenticates to the KMS to fetch the keys required to decrypt the cells, completely bypassing the database’s internal permission structure.

Centralizing Cryptographic Secrets

Regardless of the database engine (SQL Server, PostgreSQL, or Oracle), a critical best practice for programmatic cell-level encryption is to never hardcode encryption keys or passphrases within application code, connection strings, or stored procedures. Instead, your application should dynamically retrieve these secrets from Google Cloud Secret Manager at runtime before passing them to native cryptographic functions (such as ENCRYPTBYKEY, PGCRYPTO, DBMS_CRYPTO). This hybrid approach centralizes secret auditing and ensures that even if your application logic or configuration files are exposed, the underlying ciphertext remains perfectly secure.

CLE in Google Cloud Database Offerings

Implementing CLE in Google Cloud relies heavily on the specific database engine’s capabilities, integrated tightly with Google Cloud KMS or the open-source Tink cryptography library:

  • Cloud SQL for SQL Server: When performing a “lift and shift” migration, continuing to utilize traditional T-SQL encryption functions (such as ENCRYPTBYKEYand DECRYPTBYKEY) is the easiest path forward, as it preserves your existing application logic and database architecture. However, some migration effort will still be required; you must meticulously plan the export and import of your existing Database Master Keys (DMK), certificates, and symmetric keys into the Cloud SQL instance to ensure the ciphertext remains accessible post-migration.
  • Oracle Database@Google Cloud: This offering allows you to run native Oracle Column Encryption while completely modernizing your key infrastructure. Because this service integrates directly with Google Cloud KMS, the Master Encryption Key (MEK) protecting your underlying column keys is managed entirely by your Google Cloud IAM policies. This grants security teams centralized, infrastructure-level control over the database’s encryption wallet. It ensures that root keys are fiercely protected from platform-level compromise, even while database access remains bound to internal database security controls.
  • Cloud SQL for PostgreSQL: Because PostgreSQL lacks built-in transparent column encryption, CLE is achieved using the pgcryptoextension. Developers use functions like pgp_sym_encrypt() within their INSERTand SELECTstatements. In Google Cloud, best practices dictate that the passphrase used by pgcryptoshould not be hardcoded in the SQL script. Instead, applications should dynamically retrieve the passphrase from Google Cloud Secret Manager at runtime.
  • AlloyDB for PostgreSQL: Similar to Cloud SQL for PostgreSQL, AlloyDB relies on the pgcryptoextension for granular column encryption.

The Architectural Advantage: Due to AlloyDB’s highly distributed storage architecture, handling cell-level encryption at the application or query level ensures that the data is already encrypted before it is broken into chunks and distributed across the storage nodes.

The On-Premises vs. Google Cloud Risk Profile

Transitioning CLE workloads to Google Cloud dramatically reduces key sprawl and mitigates the risk of insider threats:

  • Key Sprawl and Hardcoded Secrets: On-premises CLE implementations often suffer from poor key management, with symmetric keys stored locally in the database or encryption passwords hardcoded into application config files. Google Cloud mitigates this via Cloud KMS and Secret Manager, abstracting the key material away from the code and the database engine entirely.
  • The DBA “God Mode” Risk: In traditional on-premises deployments, a sysadmin or highly privileged local administrator often has the clearance to access the local keystores or view the programmatic logic containing the decryption keys, defeating the purpose of CLE. By leveraging frameworks backed by Google Cloud KMS, the control planes are severed. Even a user with top-tier privileges on the database instance cannot decrypt the column data unless their specific IAM identity is granted the roles/cloudkms.cryptoKeyDecrypterIAM role.

Conclusion: The Path to a Secure Postgres Migration

Migrating to PostgreSQL is an excellent opportunity to modernize more than just your database engine — it is your chance to elevate your entire data security posture. While shifting from built-in engine encryption to a query-layer or client-side approach requires a fundamental rethink of your schema and indexing strategies, the security payoffs are massive. By anchoring your encryption keys in centralized cloud services like Google Cloud KMS and Secret Manager rather than the database itself, you successfully dismantle the DBA “God Mode” threat and achieve a true Zero Trust architecture. Don’t treat cell-level encryption as an afterthought on your migration checklist; architect for it from day one.

What is your biggest roadblock so far in your journey to PostgreSQL? Drop a comment below with your thoughts or architecture questions. If you found this breakdown helpful, be sure to follow for more deep dives into cloud migrations and database security!


메타데이터
post_id
f23b62ca38dd
slug
migrating-to-postgres-dont-leave-your-cell-level-encryption-behind-f23b62ca38dd
url
https://medium.com/google-cloud/migrating-to-postgres-dont-leave-your-cell-level-encryption-behind-f23b62ca38dd
canonical_url
https://medium.com/google-cloud/migrating-to-postgres-dont-leave-your-cell-level-encryption-behind-f23b62ca38dd
author_url
https://medium.com/@assaff_3668
status
ok
fetched_at
2026-06-09 15:37:30