Commit 36e3e30
committed
[BACKPORT 2025.2][yugabyte#29080] YSQL: add debug log for relcache
Summary:
The stacktrace of the core dump:
```
(lldb) bt all
* thread #1, name = 'postgres', stop reason = signal SIGSEGV: address not mapped to object
* frame #0: 0x0000aaaac59fb720 postgres`FreeTupleDesc [inlined] GetMemoryChunkContext(pointer=0x0000000000000000) at memutils.h:141:12
frame #1: 0x0000aaaac59fb710 postgres`FreeTupleDesc [inlined] pfree(pointer=0x0000000000000000) at mcxt.c:1500:26
frame #2: 0x0000aaaac59fb710 postgres`FreeTupleDesc(tupdesc=0x000013d7fd8dccc8) at tupdesc.c:326:5
frame #3: 0x0000aaaac61c7204 postgres`RelationDestroyRelation(relation=0x000013d7fd8dc9a8, remember_tupdesc=false) at relcache.c:4577:4
frame #4: 0x0000aaaac5febab8 postgres`YBRefreshCache at relcache.c:5216:3
frame #5: 0x0000aaaac5feba94 postgres`YBRefreshCache at postgres.c:4442:2
frame #6: 0x0000aaaac5feb50c postgres`YBRefreshCacheWrapperImpl(catalog_master_version=0, is_retry=false, full_refresh_allowed=true) at postgres.c:4570:3
frame #7: 0x0000aaaac5feea34 postgres`PostgresMain [inlined] YBRefreshCacheWrapper(catalog_master_version=0, is_retry=false) at postgres.c:4586:9
frame #8: 0x0000aaaac5feea2c postgres`PostgresMain [inlined] YBCheckSharedCatalogCacheVersion at postgres.c:4951:3
frame #9: 0x0000aaaac5fee984 postgres`PostgresMain(dbname=<unavailable>, username=<unavailable>) at postgres.c:6574:4
frame #10: 0x0000aaaac5efe5b4 postgres`BackendRun(port=0x000013d7ffc06400) at postmaster.c:4995:2
frame #11: 0x0000aaaac5efdd08 postgres`ServerLoop [inlined] BackendStartup(port=0x000013d7ffc06400) at postmaster.c:4701:3
frame #12: 0x0000aaaac5efdc70 postgres`ServerLoop at postmaster.c:1908:7
frame #13: 0x0000aaaac5ef8ef8 postgres`PostmasterMain(argc=<unavailable>, argv=<unavailable>) at postmaster.c:1562:11
frame #14: 0x0000aaaac5ddae1c postgres`PostgresServerProcessMain(argc=25, argv=0x000013d7ffe068f0) at main.c:213:3
frame #15: 0x0000aaaac59dee38 postgres`main + 36
frame #16: 0x0000ffff9f606340 libc.so.6`__libc_start_call_main + 112
frame #17: 0x0000ffff9f606418 libc.so.6`__libc_start_main@@GLIBC_2.34 + 152
frame #18: 0x0000aaaac59ded34 postgres`_start + 52
```
It is related to invalidation message. The test involves concurrent DDL execution without object
locking.
I added a few logs to help to debug this issue.
Original commit: 506e44e / D48114
Test Plan:
(1)
Append to the end of file ./build/latest/postgres/share/postgresql.conf.sample:
```
yb_debug_log_catcache_events=1
log_min_messages=DEBUG1
```
(2) Create a RF-1 cluster
```
./bin/yb-ctl create --rf 1
```
(3) Run the following example via ysqlsh:
```
-- === 1. SETUP ===
DROP TABLE IF EXISTS accounts_timetravel;
CREATE TABLE accounts_timetravel (
id INT PRIMARY KEY,
balance INT,
last_updated TIMESTAMPTZ
);
INSERT INTO accounts_timetravel VALUES (1, 1000, now());
\echo '--- 1. Initial Data (The Past) ---'
SELECT * FROM accounts_timetravel;
-- Wait 2 seconds
SELECT pg_sleep(2);
-- === 2. CAPTURE THE "PAST" HLC TIMESTAMP ===
--
-- *** THIS IS THE FIX ***
-- Get the current time as seconds from the Unix epoch,
-- multiply by 1,000,000 to get microseconds,
-- and cast to a big integer.
--
SELECT (EXTRACT(EPOCH FROM now())*1000000)::bigint AS snapshot_hlc \gset
SELECT :snapshot_hlc;
\echo '--- (Snapshot HLC captured) ---'
SELECT * FROM pg_yb_catalog_version;
-- Wait 2 more seconds
SELECT pg_sleep(2);
-- === 3. UPDATE THE DATA ===
UPDATE accounts_timetravel SET balance = 500, last_updated = now() WHERE id = 1;
\echo '--- 2. New Data (The Present) ---'
SELECT * FROM accounts_timetravel;
CREATE TABLE foo(id int);
-- increment the catalog version
ALTER TABLE foo ADD COLUMN val TEXT;
SELECT * FROM pg_yb_catalog_version;
-- === 4. PERFORM THE TIME-TRAVEL QUERY ===
--
-- Set our 'read_time_guc' variable to the HLC value
--
\set read_time_guc :snapshot_hlc
\echo '--- 3. Time-Travel Read (Querying the Past) ---'
\echo 'Setting yb_read_time to HLC (microseconds):' :read_time_guc
-- This will now be interpolated correctly and will succeed.
SET yb_read_time = :read_time_guc;
-- This query will now correctly read the historical data
SELECT * FROM accounts_timetravel;
SELECT * FROM pg_yb_catalog_version;
-- === 5. CLEANUP ===
RESET yb_read_time;
\echo '--- 4. Back to the Present ---'
SELECT * FROM accounts_timetravel;
DROP TABLE accounts_timetravel;
```
(4) Look at the postgres log for the following samples:
```
2025-11-07 18:31:06.223 UTC [3321231] LOG: Preloading relcache for database 13524, session user id: 10, yb_read_time: 0
```
```
2025-11-07 18:31:06.303 UTC [3321231] LOG: Building relcache entry for pg_index (oid 2610) took 785 us
```
```
2025-11-07 18:31:09.265 UTC [3321221] LOG: Rebuild relcache entry for accounts_timetravel (oid 16384)
```
```
2025-11-07 18:31:09.525 UTC [3321221] LOG: Delete relcache entry for accounts_timetravel (oid 16384)
```
```
2025-11-07 18:31:14.035 UTC [3321221] DEBUG: Setting yb_read_time to 1762540271568993
```
```
2025-11-07 18:31:14.037 UTC [3321221] LOG: Preloading relcache for database 13524, session user id: 13523, yb_read_time: 1762540271568993
```
```
2025-11-07 18:31:14.183 UTC [3321221] DEBUG: Setting yb_read_time to 0
```
Reviewers: #db-approvers, kfranz
Reviewed By: kfranz
Subscribers: yql, jason
Differential Revision: https://phorge.dev.yugabyte.com/D482161 parent fa6ea17 commit 36e3e30
2 files changed
Lines changed: 26 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
| 120 | + | |
120 | 121 | | |
121 | 122 | | |
122 | 123 | | |
| |||
1561 | 1562 | | |
1562 | 1563 | | |
1563 | 1564 | | |
| 1565 | + | |
| 1566 | + | |
| 1567 | + | |
1564 | 1568 | | |
1565 | 1569 | | |
1566 | 1570 | | |
| |||
2970 | 2974 | | |
2971 | 2975 | | |
2972 | 2976 | | |
2973 | | - | |
2974 | | - | |
2975 | | - | |
| 2977 | + | |
| 2978 | + | |
| 2979 | + | |
| 2980 | + | |
| 2981 | + | |
| 2982 | + | |
2976 | 2983 | | |
2977 | 2984 | | |
2978 | 2985 | | |
| |||
3426 | 3433 | | |
3427 | 3434 | | |
3428 | 3435 | | |
3429 | | - | |
| 3436 | + | |
3430 | 3437 | | |
3431 | 3438 | | |
3432 | 3439 | | |
| |||
4712 | 4719 | | |
4713 | 4720 | | |
4714 | 4721 | | |
| 4722 | + | |
| 4723 | + | |
| 4724 | + | |
| 4725 | + | |
4715 | 4726 | | |
4716 | 4727 | | |
4717 | 4728 | | |
| |||
4815 | 4826 | | |
4816 | 4827 | | |
4817 | 4828 | | |
| 4829 | + | |
| 4830 | + | |
| 4831 | + | |
| 4832 | + | |
4818 | 4833 | | |
4819 | 4834 | | |
4820 | 4835 | | |
| |||
9079 | 9094 | | |
9080 | 9095 | | |
9081 | 9096 | | |
| 9097 | + | |
| 9098 | + | |
| 9099 | + | |
| 9100 | + | |
| 9101 | + | |
9082 | 9102 | | |
| 9103 | + | |
9083 | 9104 | | |
9084 | 9105 | | |
9085 | 9106 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6805 | 6805 | | |
6806 | 6806 | | |
6807 | 6807 | | |
| 6808 | + | |
6808 | 6809 | | |
6809 | 6810 | | |
6810 | 6811 | | |
| |||
7789 | 7790 | | |
7790 | 7791 | | |
7791 | 7792 | | |
7792 | | - | |
7793 | 7793 | | |
7794 | 7794 | | |
7795 | 7795 | | |
7796 | 7796 | | |
7797 | 7797 | | |
7798 | 7798 | | |
7799 | 7799 | | |
7800 | | - | |
7801 | 7800 | | |
7802 | 7801 | | |
7803 | 7802 | | |
| |||
0 commit comments