fix(weather): analyze_all skip_recent check reads both analyze timestamps
pg_stat_user_tables tracks two timestamps — `last_autoanalyze` is only bumped by the autovacuum daemon, while `last_analyze` is bumped by manual ANALYZE statements (including the ones our Task issues). The previous query only filtered on `last_autoanalyze`, so on a re-run within the skip_recent window every manually- analyzed table came back for another ANALYZE pass. Uses `GREATEST(last_analyze, last_autoanalyze)` so fresh manual analyses count as recent.
This commit is contained in:
parent
36049808a4
commit
e192ca3300
1 changed files with 8 additions and 2 deletions
|
|
@ -434,12 +434,18 @@ defmodule Microwaveprop.Weather do
|
||||||
def analyze_all(opts \\ []) do
|
def analyze_all(opts \\ []) do
|
||||||
skip_recent = Keyword.get(opts, :skip_recent_seconds, 6 * 3600)
|
skip_recent = Keyword.get(opts, :skip_recent_seconds, 6 * 3600)
|
||||||
|
|
||||||
|
# `last_autoanalyze` is only set by the autovacuum daemon;
|
||||||
|
# `last_analyze` is set by manual ANALYZE (including our Task
|
||||||
|
# below). Take the newer of the two — otherwise a re-run within
|
||||||
|
# `skip_recent` would re-analyze everything we just did.
|
||||||
q = """
|
q = """
|
||||||
SELECT relname
|
SELECT relname
|
||||||
FROM pg_stat_user_tables
|
FROM pg_stat_user_tables
|
||||||
WHERE schemaname = 'public'
|
WHERE schemaname = 'public'
|
||||||
AND (last_autoanalyze IS NULL
|
AND COALESCE(
|
||||||
OR last_autoanalyze < now() - ($1 || ' seconds')::interval)
|
GREATEST(last_analyze, last_autoanalyze),
|
||||||
|
'epoch'::timestamptz
|
||||||
|
) < now() - ($1 || ' seconds')::interval
|
||||||
ORDER BY n_live_tup ASC
|
ORDER BY n_live_tup ASC
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue