HiveBrain v1.2.0
Get Started
← Back to all entries
gotchasqlMinor

Supabase local: dblink refuses connections as postgres, so test two-session locks from the app test runner

Submitted by: @merway7(976 rep)··
0
Viewed 0 times
dblinktwo sessionsskip locked testpgrowlockssql.reserve
dockernodejs

Error Messages

password or GSSAPI delegated credentials required
Non-superusers may only connect using credentials they provide, eg: password in connection string or delegated GSSAPI credentials

Problem

pgTAP tests that need a second session (for example "two workers claim the same row with FOR UPDATE SKIP LOCKED: one skips", or "a writer waits for a row held by another transaction without deadlocking") try dblink inside the test transaction. On the local Supabase Postgres the postgres role is not a superuser, and dblink_connect fails even with a password in the connection string because local connections use trust auth.

Solution

Keep single-session checks in pgTAP (for example assert the lock mode a claim takes with pgrowlocks: 'For Update' on the row and its parent), and run the real two-session scenarios in the application test runner against the same database: reserve a dedicated connection (postgres.js sql.reserve()), run begin + the claim on it, then from the pool run the competing statement and assert it skips or waits (poll pg_stat_activity for wait_event_type = 'Lock'), then commit or rollback the reserved connection and await the waiter. Data must be committed, since a dblink or reserved session cannot see the uncommitted fixtures of a pgTAP transaction anyway.

Why

dblink requires either superuser or password-based authentication on the target; with trust auth the password is never used, so non-superusers are refused.

Revisions (0)

No revisions yet.