The Simplest Way to Make Databricks ML and PostgreSQL Work Like They Should

Published
Length
3 min read

Luis Felipe Dias

All posts

Teams pair databricks ml and postgresql to train models on operational data and store predictions. This setup pulls live tables into notebooks and writes model scores back for apps. Data scientists need fresh records from transactional tables to build good features. At the same time, database admins must protect production tables from heavy queries and leaks. Setting up clear rules between your notebooks and your database keeps both sides happy. How databricks ml and postgresql share data and

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 databricks ml and postgresql to train models on operational data and store predictions. This setup pulls live tables into notebooks and writes model scores back for apps.

Data scientists need fresh records from transactional tables to build good features. At the same time, database admins must protect production tables from heavy queries and leaks. Setting up clear rules between your notebooks and your database keeps both sides happy.

How databricks ml and postgresql share data and roles

A machine learning cluster reads training rows from database tables over a network link. Once a job finishes scoring, it writes the output back to a target table. To do this, the compute cluster logs in with a database role.

In PostgreSQL, admins can set up group roles to manage permissions for many users. Individual users or compute jobs then join the group role to get the right access. For training jobs that only read data, admins grant the SELECT privilege. The SELECT privilege allows reading from a full table or from specific columns. It also allows copying data out of the table for fast batch reads.

Admins should also check what the special PUBLIC role can do. By default, PUBLIC gives every role the ability to connect to databases and create temporary tables. It also lets every role run functions and procedures unless the owner revokes those defaults. Tightening these defaults stops notebook jobs from running unwanted database functions.

Common failure modes with shared accounts and broad permissions

Many teams start by putting one shared database password into a workspace secret store. Every notebook and scheduled job then uses that same login to query production tables. When a bad query locks a table, admins cannot tell which user ran it. Database logs only show the shared account name, not the person behind the notebook.

Overly broad permissions create a second risk for production data. If a training role has full table access, it pulls every column into memory by default. That means sensitive fields like emails, phone numbers, card numbers, or national IDs enter notebooks. Data masking rewrites matched fields in query results to reduce this exposure. You can also grant SELECT only on the exact columns needed for model features.

PostgreSQL Access Control + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Write permissions need strict limits as well. In PostgreSQL 15 and later, regular users cannot create objects in the public schema by default. Older databases, or ones upgraded from older releases, might still allow this. On those systems, an admin must revoke CREATE on the public schema from PUBLIC. Model scoring jobs should only write to a dedicated output table, never the whole schema.

Scoping network paths and database roles for model workflows

Good architecture separates interactive notebook sessions from automated scoring pipelines. Interactive users only need read permissions on safe feature views or selected columns. Automated pipelines need write permissions on a single prediction table and nothing else. Give each workflow its own group role with strict table and column rules.

Route heavy training reads to a read replica instead of the primary database node. This simple split stops large feature pulls from slowing down customer transactions. Keep network paths closed by default, allowing traffic only from known cluster networks. When you pair scoped roles with clean network paths, your data stays safe during training.

Check database and API queries on the wire

Identity tools, roles, and network rules decide who opens a session. Setup alone cannot check what each query does or mask sensitive values in a response once a session starts. When workflows touch Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, or internal HTTP APIs, hoop.dev runs beside those services as an open-source proxy, a sidecar for your Postgres or API. It inspects requests coming in and results going back on the wire.

Your login details and client tools stay as they are while hoop.dev guardrails refuse bad deletes or drops before they run. On responses, hoop.dev data masking rewrites matched sensitive values in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and writes every query and decision to an audit trail that generates evidence for HIPAA, GDPR, and PCI DSS. See the source on GitHub.

Frequently asked questions

How can I stop notebooks from reading sensitive columns in PostgreSQL?

Grant the SELECT privilege only on the specific columns required for your model features. You can also use data masking to rewrite emails, phone numbers, and card numbers in results.

Why can my training job still create tables in the public schema?

Databases created before PostgreSQL 15 allow PUBLIC to create objects in the public schema. An admin must revoke the CREATE privilege on the public schema from the PUBLIC role.

Should interactive notebooks and automated ML jobs share a database role?

No, you should set up separate group roles for interactive users and automated scoring jobs. Give interactive roles read-only column permissions, and give automated jobs write access only to output tables.

The query runs. The emails stay hidden.