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
The recorder.states
table does not have index on old_state_id
column
#44736
Comments
It looks like the database was created before #43610 and somehow didn't get the Edit: it looks like we did add an index on |
The index is required otherwise in some cases for some DB FK will fail to be created, or in other it will be super slow to delete due to having to perform sequential scan instead of index scan on data removal. We need to check if As for the FK, this is great. I will check it. |
Interesting. I also checked if my install has Edit: Looking at this https://github.com/home-assistant/core/pull/43610/files#diff-b13fb7a9fcbe98090c51f229ca8305a0690ae42a633346b177574ee43b3a31c8R235. I don't really see anything that would set FK constraint to |
Its likely postgresql might have some type of default that prevents I don't have a working postgresql setup at the moment so its not something I can validate right now. I'll leave the linked PR as a draft and see why It would be helpful to know which version of postgresql you are running. |
@bdraco I use |
@bdraco Thank you for a quick fix :) |
@bdraco I'm seeing the errors below when starting Home Assistant. I use Microsoft SQL Server for my recorder database. Will the fix in #44757 also address this FK issue in MS SQL? 1/8/2021 12:06:22 PM2021-01-08 17:06:22 ERROR (MainThread) [homeassistant.setup] Setup of recorder is taking longer than 300 seconds. Startup will proceed without waiting any longer |
@sqldiablo This issue has been fixed, closed and handled. If you have a new issue, please open up a new issue accordingly. Thanks 👍 |
I was just wanting to know if the fix in the PR targets MS SQL as well, as it looks like it's specifically targeting MySQL and Postgres. If @bdraco lets me know it won't fix the issue in MS SQL as well, then I'll be glad to open a new issue. I just didn't want to create issue spam if my issue is already fixed by the PR. |
You are now bumping a closed issue, possibly polluting it with unrelated information. Your data is not fully complete, as you are not using an issue template and you are above all pinging and mentioning people (which one should generally not). Lastly, closed issues are not tracked anymore and notify all participants, possibility unessesarry. Could you just, please, raise a new issue instead? Thanks 👍 |
The problem
I have serious problems removing data from PSQL with
recorder:
.It appears that this is due to amount of records stored, and size of data, it simply takes ages to execute:
I looked at indexes of the questioned tables, and they current look following:
Looking at data structure it appears the following:
states.old_state_id
has FK, but lacks an index causing the need to load the whole table on the object removal due to FKstates.event_id
andstates.old_state_id
FK is a constraint validation, but does not haveON DELETE SET NULL
set which results in blockingDELETEs
from being executedThe above seems to prevent timely removal of data, causing extensive time to run
DELETE
, second crashing thisDELETE
due to FK violations.I run the following commands to remedy and alter DB structure, and after doing this deletes are successfully executed.
Environment
armv7l
via official Docker ImageProblem-relevant
configuration.yaml
Traceback/Error logs
Additional information
The text was updated successfully, but these errors were encountered: