Skip to content

2025.1.0.0-b108

@fizaaluthra fizaaluthra tagged this 02 Jun 22:48
Summary:
Since commit ccb70d235eb7e1ac4c3d73e5d82565a3e43d0235 adds new counters to the pg_stat_statements struct and changes the file format, we need to bump the pg_stat_statements file header to correctly handle the upgrade from 2.25 to 2.27. We will drop the existing stats after an upgrade from 2.25 to 2.27.

This change will also be backported to 2025.1, so as to preserve stats between 2025.1 and future stable releases (2025.2+).

Specifically:
- 2024.2 -> 2025.1 - stats will not be preserved (a new PG data directory is created as part of YSQL major upgrade)
- 2.25 -> 2.27 - stats will not be preserved (with this change, the old stats file will be discarded)
- 2025.1 -> 2025.2 - stats will be preserved

Specific changes:
- Bump file header to 0x20250425
- Set extended_header_reader (the current reader) as the reader for the new version
- Fix asserts in `extended_header_reader` and `read_entry_hdr` to allow the new version
- Re-introduce the the check for the file header in `pgss_shmem_startup` (removed by commit c55d458af8fd9a45839f3ea9e76d1c4d016cd4b5) since we no longer want to preserve stats when the header is different (i.e., we want to reset them when upgrading to 2.27). In fact, all of the special file reading logic introduced by commit c55d458af8fd9a45839f3ea9e76d1c4d016cd4b5 can be cleaned up in a future revision, as we no longer need more than one file reader.
Jira: DB-16667

Original commit: 3e65363168d40453016c4c8fe0fd8662de0261d8 / D43559

Test Plan:
on a 2.25.0 cluster, run some queries to generate data for pg_stat_statements:
```
yugabyte=# SELECT query, yb_latency_histogram FROM pg_stat_statements;
                         query                         |                  yb_latency_histogram
-------------------------------------------------------+--------------------------------------------------------
 INSERT INTO x VALUES ($1), ($2), ($3)                 | [{"[2.8,3.0)": 1}, {"[4.8,5.2)": 1}]
 DELETE FROM x                                         | [{"[1.4,1.5)": 1}, {"[3.2,3.6)": 1}]
 SELECT * FROM pg_stat_statements                      | [{"[0.3,0.4)": 2}, {"[1.5,1.6)": 1}, {"[1.6,1.8)": 1}]
 CREATE TABLE x (t int)                                | [{"[83.2,89.6)": 1}]
 SELECT * FROM x                                       | [{"[0.7,0.8)": 1}, {"[1.3,1.4)": 1}, {"[1.8,2.0)": 1}]
 SELECT query, total_plan_time FROM pg_stat_statements | [{"[2.0,2.2)": 1}]
(6 rows)

```
restart the cluster and then upgrade to 2.27.

without this patch, the file is read incorrectly and there's a junk entry:

```
yugabyte=# SELECT query, yb_latency_histogram FROM pg_stat_statements;
                           query                            | yb_latency_histogram
------------------------------------------------------------+----------------------
                                                            | []
 SELECT query, yb_latency_histogram FROM pg_stat_statements | []
(2 rows)

```

with this patch, the entry is discarded:

```
yugabyte=# SELECT query, yb_latency_histogram FROM pg_stat_statements;
                           query                            | yb_latency_histogram
------------------------------------------------------------+----------------------
 SELECT query, yb_latency_histogram FROM pg_stat_statements | []
(1 row)

```

Reviewers: kramanathan

Reviewed By: kramanathan

Subscribers: yql

Differential Revision: https://phorge.dev.yugabyte.com/D44375
Assets 2
Loading