Insights
What we ran into along the way.
No tips and tricks. Notes from building real products, with the numbers and the miscalculations included.
Start here
- Multi-tenant SaaS on PostgreSQL: six decisions Six decisions a multi-tenant product locks into its database, two of which we measured ourselves.
- PostgreSQL row-level security for SaaS: what we measured What we measured about row-level security, by question, with the article for each.
- PostgreSQL error codes (SQLSTATE), with measured causes Got an error? Over thirty PostgreSQL errors by code, with the cause and the measurement.
-
Peer authentication failed for user "postgres": fixes
PostgreSQL's Peer authentication failed, measured on the Debian and Ubuntu packages: why sudo -u postgres works, -h localhost, pg_ident.conf and psycopg2.
Read on · 8 min read -
could not resize shared memory segment: Postgres in Docker
PostgreSQL could not resize shared memory segment: No space left on device is /dev/shm, not disk. Measured in Docker on 16 to 18; why 256 MB fell short.
Read on · 10 min read -
invalid input syntax for type json in PostgreSQL, measured
What raises 'invalid input syntax for type json' (22P02), measured on PostgreSQL 16 to 18: JS arrays, Python lists, NUL escapes, bad rows and a safe ALTER.
Read on · 12 min read -
json vs jsonb in PostgreSQL: size and speed, measured
json vs jsonb in PostgreSQL 17 and 18, measured on six document shapes: when jsonb is 23% smaller or 41% larger, read speed, GIN, and what it changes.
Read on · 10 min read -
server closed the connection unexpectedly in PostgreSQL
PostgreSQL's server closed the connection unexpectedly, measured in six clients: what the server log says per cause, where the reason goes, and lost COMMITs.
Read on · 16 min read -
no pg_hba.conf entry for host: what it means, measured
PostgreSQL's no pg_hba.conf entry for host, measured on 12 to 18 (not 15): the 'no encryption' tail, Docker's gateway address, hostssl, replication and reload.
Read on · 10 min read -
canceling statement due to conflict with recovery
Measured on a PostgreSQL 17 read replica: why queries are cancelled after 30 seconds, what the fixes cost, and why inserts fail with read-only transaction.
Read on · 12 min read -
canceling statement due to lock timeout in PostgreSQL
PostgreSQL's lock timeout error, measured on 17: what it cancels, why the transaction is then aborted, how it differs from statement_timeout, and a retry.
Read on · 8 min read -
canceling statement due to statement timeout: causes, fixes
PostgreSQL's statement timeout (SQLSTATE 57014), measured on 12 to 18: find which setting set the limit, raise it for one query, tell it from user request.
Read on · 11 min read -
cannot drop … because other objects depend on it, measured
PostgreSQL's 2BP01 measured on 17 and 12: which objects block a DROP, what CASCADE really removes, DROP ROLE across databases, and finding dependents first.
Read on · 10 min read -
column does not exist in PostgreSQL: causes, measured
PostgreSQL's 'column does not exist', measured on 12 to 18: capitals, double quotes, aliases in WHERE, UPDATE SET, renamed columns, psql's daticulocale.
Read on · 11 min read -
column is of type jsonb but expression is of type text
PostgreSQL 42804 measured on 17: why a literal works and a text parameter does not, JDBC setString on jsonb, stringtype=unspecified, psycopg 3 and the cast.
Read on · 8 min read -
must appear in the GROUP BY clause in PostgreSQL, measured
PostgreSQL's must appear in the GROUP BY clause error (42803), measured on 12, 15, 16 and 17: the primary-key exception, any_value, DISTINCT ON, aliases, ORMs.
Read on · 7 min read -
Connection refused: is the PostgreSQL server running?
psql's Connection refused, measured on PostgreSQL 17: what the message means, how it differs from timeouts and DNS errors, and the Docker cases behind it.
Read on · 10 min read -
current transaction is aborted, commands ignored: fixes
'commands ignored until end of transaction block' means an earlier statement failed. Find it, then roll back or use a savepoint. Shown for 20 clients.
Read on · 8 min read -
database is being accessed by other users in PostgreSQL
PostgreSQL's database is being accessed by other users, measured on 12, 13, 15 and 17: the 5-second wait, WITH (FORCE), its refusals and the reconnect race.
Read on · 8 min read -
deadlock detected in PostgreSQL: causes, measured
PostgreSQL's deadlock detected, measured on 17: which session loses, foreign key and batch-update deadlocks, ORDER BY … FOR UPDATE, and the retry.
Read on · 8 min read -
PostgreSQL: duplicate key value violates unique constraint
Measured on PostgreSQL 17 and 18: why inserts fail on the _pkey after an import, the setval that fixes it, and the upsert and NULL cases that cause it too.
Read on · 8 min read -
PostgreSQL error codes (SQLSTATE), with measured causes
Over thirty PostgreSQL errors by SQLSTATE — 23505, 42501, 42P01, 42703, 25P02, 40001 and more — each with the cause we reproduced and the measurement.
Read on · 10 min read -
invalid byte sequence for encoding "UTF8": measured fixes
PostgreSQL's invalid byte sequence for encoding UTF8, measured: 0x00, 0x92, 0xa0, 0xff, jsonb \u0000, COPY ENCODING, iconv, and finding bad rows.
Read on · 8 min read -
more than one row returned by a subquery in PostgreSQL
PostgreSQL error 21000, measured on 17 and 12: why a query works until the data changes, which fix returns which row, and how RLS makes it depend on the role.
Read on · 8 min read -
no unique or exclusion constraint matching ON CONFLICT
PostgreSQL's 42P10 on INSERT … ON CONFLICT, measured on 17: unique per tenant, partial and expression indexes, deferrable constraints, SQLAlchemy and Django.
Read on · 7 min read -
null value in column "id" violates not-null constraint
Why PostgreSQL inserts NULL into id, measured on 10 to 17: a missing default after LIKE or a partial restore, an explicit NULL from an ORM, and fixes that work.
Read on · 7 min read -
operator does not exist: uuid = text in PostgreSQL
Measured on PostgreSQL 17: why uuid = text fails, the current_setting cast in an RLS policy, which join side to cast for the index, and psycopg2 vs psycopg 3.
Read on · 7 min read -
out of shared memory in PostgreSQL: the lock table
PostgreSQL's out of shared memory, measured on 17 and 18: how many locks one transaction gets, what pg_dump, DROP SCHEMA and partitions take, and the fix.
Read on · 9 min read -
password authentication failed for user: causes, measured
PostgreSQL's password authentication failed for user, measured on 17: what the server log says, the Docker volume trap, md5 vs SCRAM, URL encoding and .pgpass.
Read on · 8 min read -
permission denied for schema public (PostgreSQL 15+)
Why CREATE TABLE fails with permission denied for schema public on PostgreSQL 15 to 18 and not on 14, measured, and which of five fixes work.
Read on · 7 min read -
permission denied for sequence in PostgreSQL
Measured on PostgreSQL 17 and 15: which privilege nextval, currval and setval need, why GRANT ALL ON ALL TABLES misses it, and the grant that covers new tables.
Read on · 7 min read -
permission denied to create extension in PostgreSQL
Which extensions a non-superuser may create in PostgreSQL 16 to 18, measured: pgcrypto, citext and uuid-ossp with one grant; vector, PostGIS, dblink not at all.
Read on · 7 min read -
relation does not exist in PostgreSQL (but it does)
Nine measured causes of PostgreSQL's 'relation does not exist' when the table is there: case, schema, USAGE, database, a dump, and a query to tell them apart.
Read on · 9 min read -
role "root" or "postgres" does not exist: causes, fixes
PostgreSQL's role does not exist, measured on 17: psql as root in Docker, POSTGRES_USER on a reused volume, quoted names, GRANT, SET ROLE and pg_restore.
Read on · 10 min read -
value too long for type character varying(255): fixes
PostgreSQL's value too long for type character varying(255), (50) or (100), measured on 12 to 18: find the column it never names and widen it without a rewrite.
Read on · 7 min read -
violates foreign key constraint in PostgreSQL, measured
PostgreSQL's violates foreign key constraint (23503), measured on 12 to 18: insert and delete variants, RESTRICT vs NO ACTION, deferred checks, RLS, orphans.
Read on · 10 min read -
hstore vs jsonb performance in PostgreSQL, measured
hstore against jsonb on a million flat documents in PostgreSQL 17 and 18, measured: storage, reads, updates, GIN indexes, and what hstore does to types.
Read on · 9 min read -
Supabase 'RLS Disabled in Public': what anon can do
What anon can do to a Supabase table without row-level security, measured on PostgreSQL 17 with Supabase's default privileges, and what the linter misses.
Read on · 7 min read -
Supabase RLS policy examples, tested on PostgreSQL 17
Four Supabase row-level security policy sets, tested with Supabase's own roles: own rows, public read, teams without recursion, and admins from the JWT.
Read on · 9 min read -
Supabase RLS policy not working? Ten causes, measured
Why a Supabase row-level security policy returns nothing, fails or leaks, measured on PostgreSQL 17 with Supabase's own roles and auth.uid(): ten causes.
Read on · 9 min read -
Supabase RLS: when (select auth.uid()) helps, measured
auth.uid() against (select auth.uid()) in a Supabase-style RLS policy on PostgreSQL 17, measured: 923 against 42 ms without an index, no difference with one.
Read on · 7 min read -
Supabase Storage RLS: why uploads fail, measured
Which policies on storage.objects a Supabase upload, upsert, download and delete need, measured on PostgreSQL 17 with the SQL the Storage API runs.
Read on · 8 min read -
could not serialize access due to concurrent update
PostgreSQL error 40001 'could not serialize access due to concurrent update', measured on 17: when it fires, why SKIP LOCKED does not avoid it, and the retry.
Read on · 8 min read -
CREATE POLICY IF NOT EXISTS in PostgreSQL: what works
PostgreSQL has no CREATE POLICY IF NOT EXISTS. Three ways to write a repeatable policy migration, measured on PostgreSQL 17 and 18: gaps, locks and races.
Read on · 7 min read -
PostgreSQL idle in transaction: what it holds, what ends it
A PostgreSQL session idle in transaction, measured on 17: what it blocks (locks, ALTER TABLE, vacuum) and how idle_in_transaction_session_timeout ends it.
Read on · 7 min read -
invalid input syntax for type uuid in PostgreSQL, measured
What raised 'invalid input syntax for type uuid' in PostgreSQL 17, measured: which strings cast, 'undefined' from a driver, '' from a setting, and fixes.
Read on · 8 min read -
remaining connection slots are reserved for superuser roles
'remaining connection slots are reserved for roles with the SUPERUSER attribute' (53300), measured on 15–17: who holds the slots and how to free them.
Read on · 8 min read -
stack depth limit exceeded in PostgreSQL: four causes
What raised 'stack depth limit exceeded' in PostgreSQL 17, measured: triggers, recursion, a policy reading its table via a function, long expressions.
Read on · 8 min read -
unrecognized configuration parameter in PostgreSQL
Restoring a pg_dump 17 file into PostgreSQL 16 fails with unrecognized configuration parameter transaction_timeout. Measured fixes, plus four other causes.
Read on · 8 min read -
Rails, ActiveRecord and PostgreSQL RLS, measured
Setting the tenant for PostgreSQL row-level security in Rails 8.1, measured: before_action, a transaction per request, threads in a request, failed writes.
Read on · 7 min read -
Hibernate multi-tenancy and PostgreSQL RLS in Spring Boot
Where to set the tenant for PostgreSQL row-level security in Spring Boot 4 and Hibernate 7, measured: DataSource wrapper, interceptor, @Transactional, provider.
Read on · 8 min read -
TypeORM and PostgreSQL row-level security, measured
Setting the tenant for PostgreSQL row-level security in TypeORM 1.1, measured: dataSource.query, QueryRunner, transactions, and an injected repository.
Read on · 7 min read -
Go, pgx and PostgreSQL row-level security, measured
Setting the tenant for PostgreSQL row-level security in Go with pgx 5.11, measured: pgxpool, PrepareConn hooks, transactions, batches and PgBouncer.
Read on · 10 min read -
ALTER DEFAULT PRIVILEGES not working? What we measured
ALTER DEFAULT PRIVILEGES in PostgreSQL 17, measured: whose new tables it covers, why a per-schema revoke does nothing, what counts as a table, how to list it.
Read on · 9 min read -
PostgreSQL BYPASSRLS: who bypasses row-level security?
BYPASSRLS, table owners, FORCE and superusers in PostgreSQL 17, measured: who sees every row, what role membership passes on, and what RLS never covers.
Read on · 7 min read -
current_setting and set_config in PostgreSQL, measured
What current_setting and set_config do with a custom setting in PostgreSQL 17, measured: NULL or empty string, how long a value lasts, defaults, who may set it.
Read on · 10 min read -
must be owner of table in PostgreSQL: who may alter it?
What raised 'must be owner of table' in PostgreSQL 17, measured: which statements need ownership, which a grant covers, and how tables end up with mixed owners.
Read on · 9 min read -
permission denied for table in PostgreSQL: which grant?
What raised 'permission denied for table', schema and sequence in PostgreSQL 17, measured: the privilege each statement needs, and why default privileges miss.
Read on · 11 min read -
A read-only user in PostgreSQL: what it can still do
Three ways to create a read-only user in PostgreSQL 17, measured: what each still allows, from a write through a function to password verifiers and RLS.
Read on · 9 min read -
PostgreSQL row-level security for SaaS: what we measured
Row-level security for a multi-tenant SaaS on PostgreSQL 17, result by result: what leaks, what it costs, how to set the tenant, and where each test is.
Read on · 7 min read -
infinite recursion detected in policy: causes and fixes
When PostgreSQL 17 raises 'infinite recursion detected in policy for relation', and what each fix costs on a million rows: from 0.09 ms to 6.6 seconds.
Read on · 10 min read -
new row violates row-level security policy: causes, fixes
What raises 'new row violates row-level security policy for table' in PostgreSQL and Supabase, measured: inserts, RETURNING, .select(), upserts and MERGE.
Read on · 10 min read -
Django and PostgreSQL row-level security, measured
Setting the tenant for PostgreSQL row-level security in Django 5.2, measured: persistent connections, the 5.1 pool, ATOMIC_REQUESTS and middleware.
Read on · 7 min read -
Drizzle RLS: PostgreSQL row-level security, measured
PostgreSQL row-level security with Drizzle ORM 0.45, measured: setting the tenant per request, the documented wrapper, and what drizzle-kit leaves out.
Read on · 6 min read -
Laravel and PostgreSQL row-level security, measured
Setting the tenant for PostgreSQL row-level security in Laravel 13, measured: middleware, persistent PDO connections and DB::transaction around a request.
Read on · 6 min read -
Debugging row-level security in PostgreSQL
Row-level security not working in PostgreSQL: why a query returns no rows, or all of them. Five checks and two catalog queries, with the output.
Read on · 7 min read -
PostgreSQL job workers: retries, crashes, tenant context
One worker serving every tenant, measured in PostgreSQL 17 with psycopg: which tenant context outlives the job, why failures go uncounted, what a crash leaves.
Read on · 11 min read -
One partition per tenant in PostgreSQL, measured
List-partitioning by tenant under row-level security, measured in PostgreSQL 17 and 18: 100, 1,000 and 3,000 partitions, planning, locks, adding a tenant.
Read on · 9 min read -
RLS in PostgreSQL: USING vs WITH CHECK on writes
Which writes fail, which silently do nothing and which cross tenants under row-level security, measured in PostgreSQL 17 for six policy setups.
Read on · 7 min read -
PostgreSQL views and row-level security, measured
Which views leak other tenants' rows under row-level security, measured in PostgreSQL 17: view owner, BYPASSRLS, security_invoker, materialized views.
Read on · 6 min read -
Prisma and PostgreSQL row-level security, measured
Setting the tenant for PostgreSQL row-level security in Prisma 7, measured: $executeRaw, batch and interactive transactions, and the client extension.
Read on · 9 min read -
SQLAlchemy and PostgreSQL row-level security, measured
Setting the tenant for PostgreSQL row-level security in SQLAlchemy 2.1, measured: the connection pool, set_config, after_begin and the reset hook.
Read on · 9 min read -
Exporting one tenant with pg_dump and row-level security
pg_dump has no WHERE clause, but row-level security can be one. Tested on PostgreSQL 17: one tenant's rows, the sequence values that leak, restoring under RLS.
Read on · 6 min read -
PgBouncer and RLS: tenant context, SET LOCAL, shared plans
RLS behind PgBouncer in transaction mode, measured: which tenant context leaks, what SET LOCAL does outside a transaction, and one plan shared by tenants.
Read on · 11 min read -
Audit log per tenant in PostgreSQL: what a trigger costs
A trigger-based audit log in PostgreSQL 17, measured: row against statement triggers, full rows against changed columns, and row-level security on the log.
Read on · 11 min read -
Counting per tenant in PostgreSQL: count, estimate, counter
count(*) per tenant in PostgreSQL 17, measured: why it got 5× slower for the largest tenant, when estimates are wrong, and what a counter row costs under load.
Read on · 7 min read -
Deleting one tenant in PostgreSQL: cascade, batch or DROP
Deleting one tenant from a shared PostgreSQL 17 database, measured: cascade, batches or dropping a partition; locks, batch size, disk space, what stays behind.
Read on · 7 min read -
Job queues per tenant in PostgreSQL: the noisy neighbour
One tenant queues 1,000 jobs, ten others five each: FIFO against round-robin with SKIP LOCKED in PostgreSQL 17, measured, plus a 10-second planner trap.
Read on · 8 min read -
Moving one tenant with logical replication row filters
Moving one tenant to its own PostgreSQL 17 database with a row-filtered publication, measured: the replica identity trap, WAL cost, cut-over, sequences.
Read on · 7 min read -
A role per tenant vs a session variable for PostgreSQL RLS
Row-level security in PostgreSQL 17 with a role per tenant or a session variable, measured: SET ROLE at 10,000 roles, PgBouncer, injection, definer functions.
Read on · 7 min read -
Schema migrations on a shared multi-tenant PostgreSQL table
ALTER TABLE on a table every tenant shares, measured on PostgreSQL 17: the lock queue, lock_timeout, rewrites, NOT VALID, and changing tenant_id under RLS.
Read on · 9 min read -
Unique per tenant in PostgreSQL: soft delete and RLS leaks
Unique constraints in multi-tenant PostgreSQL 17, tested: per tenant or global, soft delete, case, NULLs, ON CONFLICT, and what a duplicate-key error reveals.
Read on · 6 min read -
Row-level security performance in PostgreSQL, measured
What an RLS policy costs in PostgreSQL 17: function volatility, the (select …) wrapper, membership subqueries and the leakproof rule that disables your index.
Read on · 9 min read -
Invoice numbers per tenant in PostgreSQL, without gaps
Sequence, max()+1, SERIALIZABLE or a counter row: five ways to number invoices per tenant, measured under load in PostgreSQL 17 for duplicates, gaps and speed.
Read on · 9 min read -
PostgreSQL indexes for multi-tenant SaaS: tenant_id first
Five indexes, 1,000 tenants, one query, measured in PostgreSQL 17: why tenant_id goes first, what RLS does to the plan, and when partitioning pays off.
Read on · 9 min read -
An MCP server for an existing SaaS: 17 tools in production
What we learned from an MCP server on Pilot-Next: 14 read and 3 write tools, an 11 KB tool list, a preview before every invoice, and the date models get wrong.
Read on · 12 min read -
Multi-tenant SaaS on PostgreSQL: six decisions
The six choices a multi-tenant SaaS locks into PostgreSQL: isolation model, RLS, indexes, money, restoring one tenant and migrating at scale. All measured.
Read on · 17 min read -
Row-level security in PostgreSQL: where tenants leak
Turning RLS on takes five lines of SQL. These are the five ways it is silently off afterwards, or leaks around the edges — each one measured in PostgreSQL 17.
Read on · 10 min read -
Money in PostgreSQL: numeric, integer cents or money?
Which PostgreSQL type holds money exactly? numeric, integer cents, bigint and money side by side, with the pitfalls we tested and a query to audit your schema.
Read on · 16 min read -
Multi-tenant architecture: choosing an isolation model
Database per customer, schema per customer or one database with tenant_id and row-level security: the models side by side, and the three questions that decide.
Read on · 12 min read -
Three decisions in a SaaS product you never get to undo
Customer separation, money and permissions. What each of the three costs up front, what it costs afterwards, and how to check your own product in ten minutes.
Read on · 6 min read -
Building software with AI: seven questions to ask
What to ask a firm that builds with AI agents: who owns the code, who is liable, how it gets tested, and whether anyone else can take it over later.
Read on · 8 min read -
Money in a SaaS product: cents, not floats
The second irreversible decision in a SaaS product is about money. Why a floating-point number loses your cents, and where it still goes wrong with cents.
Read on · 8 min read -
Permissions in SaaS: roles, not checkboxes
The third irreversible decision: who may do what. Why a list of checkboxes per user seizes up after twenty customers, and what does work instead.
Read on · 8 min read -
A nightly crew of AI agents: maintenance while you sleep
Every night a crew of agents removes dead code, fills test gaps and measures search visibility. How it is set up, and why it is only safe behind gates.
Read on · 8 min read -
Multi-tenant from day one, or it never gets fixed
Three decisions in a SaaS product are nearly impossible to reverse. Separating customers is the first, and the most expensive one to skip.
Read on · 7 min read -
What building a SaaS product with AI agents really costs
Two products, built with AI coding agents. What went faster than expected, what was more expensive, and the mistake that slipped through three times.
Read on · 9 min read
Let's talk
What are we building?
One conversation is enough to know whether we fit. Tell us what you have in mind — we will tell you how fast it can happen, and whether we are the right people for it.