Skip to content

Postgres Notes

Robert Konigsberg edited this page Apr 4, 2023 · 3 revisions

Broken purges

Some games are only partially purged in Postgres. It seems to be due to an active game where people take actions that save rows even though the underlying tables were purged.

A query that helps find those games is the following.

SELECT
  all_games.game_id
FROM
  (SELECT distinct game_id FROM games) AS all_games
LEFT JOIN
  (SELECT game_id FROM games WHERE save_id = 0) AS initial_rows
ON
  initial_rows.game_id = all_games.game_id
WHERE
  initial_rows.game_id IS NULL;

After which you can manually delete games with commands like

DELETE FROM games where game_id='...'; and DELETE FROM participants where game_id='...';

Obviously those two commands can link up with the SELECT statement above if necessary.

Vacuum

Vacuum is supposed to reclaim space, but it doesn't seem to be terribly efficient. I mean, it works, but it doesn't seem to release enough to provide reasonable efficient row counts.

Some notes:

More on Row Counts