How to Configure TimescaleDB Row Level Security

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up timescaledb row level security by turning on row rules for a parent hypertable. You then attach a filter rule that matches each row against the active database role. Most engineering teams use this method to isolate tenant metrics in a single time-series table. When teams skip row rules and rely on broad roles, any user can read all rows by default. A single bad query from an app or engineer can pull private records across tenants. How timescaledb row level security works on hyperta

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.

You set up timescaledb row level security by turning on row rules for a parent hypertable. You then attach a filter rule that matches each row against the active database role. Most engineering teams use this method to isolate tenant metrics in a single time-series table. When teams skip row rules and rely on broad roles, any user can read all rows by default. A single bad query from an app or engineer can pull private records across tenants.

How timescaledb row level security works on hypertables

TimescaleDB runs on PostgreSQL and uses the same base rule system for table rows. When you turn on row rules for a hypertable, the database blocks all rows by default. You must write a rule that tells the engine which rows a role can read. The rule checks a column value, like a tenant ID, against the current session role. You can also check a custom session variable that your app sets during login.

Under the hood, a hypertable splits time-series data into many smaller tables called chunks. When you add a row rule to the parent hypertable, it passes down to new chunks. Every query that hits the parent table runs through this filter before returning any data. You can set separate rules for reading rows, adding rows, updating rows, and deleting rows. Database superusers and table owners bypass these row rules unless you force rules for owners too.

How compression and continuous aggregates affect row rules

Time-series workloads often use data compression and pre-computed rollups to keep queries fast. These features change how the database stores chunks and reads rows on disk. Compressed chunks turn many rows into a single columnar array to save disk space. You cannot mix row-level rules with every compression or rollup setup without extra planning.

Continuous aggregates build summary views from raw hypertable data in the background. If you query a summary view, the database reads the view instead of raw chunks. You must check how permissions apply to those summary views so tenants stay isolated. Teams often create separate views per role or filter queries at the view layer. Testing your rules against both raw and compressed chunks stops accidental data leaks.

Row-Level Security + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

What native row rules solve and what they leave open

Native row rules work well when every human and app uses a distinct database role. The database engine enforces the filter on every read and write inside that session. Even if an app builds a wide query, the database hides rows from other tenants. This stops cross-tenant bugs inside multi-tenant apps.

The gap appears when engineers or support staff log in with shared admin roles. Teams often share a few high-level roles to fix production bugs or run manual checks. Those admin roles often own the tables or hold permissions that bypass row rules. Also, row rules only filter which rows a query touches. They do not mask sensitive fields like emails, phone numbers, card numbers, or national IDs. Once a row passes the filter, the query returns every column in raw text. Native rules also cannot pause a destructive query for peer approval before it runs.

Add runtime guardrails and masking beside your databases and APIs

Login rules, role grants, and CI checks govern who connects to your stack. Yet any allowed script, engineer, or AI agent still runs commands with the full scope of its role. For workloads on Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes, SSH, or internal HTTP services, hoop.dev sits inline in the protocol beside the service as an open-source proxy, a sidecar for your database or API. On every production query an agent or human runs, hoop.dev decides whether to pass, mask, block, or escalate it for review.

Before a query runs, hoop.dev guardrails check the statement against your rules, an AI Analyzer you configure can score intent or hold risky calls for human approval, and hoop.dev data masking rewrites sensitive fields in responses in memory. Explore the MIT-licensed project on GitHub.

Frequently asked questions

Do row rules pass down to new hypertable chunks?

Yes, rules set on the parent hypertable pass down to newly created chunks. You should still check existing chunks to confirm the rules apply across old data.

Why can my admin role still read all rows in the hypertable by default?

Table owners and superusers bypass row rules by default in the database engine. You must force row rules on table owners and remove superuser flags from human roles.

Can row rules hide specific columns like emails or phone numbers?

No, row rules only control which rows a query can read or change. If a user can read a row, they receive all columns unless you rewrite results.

The query runs. The emails stay hidden.