From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Tyler <tyhou13@gmx.com>
To: pgsql-bugs@lists.postgresql.org
Subject: Re: Column changes such as an increase in varchar size, can cause extremely slow queries, and postgres should run analyze automatically.
Date: Fri, 01 Nov 2024 07:32:28 +0100
Message-ID: <3a24172c1ed0082e279905392bcd46e3062f81e5.camel@cybertec.at> (raw)
In-Reply-To: <263af164-52f5-4b9c-bac3-5309795fe802@gmx.com>
References: <263af164-52f5-4b9c-bac3-5309795fe802@gmx.com>
On Thu, 2024-10-31 at 14:34 -0400, Tyler wrote:
> In our project lemmy, we recently had a production breaking bug causing extremely
> slow queries to one of our tables.
>
> Finally after a lot of testing, we narrowed it down to a migration that increased
> the size of a varchar column meant to store URL data.
>
> This increases the url column from 512 -> 2000 characters.
>
> ALTER TABLE post
> ALTER COLUMN url TYPE varchar(2000);
>
> We finally realized that running this simple query manually, fixed the issue:
>
> `ANALYZE post (url);`
>
> I'm sure we're not the only ones to experience this potentially production-breaking bug, and postgres should
> probably automatically re-run analyze on columns for tables that have a large number of rows, that are changed.
>
> For more context, see: https://github.com/LemmyNet/lemmy/pull/5148
I don't know if that should be considered a bug, but I sympathize with the complaint.
At the very least we should document on
https://www.postgresql.org/docs/current/routine-vacuuming.html#VACUUM-FOR-STATISTICS
that operations like ALTER TABLE or CREATE INDEX don't trigger autoanalyze.
Would it be an option to clear pg_class.reltuples and pg_stat_all_tables.n_mod_since_analyze
whenever the statistics for a table are cleared? Then autoanalyze would trigger after 50
modifications.
Yours,
Laurenz Albe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: laurenz.albe@cybertec.at, tyhou13@gmx.com, pgsql-bugs@lists.postgresql.org
Subject: Re: Column changes such as an increase in varchar size, can cause extremely slow queries, and postgres should run analyze automatically.
In-Reply-To: <3a24172c1ed0082e279905392bcd46e3062f81e5.camel@cybertec.at>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox