<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Alex Serban</title>
    <description>The latest articles on DEV Community by Alex Serban (@alex_serban).</description>
    <link>https://dev.to/alex_serban</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3932555%2F3b55ffae-761d-4f6f-a057-2a510a9788b9.jpg</url>
      <title>DEV Community: Alex Serban</title>
      <link>https://dev.to/alex_serban</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/alex_serban"/>
    <language>en</language>
    <item>
      <title>The pgAudit Attribution Gap: Why Role-Level Logging Fails GDPR and How to Close It</title>
      <dc:creator>Alex Serban</dc:creator>
      <pubDate>Mon, 25 May 2026 05:49:00 +0000</pubDate>
      <link>https://dev.to/alex_serban/the-pgaudit-attribution-gap-why-role-level-logging-fails-gdpr-and-how-to-close-it-2o88</link>
      <guid>https://dev.to/alex_serban/the-pgaudit-attribution-gap-why-role-level-logging-fails-gdpr-and-how-to-close-it-2o88</guid>
      <description>&lt;h2&gt;
  
  
  What pgAudit Actually Logs
&lt;/h2&gt;

&lt;p&gt;pgAudit is a PostgreSQL extension that captures query-level events at the database session layer. A typical entry looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="mi"&gt;2026&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;03&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;14&lt;/span&gt; &lt;span class="mi"&gt;11&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;22&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;08&lt;/span&gt; &lt;span class="n"&gt;UTC&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;8841&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="k"&gt;user&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;app_user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;production&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;psql&lt;/span&gt;
  &lt;span class="n"&gt;AUDIT&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;SESSION&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="k"&gt;READ&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="k"&gt;TABLE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;subscription_tier&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;region&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'EU'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This tells you: the role &lt;code&gt;app_user&lt;/code&gt; ran a SELECT against the &lt;code&gt;users&lt;/code&gt; table at 11:22 UTC. Accurate. Tamper-resistant. Exactly what pgAudit is designed to produce.&lt;/p&gt;

&lt;p&gt;It does not tell you which human being was behind that session.&lt;/p&gt;

&lt;p&gt;In every production PostgreSQL application using a connection pooler PgBouncer, PgCat, Odyssey all queries arrive at the database authenticated as a shared service account. Your Django backend, your Node API, your internal admin panel, and your data team's analytics queries all hit Postgres as &lt;code&gt;app_user&lt;/code&gt;. pgAudit logs all of them identically.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Gap, In Two Log Entries
&lt;/h2&gt;

&lt;p&gt;This is the difference between a compliant and a non-compliant audit trail:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What pgAudit produces (shared credential):&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="mi"&gt;2026&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;03&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;14&lt;/span&gt; &lt;span class="mi"&gt;11&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;22&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;08&lt;/span&gt; &lt;span class="n"&gt;UTC&lt;/span&gt;
  &lt;span class="k"&gt;user&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;app_user&lt;/span&gt;
  &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;subscription_tier&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;region&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'EU'&lt;/span&gt;
  &lt;span class="n"&gt;rows_returned&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;47291&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;What a compliant audit log contains:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;2026-03-14 11:22:08 UTC
  session_user_id: employee_id_2291
  session_email: j.muller@company.com
  db_role: app_user
  query: SELECT id, email, subscription_tier FROM users WHERE region = 'EU'
  affected_table: users
  columns_accessed: id, email, subscription_tier
  rows_returned: 47291
  masked_fields: email → j***@***.com
  log_id: immutable-7a3c91f2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Same query. Same shared credential. Same database. The difference is where the user's identity was captured.&lt;/p&gt;

&lt;p&gt;Run this on your database now: &lt;code&gt;SELECT usename FROM pg_stat_activity;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If every row shows &lt;code&gt;app_user&lt;/code&gt; instead of individual emails, you have the gap.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why the Obvious Workaround Doesn't Hold
&lt;/h2&gt;

&lt;p&gt;The standard response to this problem is session-level injection: set a PostgreSQL session variable that identifies the current user before each query.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;current_user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'alice@company.com'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;email&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;pgAudit then captures &lt;code&gt;alice@company.com&lt;/code&gt;. The attribution problem appears solved.&lt;/p&gt;

&lt;p&gt;It is not solved in most production systems.&lt;/p&gt;

&lt;p&gt;The reason is PgBouncer in &lt;strong&gt;transaction mode&lt;/strong&gt; — the most common production configuration because it provides the best connection multiplexing efficiency. In transaction mode, a client connection is bound to a server connection only for the duration of a single transaction. Between transactions, the server connection is returned to the pool and reassigned to a different client.&lt;/p&gt;

&lt;p&gt;When that reassignment happens, session state resets. The &lt;code&gt;SET app.current_user&lt;/code&gt; variable you injected at the start of your request is gone before the next query runs. You get no error, no warning, and no log entry indicating the attribution failed. The audit log quietly fills with &lt;code&gt;app_user&lt;/code&gt; entries while your system appears to be working correctly.&lt;/p&gt;

&lt;p&gt;This is not a configuration mistake you can fix. It is how transaction-mode pooling works.&lt;/p&gt;




&lt;h2&gt;
  
  
  What GDPR Actually Requires
&lt;/h2&gt;

&lt;p&gt;In January 2026, CNIL fined France Travail €5 million. The decision cited two specific Article 32 failures: access authorizations defined too broadly, and logging insufficient to detect abnormal behaviour. The investigators could not reconstruct the full scope of the breach because the logs did not capture enough granularity.&lt;/p&gt;

&lt;p&gt;In March 2026, Italy's Garante fined Intesa Sanpaolo €31.8 million. One employee ran 6,637 unauthorized queries across 3,573 customer records over 460 working days. pgAudit ran throughout. Not one query triggered an alert, because pgAudit attributed every query to &lt;code&gt;app_user&lt;/code&gt; making the employee's pattern invisible.&lt;/p&gt;

&lt;p&gt;Neither company lacked logging. Both lacked attribution.&lt;/p&gt;

&lt;p&gt;Article 5(2) of GDPR requires you to demonstrate that personal data is processed lawfully. Article 32 requires appropriate technical measures. The operational implication, made explicit by both decisions: your logging must be sufficient to identify which person accessed which records, not just which role executed which query.&lt;/p&gt;

&lt;p&gt;Two scenarios where this becomes an immediate liability:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Data subject access requests.&lt;/strong&gt; Under Article 15, a data subject can ask for a complete record of who accessed their personal data and when. If your audit log only shows &lt;code&gt;app_user&lt;/code&gt;, you cannot produce a complete response. An incomplete DSAR response is itself a violation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Insider access investigations.&lt;/strong&gt; Both France Travail and Intesa Sanpaolo involved authorized users accessing records outside their legitimate scope. In both cases, the regulator found the company could not reconstruct what happened which is treated as evidence of inadequate controls, regardless of intent.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Fix: A Query Proxy Covers Every Access Path
&lt;/h2&gt;

&lt;p&gt;There is only one approach that covers all paths into your database: a query proxy layer that intercepts every query before it reaches Postgres, while the application-layer identity is still available.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Per-user database roles&lt;/strong&gt; solve the attribution problem cleanly each person connects with their own credential, and pgAudit attributes correctly. In practice, this is incompatible with connection pooling at any meaningful scale, requires role management across every migration, and breaks most ORM configurations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Application-level audit middleware&lt;/strong&gt; covers queries that go through your application. It misses direct database access by engineers running ad-hoc queries, analytics tools, migration scripts, and DBA sessions exactly the access paths that created liability in France Travail and Intesa Sanpaolo. If your application logs are your only audit trail, those paths are invisible.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A query proxy&lt;/strong&gt; sits between your application and your database, intercepting before the connection pool strips identity. It covers every access path application queries, direct connections, analytics tools, and DBA sessions all pass through the same point. It requires no changes to your application code, your ORM, or your database role structure.&lt;/p&gt;




&lt;h2&gt;
  
  
  How Scalple Closes the Gap
&lt;/h2&gt;

&lt;p&gt;Scalple is a query-level PostgreSQL proxy. It runs between your application and your database and intercepts every query before it reaches Postgres.&lt;/p&gt;

&lt;p&gt;Here is how identity capture works: your application passes the authenticated user's identity as a connection parameter a single line in your database connection string, not an application code change. Scalple reads this parameter at the connection layer, before PgBouncer enters the picture. Because Scalple sits in front of PgBouncer, the transaction-mode session reset that breaks &lt;code&gt;SET app.current_user&lt;/code&gt; does not apply identity is captured at the proxy layer, not the session layer.&lt;/p&gt;

&lt;p&gt;For each query, Scalple writes an immutable, append-only log entry: the user ID, session metadata, the full query text, the tables and columns touched, masked values for fields you designate as PII, and a tamper-evident log ID. Then it forwards the query to Postgres as normal.&lt;/p&gt;

&lt;p&gt;Your application continues connecting as &lt;code&gt;app_user&lt;/code&gt;. Your PgBouncer configuration does not change. Your ORM does not change. Deployment is a connection string change your app points to Scalple instead of directly to Postgres, and Scalple forwards to Postgres. Setup takes under 30 minutes.&lt;/p&gt;

&lt;p&gt;If CNIL asked you today for every access to a specific user's data over the last six months, Scalple gives you that query in under a minute. Without it, you have &lt;code&gt;app_user&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Before the Next Fine
&lt;/h2&gt;

&lt;p&gt;France Travail was fined €5 million. They had logging. The logging was insufficient because it could not reconstruct who accessed what.&lt;/p&gt;

&lt;p&gt;Intesa Sanpaolo was fined €31.8 million. They had pgAudit running for 460 working days. One employee's unauthorized access pattern was invisible the entire time.&lt;/p&gt;

&lt;p&gt;The engineering team that enabled pgAudit and stopped is not non-compliant because they chose the wrong tool. pgAudit is the right tool for query-level database logging. It is not the right tool for GDPR access attribution, because in a pooled environment it cannot attach a human identity to a database query.&lt;/p&gt;

&lt;p&gt;The demo at scalple.com runs against a live PgBouncer connection pool. You can see exactly what your current pgAudit log is missing and what a compliant per-user audit log looks like in its place.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;&lt;a href="https://scalple.com" rel="noopener noreferrer"&gt;Scalple&lt;/a&gt; is a database audit platform for B2B SaaS teams with GDPR obligations. Per-user query attribution at the proxy layer, no application code changes required.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>security</category>
      <category>devops</category>
      <category>database</category>
      <category>startup</category>
    </item>
    <item>
      <title>If someone asked you who accessed your production database last Tuesday, could you answer?</title>
      <dc:creator>Alex Serban</dc:creator>
      <pubDate>Tue, 19 May 2026 06:35:45 +0000</pubDate>
      <link>https://dev.to/alex_serban/if-someone-asked-you-who-accessed-your-production-database-last-tuesday-could-you-answer-1nip</link>
      <guid>https://dev.to/alex_serban/if-someone-asked-you-who-accessed-your-production-database-last-tuesday-could-you-answer-1nip</guid>
      <description>&lt;p&gt;Two scenarios.&lt;/p&gt;

&lt;p&gt;Your biggest prospect sends over a security questionnaire. &lt;br&gt;
Question 47: "Can you provide per-user audit trails for all production database access?" Or a customer emails saying they think their account may have been accessed by someone who shouldn't have had access. You have 24 hours to respond.&lt;/p&gt;

&lt;p&gt;Both questions come down to the same thing: who ran what query, and when?&lt;/p&gt;

&lt;p&gt;Most teams can't answer that. Not because they have no logs because their logs don't answer that question.&lt;/p&gt;

&lt;p&gt;In March 2026, Italy's data protection authority fined Intesa Sanpaolo €31.8M. Not a breach, not data sold one employee ran 6,637 queries across 3,573 customer records over two years, no access controls stopped them, and no anomaly detection fired. Query logs existed. Per-user attribution didn't. When the regulator asked who ran those queries, the bank couldn't say.&lt;/p&gt;
&lt;h2&gt;
  
  
  The shared credentials problem
&lt;/h2&gt;

&lt;p&gt;Most engineering teams handle production database access the same way. One &lt;code&gt;readonly&lt;/code&gt; role. Credentials in a 1Password vault or a &lt;code&gt;.env.production&lt;/code&gt; in secrets manager. Shared across everyone who needs it.&lt;/p&gt;

&lt;p&gt;It works until it doesn't. A few situations where it bites:&lt;/p&gt;

&lt;p&gt;An enterprise prospect asks for SOC 2 evidence. CC6.1 and CC7.2 require logical access controls and monitoring of system activity. Your answer: "We use a shared readonly role with pg_audit logging." Their security team: "We need per-user attribution, not role-level attribution." Deal paused.&lt;/p&gt;

&lt;p&gt;A regulator or customer's lawyer asks about a specific record. "Show me every access to this customer's account in March." Your pg_audit logs show &lt;code&gt;readonly_user&lt;/code&gt; ran a SELECT on the &lt;code&gt;users&lt;/code&gt; table. You have 15 engineers sharing that role. You cannot answer the question.&lt;/p&gt;

&lt;p&gt;An engineer leaves under bad terms. You rotate the shared credential or you don't, because rotating means hunting down every CI pipeline, every &lt;code&gt;.env&lt;/code&gt;, every tunnel they might have set up. And even if you do rotate it, you still have no idea what they accessed in their last two weeks. The logs show &lt;code&gt;readonly_user&lt;/code&gt; and nothing else.&lt;/p&gt;
&lt;h2&gt;
  
  
  What pg_audit actually gives you
&lt;/h2&gt;

&lt;p&gt;pg_audit is a solid extension. You should have it. Here's a typical log entry:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="mi"&gt;2026&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;03&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;15&lt;/span&gt; &lt;span class="mi"&gt;14&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;23&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;11&lt;/span&gt; &lt;span class="n"&gt;UTC&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;12847&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt; &lt;span class="n"&gt;LOG&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="n"&gt;AUDIT&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;SESSION&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="k"&gt;READ&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="k"&gt;TABLE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nv"&gt;"SELECT id, email, created_at FROM users WHERE id = $1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;not&lt;/span&gt; &lt;span class="n"&gt;logged&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You get the role, the statement type, the object accessed, the full query text, and the timestamp.&lt;/p&gt;

&lt;p&gt;What you don't get: which human ran this, whether they were authorized to access that table, or which fields came back.&lt;/p&gt;

&lt;p&gt;If every engineer has their own PostgreSQL role, pg_audit gives you genuine per-user attribution. If they share a role, you get role-level attribution. You can prove &lt;code&gt;readonly_user&lt;/code&gt; ran a query. You can't prove it was Alex from the backend team, or that Alex's access was authorized at that time.&lt;/p&gt;

&lt;p&gt;pg_audit is necessary. On a shared role, it's not sufficient.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Teleport and Boundary give you
&lt;/h2&gt;

&lt;p&gt;Teleport and Boundary solve the attribution problem at the session level. Each engineer authenticates with their own identity, that identity gets attached to the database session, the session is recorded. A real step up from shared credentials.&lt;/p&gt;

&lt;p&gt;The limits are worth understanding. Both are perimeter-based they secure the path through the approved tunnel. If a credential exists anywhere else (a CI variable with a hardcoded connection string, a developer's local &lt;code&gt;.env&lt;/code&gt; from before Teleport was rolled out, an old bastion rule someone forgot to clean up) that path is wide open.&lt;/p&gt;

&lt;p&gt;Session recordings also create volume. To answer "which queries touched this customer record in March," you're either replaying recordings or building a search layer on top. For a regulator audit or a subject access request, being able to query logs directly beats replaying session recordings one by one, that's a real problem.&lt;/p&gt;

&lt;p&gt;Both tools are worth having. They don't close the field-level problem.&lt;/p&gt;

&lt;h2&gt;
  
  
  The field-level gap nobody talks about
&lt;/h2&gt;

&lt;p&gt;An engineer debugging a billing issue runs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;customers&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That returns &lt;code&gt;customer_id&lt;/code&gt;, &lt;code&gt;created_at&lt;/code&gt;, &lt;code&gt;plan_tier&lt;/code&gt; and also &lt;code&gt;iban&lt;/code&gt;, &lt;code&gt;date_of_birth&lt;/code&gt;, &lt;code&gt;ssn&lt;/code&gt;. The engineer needed the first three. They got all six. The billing bug didn't require those fields. Returning them is a data minimization risk under GDPR Art. 5(1)(c), whether or not the access was logged.&lt;/p&gt;

&lt;p&gt;PostgreSQL column-level privileges exist but break down with CTEs, subqueries, and joins in ways that are easy to misconfigure. The bigger issue is that most teams have never applied field-level controls to internal database access at all. They applied data minimization to their external APIs and assumed internal access was different.&lt;/p&gt;

&lt;p&gt;The regulation doesn't make that distinction.&lt;/p&gt;

&lt;h2&gt;
  
  
  An architecture that closes all three gaps
&lt;/h2&gt;

&lt;p&gt;The fix that actually works: engineers don't connect directly to production. This sounds annoying until you see what it enables.&lt;/p&gt;

&lt;p&gt;Instead, they call named, typed query functions. &lt;code&gt;get_order_by_id(order_id)&lt;/code&gt;. &lt;code&gt;search_customers(email_prefix)&lt;/code&gt;. Those functions run in a policy evaluation layer between the engineer and the database. Before the query reaches Postgres, it attaches user identity from the auth context, evaluates field-level policies (does this user's role permit access to &lt;code&gt;iban&lt;/code&gt; fields here? if not, mask or reject), and writes to an append-only audit table.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="n"&gt;audit_log&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;user_email&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;function_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;parameters&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;rows_returned&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;field_policies_applied&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;called_at&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;VALUES&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="s1"&gt;'usr_abc123'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'alex@company.com'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'get_order_by_id'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s1"&gt;'{"order_id": "ord_xyz789"}'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;14&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s1"&gt;'{"iban": "masked", "ssn": "masked"}'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s1"&gt;'2026-03-15T14:23:11Z'&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The audit table is INSERT-only. No UPDATE, no DELETE. When Alex leaves, you revoke their identity in one place. No credential rotation across 12 pipelines.&lt;/p&gt;

&lt;p&gt;How the options compare:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Control&lt;/th&gt;
&lt;th&gt;Per-user attribution&lt;/th&gt;
&lt;th&gt;Field-level control&lt;/th&gt;
&lt;th&gt;Revocable on offboarding&lt;/th&gt;
&lt;th&gt;Immutable log&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Shared DB role&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;pg_audit (shared role)&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Teleport / Boundary&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Partial&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Application-layer proxy&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;You can build this yourself. The pieces exist in the Postgres ecosystem. Whether it's worth the build time and maintenance is a separate question.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This is what &lt;a href="https://scalple.com" rel="noopener noreferrer"&gt;Scalple&lt;/a&gt; implements, free for teams under 15 users. Either waycan you answer "who accessed that record and when" before someone asks?&lt;/em&gt;&lt;/p&gt;

</description>
      <category>security</category>
      <category>devops</category>
      <category>database</category>
      <category>privacy</category>
    </item>
  </channel>
</rss>
