12.5 Auditing what’s stored

Goal: get a high-level picture of what’s in the store.

12.5.1 Count by tag

sudo -u ownsona psql -d ownsona <<'EOF'
SELECT unnest(tags) AS tag, count(*) AS n
FROM memories
WHERE deleted_at IS NULL
GROUP BY 1
ORDER BY n DESC;
EOF

12.5.2 Count by capture mode

How many memories were explicitly requested vs. inferred by the LLM:

SELECT metadata->>'capture_mode' AS mode, count(*)
FROM memories
WHERE deleted_at IS NULL
GROUP BY 1;

12.5.3 Oldest and newest memories

(SELECT id, text, created_at FROM memories WHERE deleted_at IS NULL ORDER BY created_at LIMIT 3)
UNION ALL
(SELECT id, text, created_at FROM memories WHERE deleted_at IS NULL ORDER BY created_at DESC LIMIT 3);

12.5.4 Tombstone history

SELECT id, text, deleted_at, forget_reason, replaced_by_id
FROM memories
WHERE deleted_at IS NOT NULL
ORDER BY deleted_at DESC;

These are operator queries — they bypass the MCP layer entirely, which is exactly the point: they’re for you, not for the LLM.