Zero Labs
Industry News / AI

Privacy-Preserving Analytics with EDB Postgres Advanced Server Data Redaction

Source · Towards AI By Chiranjib Ghatak

From the publisher’s feed, collected in the ZeroLabs newsroom.

How database-level masking, role-based access, and Power BI can protect sensitive data without duplicating the warehouseHigh Level Architecture ( AI Generated)IntroductionModern analytics platforms must make data available to a wide range of users while ensuring that sensitive information remains protected.A business lead may require access to complete customer information for an approved operational purpose. An analyst working with the same dataset may need transaction patterns, customer segments, and aggregated measures, but may not need to see names, email addresses, phone numbers, identification numbers, or other personally identifiable information.Creating separate physical copies of the data for each user group can increase storage, synchronization, operational, and governance complexity. A more controlled approach is to retain one authoritative dataset and dynamically transform sensitive values based on the identity used to query the database.This article presents a generic implementation pattern using:EDB Postgres Advanced Server data redactionA centralized sensitive-column inventoryDatatype-specific masking functionsTable-level redaction policiesSeparate masked and unmasked database rolesPower BI Report Server folder-level access controlEDB describes data redaction as a feature that limits sensitive-data exposure by dynamically changing data when it is displayed to particular users. The underlying value remains stored in the database.Data obfuscation, masking, and redactionThese terms are often used interchangeably, but they can represent different controls.Data obfuscationData obfuscation is the broader concept of making sensitive information difficult or impossible for unauthorized users to understand. It can include:Data maskingRedactionTokenizationHashingEncryptionData substitutionData anonymizationStatic data maskingStatic masking creates a transformed copy of the dataset.Original email: alex.lee@example.test Masked copy: *********************This approach is commonly used when a separate, non-production dataset is required.Dynamic data redactionDynamic redaction does not create another physical copy of the value. Instead, the database changes the value returned in the SQL result based on a policy condition.Authorized role: alex.lee@example.test Restricted role: *********************Security hierarchyDirectory group -> Power BI Report Server folder -> Published report copy -> Database service account -> Database group role -> Schema and table privileges -> Redaction policy -> Masked or original resultDirectory groups control which report users can open.Report credentials determine which database identity executes the query.Database roles provide schema and table permissions.Redaction policies determine whether sensitive values are transformed.Masking functions define the replacement value.Step 1: Maintain a centralized sensitive-column inventoryA scalable implementation should avoid embedding an uncontrolled list of sensitive columns in multiple deployment scripts. Instead, maintain the approved inventory as metadata.CREATE SCHEMA IF NOT EXISTS data_security; CREATE TABLE IF NOT EXISTS data_security.sensitive_columns ( schema_name VARCHAR(100) NOT NULL, table_name VARCHAR(200) NOT NULL, column_name VARCHAR(200) NOT NULL, expected_datatype VARCHAR(100) NOT NULL, masking_function VARCHAR(200) NOT NULL, enabled_flag BOOLEAN NOT NULL DEFAULT TRUE, CONSTRAINT pk_sensitive_columns PRIMARY KEY (schema_name, table_name, column_name) );A fictional inventory might look like this:INSERT INTO data_security.sensitive_columns (schema_name, table_name, column_name, expected_datatype, masking_function) VALUES (‘analytics’,’dim_person’,’full_name’,’VARCHAR(100)’,’data_security.mask_varchar’), (‘analytics’,’dim_person’,’email_address’,’TEXT’,’data_security.mask_text’), (‘analytics’,’dim_person’,’mobile_number’,’VARCHAR(40)’,’data_security.mask_varchar’), (‘analytics’,’dim_person’,’birth_date’,’DATE’,’data_security.mask_date’) ON CONFLICT (schema_name, table_name, column_name) DO UPDATE SET expected_datatype = EXCLUDED.expected_datatype, masking_function = EXCLUDED.masking_function, enabled_flag = TRUE;The metadata table becomes the governed inventory for deployment input, completeness checks, datatype validation, policy generation, audit reporting, and change management. It should contain only formally approved sensitive columns.Step 2: Validate metadata against physical tablesThe implementation should not assume that a spreadsheet or design document contains the final physical datatype. Validate every metadata entry against the actual database catalog:SELECT s.schema_name, s.table_name, s.column_name, s.expected_datatype, c.data_type AS actual_datatype, c.udt_name, c.character_maximum_length, c.numeric_precision, c.numeric_scale, CASE WHEN c.column_name IS NULL THEN ‘COLUMN NOT FOUND’ ELSE ‘FOUND’ END AS validation_status FROM data_security.sensitive_columns s LEFT JOIN information_schema.columns c ON c.table_schema = s.schema_name AND c.table_name = s.table_name AND c.column_name = s.column_name WHERE s.enabled_flag = TRUE ORDER BY s.schema_name, s.table_name, s.column_name;This step is essential because TEXT, VARCHAR, INTEGER, NUMERIC, and DATE cannot all use an identical return datatype. EDB requires the redaction function return type to match the protected column datatype.Step 3: Create datatype-compatible masking functionsMasking a TEXT valueCREATE OR REPLACE FUNCTION data_security.mask_text(sensitive_value TEXT) RETURNS TEXT LANGUAGE plpgsql IMMUTABLE STRICT AS $function$ BEGIN RETURN repeat(‘*’, char_length(sensitive_value)); END; $function$;Masking a VARCHAR valueCREATE OR REPLACE FUNCTION data_security.mask_varchar(sensitive_value VARCHAR) RETURNS VARCHAR LANGUAGE plpgsql IMMUTABLE STRICT AS $function$ BEGIN RETURN repeat(‘*’, char_length(sensitive_value))::VARCHAR; END; $function$;Masking a dateA date column cannot directly return ***** because that value is text. The replacement must remain a date or NULL.CREATE OR REPLACE FUNCTION data_security.mask_date(sensitive_value DATE) RETURNS DATE LANGUAGE plpgsql IMMUTABLE AS $function$ BEGIN RETURN NULL; END; $function$;Design decision: Replacement rules for dates and numeric values require business approval. Returning 0, -1, or a fixed date can introduce misleading meaning. NULL may be safer, but report calculations must handle the masked state.Step 4: Separate login identities from permission rolesA clean design uses non-login group roles for permissions and login-enabled service accounts for report connectivity.CREATE ROLE analytics_unmasked_role NOLOGIN; CREATE ROLE analytics_masked_role NOLOGIN;Create fictional service accounts:CREATE ROLE reporting_authorized_svc LOGIN PASSWORD ‘REPLACE_WITH_SECURE_SECRET’; CREATE ROLE reporting_masked_svc LOGIN PASSWORD ‘REPLACE_WITH_SECURE_SECRET’;Map accounts to roles:GRANT analytics_unmasked_role TO reporting_authorized_svc; GRANT analytics_masked_role TO reporting_masked_svc;Grant permissions to the group roles:GRANT USAGE ON SCHEMA analytics TO analytics_unmasked_role, analytics_masked_role; GRANT SELECT ON ALL TABLES IN SCHEMA analytics TO analytics_unmasked_role, analytics_masked_role;Both roles can query the reporting tables. The redaction policy determines whether the returned sensitive values are original or masked.Step 5: Create one redaction policy per tableAssume the fictional table analytics.dim_person contains full_name as VARCHAR, email_address as TEXT, mobile_number as VARCHAR, and birth_date as DATE.CREATE REDACTION POLICY rp_mask_dim_person ON analytics.dim_person FOR ( NOT pg_has_role( session_user, ‘analytics_unmasked_role’, ‘member’ ) ) ADD COLUMN full_name USING data_security.mask_varchar(full_name), ADD COLUMN email_address USING data_security.mask_text(email_address), ADD COLUMN mobile_number USING data_security.mask_varchar(mobile_number), ADD COLUMN birth_date USING data_security.mask_date(birth_date);EDB supports multiple ADD COLUMN clauses within a redaction policy. This allows one policy to protect multiple columns of the same table. A practical convention is: one protected table equals one redaction policy.How the policy condition worksThe key expression is:NOT pg_has_role(session_user, ‘analytics_unmasked_role’, ‘member’)Authorized accountreporting_authorized_svc -> Member of analytics_unmasked_role -> pg_has_role returns TRUE -> NOT TRUE becomes FALSE -> Redaction is not applied -> Original values are returnedMasked accountreporting_masked_svc -> Not a member of analytics_unmasked_role -> pg_has_role returns FALSE -> NOT FALSE becomes TRUE -> Redaction is applied -> Masked values are returnedEDB notes that superusers and table owners bypass data redaction. Functional testing should therefore use representative non-owner identities rather than an administrative account.Step 6: Integrate with Power BI Report ServerWith fixed database service accounts, the simplest controlled design is to maintain one PBIX source and publish two report copies.Authorized report copyFolder: Authorized Reports Database identity: reporting_authorized_svc Database role: analytics_unmasked_role Result: Original sensitive valuesMasked report copyFolder: Masked Reports Database identity: reporting_masked_svc Database role: analytics_masked_role Result: Masked sensitive valuesThe two report copies should have the same visuals, Power Query logic, calculations, measures, navigation, and release version. Only the published folder, database credential, and access-control assignment should differ.This creates two complementary controls:Power BI folder security determines which report a user can open.EDB redaction determines which values the report receives.Testing the implementationTest with the restricted identitySELECT session_user, pg_has_role( session_user, ‘analytics_unmasked_role’, ‘member’ ) AS has_unmasked_access;Expected: has_unmasked_access is false.SELECT person_key, full_name, email_address, mobile_number, birth_date FROM analytics.dim_person LIMIT 10;Expected fictional output:101 | ************ | ************************ | ********** | NULLTest with the authorized identityRun the same query using reporting_authorized_svc. Expected fictional output:101 | Avery Morgan | avery.morgan@example.test | 0000000000 | 1990–01–01All names, addresses, dates, identifiers, schemas, and account names in this example are synthetic.Operational controls that should not be overlookedProtect service-account credentialsPasswords should not be stored in:ArticlesSQL repositoriesPBIX documentationEmailsScreenshotsDeployment logsUse the organization’s approved secret-management and credential-rotation process.Review role membershipSELECT pg_has_role( ‘reporting_masked_svc’, ‘analytics_unmasked_role’, ‘member’ ) AS unexpected_unmasked_access;Expected: false.Review semantic and materialized objectsA redaction policy attached to a curated table does not automatically prove that every downstream object is safe. Special attention is required for:Materialized viewsExtracted datasetsImported Power BI modelsCached resultsReport exportsSubscriptionsFiles created from report dataValidate masked access at the actual reporting boundary, not only at the source table.Preserve datatype behaviorReplacing a numeric value with a text label such as Masked is not possible at the database redaction layer without changing the result datatype. A practical pattern is for the database to return NULL or an approved numeric sentinel, while Power BI displays a friendly label and calculations explicitly handle the masked state.Final perspectiveData obfuscation is not a single function or one SQL command. It is a layered security design.A robust solution combines:An approved sensitive-data inventoryPhysical datatype validationReusable masking functionsTable-level redaction policiesLeast-privilege database rolesSeparate report identitiesFolder-level report accessContinuous testing and access reviewEDB Postgres Advanced Server data redaction provides the database-level mechanism for dynamically transforming protected values. The real strength of the architecture comes from connecting that mechanism to identity, metadata, reporting, and governance. When these controls are implemented together, organizations can support broad analytical access while reducing unnecessary exposure of sensitive information.ReferencesEDB Postgres Advanced Server v18: Redacting dataEDB Postgres Advanced Server v18: Data redaction key conceptsEDB Postgres Advanced Server v18: Creating a data redaction policyEDB Postgres Advanced Server security features#DataEngineering #DataSecurity #PostgreSQL #Power BI #DataGovernancePrivacy-Preserving Analytics with EDB Postgres Advanced Server Data Redaction was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.