Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Periodically clear postgres ccnew indexes. #2431

Closed
dessalines opened this issue Sep 7, 2022 · 0 comments
Closed

Periodically clear postgres ccnew indexes. #2431

dessalines opened this issue Sep 7, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@dessalines
Copy link
Member

In order to do lemmy's hot sorting, it needs to periodically rebuild indexes on the post_aggregates. Unfortunately this occasionally leaves behind extra unused "phantom" indexes that postgres titles idx_....ccnew1, idx....ccnew1. I'm not sure why or under what circumstance it creates these.

These pointless indexes can fill the database, on lemmy.ml they took up 11GB.

To solve this, do a migration to add a "drop_ccnew_indexes()" postgres function. Then periodically run this function in lemmy's recurring jobs.

The function:

CREATE OR REPLACE FUNCTION drop_ccnew_indexes() RETURNS INTEGER AS $$
DECLARE
i RECORD;
BEGIN
  FOR i IN
    (SELECT relname FROM pg_class WHERE relname like '%ccnew%')
    LOOP
      EXECUTE 'DROP INDEX ' || i.relname;
    END LOOP;
    RETURN 1;
  END;
$$ LANGUAGE plpgsql;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant