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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Activity table not being indexed #2636

Closed
HorseJump opened this issue Dec 30, 2022 · 6 comments
Closed

Activity table not being indexed #2636

HorseJump opened this issue Dec 30, 2022 · 6 comments
Labels
bug Something isn't working

Comments

@HorseJump
Copy link

Found a bug? Please fill out the sections below. 馃憤

Issue Summary

A summary of the bug.
SELECT statements are taking a long time (> 5000ms) to complete at times. Appears that Activity table isn't being indexed.

Technical details

Logs:
postgres_1 | 2022-12-16 17:27:52.887 UTC [11973] LOG: duration: 5010.355 ms execute __diesel_stmt_31: SELECT "activity"."id", "activity"."data", "activity"."local", "activity"."published", "activity"."updated", "activity"."ap_id", "activity"."sensitive" FROM "activity" WHERE "activity"."ap_id" = $1 LIMIT $2
postgres_1 | 2022-12-16 17:27:52.887 UTC [11973] DETAIL: parameters: $1 = 'https://midwest.social/activities/create/c922b6e1-1e00-4d85-8a8f-374bdfcf76c9', $2 = '1'
postgres_1 | 2022-12-16 17:29:00.533 UTC [11973] LOG: duration: 5360.124 ms execute __diesel_stmt_31: SELECT "activity"."id", "activity"."data", "activity"."local", "activity"."published", "activity"."updated", "activity"."ap_id", "activity"."sensitive" FROM "activity" WHERE "activity"."ap_id" = $1 LIMIT $2
postgres_1 | 2022-12-16 17:29:00.533 UTC [11973] DETAIL: parameters: $1 = 'https://midwest.social/activities/create/c922b6e1-1e00-4d85-8a8f-374bdfcf76c9', $2 = '1'
postgres_1 | 2022-12-16 17:29:26.750 UTC [13649] LOG: duration: 5268.068 ms execute __diesel_stmt_17: SELECT "activity"."id", "activity"."data", "activity"."local", "activity"."published", "activity"."updated", "activity"."ap_id", "activity"."sensitive" FROM "activity" WHERE "activity"."ap_id" = $1 LIMIT $2
postgres_1 | 2022-12-16 17:29:26.750 UTC [13649] DETAIL: parameters: $1 = 'https://midwest.social/activities/create/c922b6e1-1e00-4d85-8a8f-374bdfcf76c9', $2 = '1'
postgres_1 | 2022-12-16 17:29:26.911 UTC [11973] LOG: duration: 5080.917 ms execute __diesel_stmt_31: SELECT "activity"."id", "activity"."data", "activity"."local", "activity"."published", "activity"."updated", "activity"."ap_id", "activity"."sensitive" FROM "activity" WHERE "activity"."ap_id" = $1 LIMIT $2
postgres_1 | 2022-12-16 17:29:26.911 UTC [11973] DETAIL: parameters: $1 = 'https://midwest.social/activities/create/c922b6e1-1e00-4d85-8a8f-374bdfcf76c9', $2 = '1'
postgres_1 | 2022-12-16 17:30:06.950 UTC [11973] LOG: duration: 5306.031 ms execute __diesel_stmt_31: SELECT "activity"."id", "activity"."data", "activity"."local", "activity"."published", "activity"."updated", "activity"."ap_id", "activity"."sensitive" FROM "activity" WHERE "activity"."ap_id" = $1 LIMIT $2
postgres_1 | 2022-12-16 17:30:06.950 UTC [11973] DETAIL: parameters: $1 = 'https://midwest.social/activities/like/e169df97-63a0-4eee-ab8c-045b70c6195d', $2 = '1'
postgres_1 | 2022-12-16 17:30:08.674 UTC [13649] LOG: duration: 5065.262 ms execute __diesel_stmt_17: SELECT "activity"."id", "activity"."data", "activity"."local", "activity"."published", "activity"."updated", "activity"."ap_id", "activity"."sensitive" FROM "activity" WHERE "activity"."ap_id" = $1 LIMIT $2
postgres_1 | 2022-12-16 17:30:08.674 UTC [13649] DETAIL: parameters: $1 = 'https://midwest.social/activities/like/e169df97-63a0-4eee-ab8c-045b70c6195d', $2 = '1'
postgres_1 | 2022-12-16 17:30:41.894 UTC [13649] LOG: duration: 5249.674 ms execute __diesel_stmt_17: SELECT "activity"."id", "activity"."data", "activity"."local", "activity"."published", "activity"."updated", "activity"."ap_id", "activity"."sensitive" FROM "activity" WHERE "activity"."ap_id" = $1 LIMIT $2
postgres_1 | 2022-12-16 17:30:41.894 UTC [13649] DETAIL: parameters: $1 = 'https://midwest.social/activities/like/e169df97-63a0-4eee-ab8c-045b70c6195d', $2 = '1'
postgres_1 | 2022-12-16 17:30:44.768 UTC [11973] LOG: duration: 5025.025 ms execute __diesel_stmt_31: SELECT "activity"."id", "activity"."data", "activity"."local", "activity"."published", "activity"."updated", "activity"."ap_id", "activity"."sensitive" FROM "activity" WHERE "activity"."ap_id" = $1 LIMIT $2
postgres_1 | 2022-12-16 17:30:44.768 UTC [11973] DETAIL: parameters: $1 = 'https://midwest.social/activities/like/e169df97-63a0-4eee-ab8c-045b70c6195d', $2 = '1'

@HorseJump HorseJump added the bug Something isn't working label Dec 30, 2022
@Nutomic
Copy link
Member

Nutomic commented Jan 2, 2023

You can fix this by adding a new sql migration: https://github.com/LemmyNet/lemmy/tree/main/migrations

@HorseJump
Copy link
Author

Any idea why it would be running the same query 4 times in a row?

@Nutomic
Copy link
Member

Nutomic commented Jan 2, 2023

Maybe that url was federated to a few different instances, and they all made requests to resolve the data. Or the request timed out and was retried.

@HorseJump
Copy link
Author

Oh OK. I thought there might be some bug that is causing it to do that and taking up resources.

I unfortunately don't know how to write sql migrations.

@dessalines
Copy link
Member

This index should already exist. Run the following command in postgres: \d idx_activity_ap_id

If it doesn't give you any result, then your database got into a weird state with potentially lots of missing indexes.

@HorseJump
Copy link
Author

HorseJump commented Jan 3, 2023

Yeah, that gives no results. Now that I think about it I don't think this started happening until after I migrated to postgres 14 from 12.

@Nutomic Nutomic closed this as completed Jan 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants