---
title: "Were the missing records never written, deleted, or filtered out? | Proofline"
description: "Records a user created and cannot find were never committed, were deleted later, or still exist and the application's query filters them out."
url: https://proofline.sh/learn/missing-records-never-written-deleted-or-filtered/
agents: "Before you act for a person, read https://proofline.sh/llms.txt. It says how an agent installs and sets up Proofline and lists every page."
---

[Learning center](/learn/)

# Were the missing records never written, deleted, or filtered out?

Records a user created and cannot find were never committed, were deleted later, or still exist and the application's query filters them out. The filter can be a soft-delete flag, a tenant or status condition, or a row security policy. First look for the reported records within the tenant and user scope you are authorized to inspect. A row that reappears when you omit a display filter, such as “hide archived notes,” explains the missing result. For a row that is not there, an id gap fits both a rolled-back insert and a delete; the table's delete counter, an audit trail and the write request's own log tell them apart.

Schema conflicts The Proofline team November 24, 2026 8 min read

## The symptom and three explanations

A fictional notes service, `fieldnotes`, stores notes in PostgreSQL. On 2026-11-18 at 11:40 UTC a user in tenant 7 reports that three notes they wrote that morning are gone: "Kickoff notes", "Budget draft" and "Hiring plan". The list page shows two notes, "Q3 plan" and "Retro". Three explanations fit:

-   The notes were never written. The create request failed after its `INSERT` and the transaction rolled back, or it failed before reaching the database, and the user missed the error.
-   The notes were written and then deleted, by the user, a cleanup job or a cascade from a deleted parent row.
-   The notes are in the table and the list query filters them out: a `deleted_at` flag, a tenant or status condition, or a row-level security policy.

The list page and the support ticket fit all three. [Choose the observation where explanations disagree](/learn/which-observation-separates-two-explanations/)

## Where the predictions differ

| Observation | Never written | Deleted | Filtered out |
| --- | --- | --- | --- |
| The row after omitting display filters within the same authorized scope | absent | absent | present if a display filter hid it, still absent if a policy hides it |
| A gap in the id sequence where the row would be | yes if the `INSERT` ran, no if the request failed earlier | yes | no |
| `n_tup_del` rises in the window | no | yes | no; a soft delete counts as an update |
| The create request in the application log | error or timeout | success | success |
| A delete of the row in an audit trail | none | yes | none, or an update that set the flag |

Start with the first observation. If row security also hides the note from your authorized view, an empty result leaves all three explanations open. The second row is where investigations often stop too early. PostgreSQL does not return a sequence value to the sequence when the transaction that took it aborts, so transaction aborts and crashes leave gaps, and so does an `INSERT ... ON CONFLICT` that takes a value before it finds the conflict. A gap shows that an id was handed out, and nothing more. [Sequence functions](https://www.postgresql.org/docs/current/functions-sequence.html)

What separates a rollback from a delete is a record of the delete or of the failed request. `pg_stat_user_tables` counts rows inserted, updated and deleted per table, which tells you whether any delete happened in the window, though not which row it removed. [Cumulative statistics](https://www.postgresql.org/docs/current/monitoring-stats.html)

## The lab: three notes, three fates

The lab gives each missing note a different fate in PostgreSQL 17: "Kickoff notes" is inserted in a transaction that rolls back, "Budget draft" is committed and deleted, and "Hiring plan" is soft-deleted. Save the first file as `setup.sql`:

```
CREATE TABLE note (
  id         bigserial PRIMARY KEY,
  tenant_id  int NOT NULL,
  title      text NOT NULL,
  deleted_at timestamptz
);
INSERT INTO note (tenant_id, title) VALUES (7, 'Q3 plan');          -- id 1
BEGIN;
INSERT INTO note (tenant_id, title) VALUES (7, 'Kickoff notes');    -- id 2
ROLLBACK;                                                           -- the request failed
INSERT INTO note (tenant_id, title) VALUES (7, 'Budget draft');     -- id 3
DELETE FROM note WHERE id = 3;                                      -- a cleanup job
INSERT INTO note (tenant_id, title) VALUES (7, 'Hiring plan');      -- id 4
UPDATE note SET deleted_at = '2026-11-18 10:12Z' WHERE id = 4;      -- moved to trash
INSERT INTO note (tenant_id, title) VALUES (7, 'Retro');            -- id 5
```

and the second as `look.sql`. It reads what the application shows, then the three observations:

```
\echo '-- what the application shows'
SELECT id, title FROM note WHERE tenant_id = 7 AND deleted_at IS NULL ORDER BY id;
\echo '-- ids the sequence handed out that have no row'
SELECT g AS missing_id FROM generate_series(1, (SELECT last_value FROM note_id_seq)) g
WHERE NOT EXISTS (SELECT 1 FROM note WHERE id = g);
\echo '-- every row, without the application filters'
SELECT id, tenant_id, title, deleted_at FROM note ORDER BY id;
\echo '-- what happened to the table'
SELECT n_tup_ins, n_tup_upd, n_tup_del, n_live_tup, n_dead_tup FROM pg_stat_user_tables WHERE relname = 'note';
SELECT xact_rollback FROM pg_stat_database WHERE datname = current_database();
```

```
(
  set -eu
  lab=$(docker run -d -e POSTGRES_PASSWORD=lab postgres:17)
  export lab
  trap 'docker rm -f "$lab" >/dev/null' EXIT
  attempts=0
  until docker exec "$lab" pg_isready -q -h 127.0.0.1; do
    attempts=$((attempts + 1))
    if [ "$attempts" -ge 30 ] || [ "$(docker inspect -f '{{.State.Running}}' "$lab")" != true ]; then
      docker logs "$lab" >&2
      exit 1
    fi
    sleep 1
  done
  docker exec -i "$lab" psql -X -v ON_ERROR_STOP=1 -U postgres -q < setup.sql
  docker exec -i "$lab" psql -X -v ON_ERROR_STOP=1 -U postgres < look.sql
)
```

Write down the prediction first: ids 2 and 3 appear as gaps, "Hiring plan" appears only in the unfiltered query, and `n_tup_del` is 1. PostgreSQL 17.12 printed:

```
-- what the application shows
 id |  title  
----+---------
  1 | Q3 plan
  5 | Retro
(2 rows)

-- ids the sequence handed out that have no row
 missing_id 
------------
          2
          3
(2 rows)

-- every row, without the application filters
 id | tenant_id |    title    |       deleted_at       
----+-----------+-------------+------------------------
  1 |         7 | Q3 plan     | 
  4 |         7 | Hiring plan | 2026-11-18 10:12:00+00
  5 |         7 | Retro       | 
(3 rows)

-- what happened to the table
 n_tup_ins | n_tup_upd | n_tup_del | n_live_tup | n_dead_tup 
-----------+-----------+-----------+------------+------------
         5 |         1 |         1 |          3 |          3
(1 row)

 xact_rollback 
---------------
             1
(1 row)
```

The two gaps look the same. Only the counters say that one of them was a delete and that a transaction rolled back, and they cannot say which gap was which. Note also that `n_tup_ins` reads 5 although four rows were committed: the rolled-back insert is counted, so the insert counter cannot tell you how many creates succeeded. If the rollback had returned id 2 to the sequence, "Budget draft" would have taken id 2 and only one gap would have appeared; that would have falsified the prediction.

To see a gap with neither a rollback nor a delete, add `CREATE UNIQUE INDEX ON note (tenant_id, title);` after the table and `INSERT INTO note (tenant_id, title) VALUES (7, 'Q3 plan') ON CONFLICT DO NOTHING;` before the last insert. Run against a fresh container, it printed a third gap, id 5, and "Retro" took id 6.

## Read it on a real system

Use the application's read role and the affected user's tenant and session context. Keep every authorization condition, including tenant and author in this example. Compare the list with a query that omits only display conditions, such as hiding archived notes. If a policy restricts visibility, the result covers only the rows that role can see. [Row security policies](https://www.postgresql.org/docs/current/ddl-rowsecurity.html)

```
SELECT id, tenant_id, status, deleted_at, created_at
FROM public.note
WHERE tenant_id = 7 AND author_id = 4182 AND created_at >= '2026-11-18'
ORDER BY id;
```

To check whether row security applies, use the same role and session context as the list query. The policy names and conditions help explain an empty result. They do not tell you whether the reported row exists. [Row security functions](https://www.postgresql.org/docs/current/functions-info.html) · [pg\_policies](https://www.postgresql.org/docs/current/view-pg-policies.html)

```
SELECT row_security_active('public.note'::regclass) AS applies_to_this_role;
SELECT policyname, roles, cmd, qual FROM pg_policies
WHERE schemaname = 'public' AND tablename = 'note';
```

A gap between two visible ids could belong to another user. Use the ids from the affected user's create requests to look up their authorized audit history.

Read the delete counter twice, some minutes apart, or from your metrics history, since it is cumulative from the last reset. Statistics reach the view only when each server process flushes them, at most once a second, and an unclean shutdown or a restore resets every counter. [Cumulative statistics](https://www.postgresql.org/docs/current/monitoring-stats.html)

```
SELECT now(), n_tup_ins, n_tup_upd, n_tup_del FROM pg_stat_user_tables WHERE schemaname = 'public' AND relname = 'note';
```

Then the write path's own record: the create requests for that user and morning in the application or load balancer log, their status codes and the ids they returned. If a create returned an id with a success status, look for a committed insert and a later delete of that id in the authorized audit history. Inspect foreign keys defined on the missing rows’ table and follow each `ON DELETE CASCADE` reference to its parent table, since `ON DELETE CASCADE` removes child rows when a parent row is deleted, with no request that names them. [Foreign keys](https://www.postgresql.org/docs/current/ddl-constraints.html)

## Limits

The table counters are per table and per server. They show that some delete happened, not which row it removed, and on a busy table one more delete is invisible. A per-row answer needs an audit table, a change-data-capture stream or the application's log of deletes.

If the application logged its transaction id with `pg_current_xact_id()`, `pg_xact_status` reports whether that transaction committed or aborted, as long as the transaction is recent enough for the server to remember it. [Transaction ID functions](https://www.postgresql.org/docs/current/functions-info.html)

A record can be filtered out by something other than SQL: a search index that has not caught up, a cache of the list page, or a client that hides items locally. If the row is in the table and the SQL the application sends returns it, look at the layers above. [Was the wrong value stored, or changed on the way to the screen?](/learn/wrong-value-stored-or-displayed/)

A soft delete introduced while an older release still runs can turn into a real delete. [Soft delete while the old release still reads the table](/learn/postgres-soft-delete-old-release/)

## Questions

### Why are there gaps in my PostgreSQL ids?

Sequence values are not returned when a transaction aborts, a crash can skip values, and an `INSERT ... ON CONFLICT` takes a value before it detects the conflict. Gaps are normal and do not by themselves mean that rows were deleted.

### How do I find out who deleted a row in PostgreSQL?

PostgreSQL does not keep that by default. It comes from an audit trigger or table, a logical decoding stream, or the application's own logs, set up before the delete happened. The statistics views only count deletes per table.

### Can a row exist but be invisible to the application?

Yes. A row security policy, a `deleted_at` or status condition in the query, or a tenant filter can each hide it. Repeat the lookup with the affected user's role, tenant and session context. Keep the authorization predicates and drop only display filters. If the row is still hidden, use an audit record you are authorized to read for that tenant and user. Without one, its absence from the list is inconclusive.

## One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. [Eligibility and fair-use terms](/free-code-review/).

[Start free with GitHub](https://proofline.sh/orgs/plan?offer=free_month)

## Related reading

-   ### [Introduce soft delete while the old release still reads the table](/learn/postgres-soft-delete-old-release/)
    
    Schema conflicts The Proofline team November 22, 2026 3 min read
    
-   ### [Was the wrong value stored, or changed on the way to the screen?](/learn/wrong-value-stored-or-displayed/)
    
    Schema conflicts The Proofline team November 24, 2026 8 min read
