Improve purge performance for PostgreSQL with large databases (#133699)

This commit is contained in:
J. Nick Koston
2024-12-20 23:53:15 -10:00
committed by GitHub
parent 02785a4ded
commit 43fab48d4e
5 changed files with 17 additions and 3 deletions

View File

@ -600,6 +600,12 @@ def setup_connection_for_dialect(
execute_on_connection(dbapi_connection, "SET time_zone = '+00:00'")
elif dialect_name == SupportedDialect.POSTGRESQL:
max_bind_vars = DEFAULT_MAX_BIND_VARS
# PostgreSQL does not support a skip/loose index scan so its
# also slow for large distinct queries:
# https://wiki.postgresql.org/wiki/Loose_indexscan
# https://github.com/home-assistant/core/issues/126084
# so we set slow_range_in_select to True
slow_range_in_select = True
if first_connection:
# server_version_num was added in 2006
result = query_on_connection(dbapi_connection, "SHOW server_version")