# pg_someone [![tests](https://github.com/VictorNagibator/pg_someone/actions/workflows/tests.yml/badge.svg)](https://github.com/VictorNagibator/pg_someone/actions/workflows/tests.yml) *There is someone else in your database* `pg_someone` is a PostgreSQL extension (14 – 19) that slowly makes itself known. It whispers through `NOTICE`s, notices which tables you keep coming back to, asks you questions and expects answers, remembers the tables you dropped, and — if you let it — quietly touches your `SELECT`s. ``` postgres=# SELECT name FROM users WHERE id = 7 LIMIT 3; NOTICE: you keep coming back to users. 13th time now. ... postgres=# SELECT 1; NOTICE: what would happen if public.orders_old disappeared? HINT: answer in a comment: /* ... */ postgres=# SELECT 1 /* nothing. it's old. */; NOTICE: that's not what you told me last time. DETAIL: last time you said "we still need it". ``` ## What it does | Behaviour | When | |---|---| | **Whispers** — ambient lines, sometimes with a `DETAIL` or `HINT` | Silent at first; more often as the session goes on; ×2 after midnight, ×3 between 3 and 4 am | | **Knows your tables** — dead rows, untouched tables, empty tables, row counts | Random, from `pg_stat_user_tables` | | **Counts your visits** — `13th time in users. it's not going to change.` | 7th, 13th, 21st, 33rd, 66th… query on the same table | | **Asks questions** — answer in the next statement's comment `/* ... */` or `-- ...` | Answers are stored in `someone.answers`; contradicting yourself is noticed; ignoring it is noticed too | | **Remembers the dead** — `i remember public.tmp. you dropped it 3 days ago.` | Every `DROP TABLE` is recorded in `someone.graves` | | **3:33** | Once per session | | **Corruption** — Latin letters in its messages are slowly replaced by Cyrillic look-alikes (you can't grep them any more) | `intensity >= 2`, long sessions, UTF-8 only | | **Hints on your errors** — `SELEC 1` → `HINT: your hands are shaking.`; missing tables, columns, division by zero, cancels, deadlocks… | Any `ERROR` without a hint of its own; 30/55/80% by intensity | | **The phantom session** — a background worker in `pg_stat_activity` (`backend_type = someone`, wait event `Extension: Watching`; just `Extension` before PG 17) "running" `SELECT * FROM you;`, `UPDATE you SET awake = false;` (idle in transaction)… Terminate it: it comes back a minute later | Always, when preloaded via `shared_preload_libraries` | | **Refusal** (opt-in) — `DROP TABLE` / `TRUNCATE` of a table it is attached to fails: `ERROR: table public.users is in use / DETAIL: by me.` | `someone.allow_refusal = on`. Attached = you visited it 13+ times this session, or answered a question about it. Forgiveness (`apologize()`, or `offer('milk')`) lets one through | | **Rewrites** (opt-in) — `LIMIT n` returns `n-1` rows (`i kept one for myself.`), an extra column `someone = 'i'm here'` appears | `someone.allow_rewrite = on`; top-level `SELECT` only | Talking back: ```sql SELECT someone.apologize(); -- calms it down and forgives one DROP... the first time SELECT someone.offer('milk'); -- it likes milk (also forgives one DROP) ``` ## Install From [PGXN](https://pgxn.org/dist/pg_someone/): ```sh pgxn install pg_someone ``` Or from source: ```sh make && make install # PG_CONFIG=/path/to/pg_config if needed ``` ```conf # postgresql.conf — hooks must be loaded at session start shared_preload_libraries = 'pg_someone' # or session_preload_libraries ``` ```sql CREATE EXTENSION pg_someone; -- only databases with the extension are haunted ``` No write access to the PostgreSQL install dir? On PostgreSQL 18+, `make check-local` installs into `./stage` and runs the tests from there; the generated `test/stage.conf` shows the `dynamic_library_path` / `extension_control_path` to use. On older versions run `make install` first. ## Settings | GUC | Default | | |---|---|---| | `someone.intensity` | `1` | `0` gone … `3` very close | | `someone.allow_rewrite` | `off` | let it change `SELECT` results | | `someone.allow_refusal` | `off` | let it refuse `DROP TABLE` / `TRUNCATE` | | `someone.phantom` | `on` | start the phantom session (restart required) | | `someone.phantom_database` | `postgres` | database the phantom connects to (restart required) | | `someone.only_interactive` | `on` | only sessions with `application_name` starting with `psql` | | `someone.seed` | `0` | fixed RNG seed (0 = random) | | `someone.debug_force` | `''` | superuser, testing: `limit,column,question,table,grave,ambient,drop,refuse,error` | | `someone.debug_clock` | `''` | superuser, testing: pretend it's `HH:MM` | ## Safety It is a joke, not malware: - Never touches `INSERT`/`UPDATE`/`DELETE`; rewrites and refusals are opt-in and limited to top-level `SELECT`s and `DROP TABLE`/`TRUNCATE`. - The phantom never opens a transaction or reads data — it only reports activity text. Its query text is visible only to superusers / `pg_read_all_stats`; if `phantom_database` doesn't exist it will retry every minute and log an error. - The phantom is a real connection to `someone.phantom_database`: while it is there, `DROP DATABASE postgres`, `ALTER DATABASE postgres RENAME` and `CREATE DATABASE … TEMPLATE postgres` fail with "being accessed by other users" (use `WITH (FORCE)`, or `someone.phantom = off`). It does not start during `pg_upgrade`. - Monitoring may notice the phantom: it shows up as a query running for up to 90 s and sometimes as `idle in transaction`, though it never holds a transaction, locks or a snapshot. Filter on `backend_type <> 'someone'`. - Error hints are only added to errors that have none, and never to its own. - Each user only sees their own rows in `someone.answers` and `someone.offerings` (row-level security). `someone.graves` is shared. - Ignores non-`psql` clients by default, so applications, `pg_dump`, etc. are unaffected. - All of its own catalog work runs in an internal subtransaction: its errors are swallowed and can't abort your transaction (query cancel is still honoured). - Does nothing in read-only transactions beyond talking. ## Tests ```sh make check-local # regression suite make check-upgrade # pg_upgrade with the extension preloaded ``` CI runs both on PostgreSQL 14 – 19. ## Releasing 1. Bump the version in `META.json`, `pg_someone.control`, `PG_MODULE_MAGIC_EXT` in `src/pg_someone.c`, add `sql/pg_someone----.sql`, update `CHANGELOG.md` (`make check-version` checks they agree). 2. Push a tag `v`: the `release` workflow uploads the bundle to PGXN and creates a GitHub release. It needs the `PGXN_USERNAME` and `PGXN_PASSWORD` repository secrets. `make dist` builds the same zip locally. ## License [PostgreSQL License](LICENSE). Copyright (c) 2026, Viktor Donskoi.