Commit 506e44e
committed
[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 yugabyte#12: 0x0000aaaac5efdc70 postgres`ServerLoop at postmaster.c:1908:7
frame yugabyte#13: 0x0000aaaac5ef8ef8 postgres`PostmasterMain(argc=<unavailable>, argv=<unavailable>) at postmaster.c:1562:11
frame yugabyte#14: 0x0000aaaac5ddae1c postgres`PostgresServerProcessMain(argc=25, argv=0x000013d7ffe068f0) at main.c:213:3
frame yugabyte#15: 0x0000aaaac59dee38 postgres`main + 36
frame yugabyte#16: 0x0000ffff9f606340 libc.so.6`__libc_start_call_main + 112
frame yugabyte#17: 0x0000ffff9f606418 libc.so.6`__libc_start_main@@GLIBC_2.34 + 152
frame yugabyte#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.
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: kfranz, #db-approvers
Reviewed By: kfranz, #db-approvers
Subscribers: jason, yql
Differential Revision: https://phorge.dev.yugabyte.com/D481141 parent 067bd22 commit 506e44e
File tree
2 files changed
+26
-6
lines changed- src/postgres/src/backend/utils
- cache
- misc
2 files changed
+26
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
| 120 | + | |
120 | 121 | | |
121 | 122 | | |
122 | 123 | | |
| |||
1554 | 1555 | | |
1555 | 1556 | | |
1556 | 1557 | | |
| 1558 | + | |
| 1559 | + | |
| 1560 | + | |
1557 | 1561 | | |
1558 | 1562 | | |
1559 | 1563 | | |
| |||
2963 | 2967 | | |
2964 | 2968 | | |
2965 | 2969 | | |
2966 | | - | |
2967 | | - | |
2968 | | - | |
| 2970 | + | |
| 2971 | + | |
| 2972 | + | |
| 2973 | + | |
| 2974 | + | |
| 2975 | + | |
2969 | 2976 | | |
2970 | 2977 | | |
2971 | 2978 | | |
| |||
3419 | 3426 | | |
3420 | 3427 | | |
3421 | 3428 | | |
3422 | | - | |
| 3429 | + | |
3423 | 3430 | | |
3424 | 3431 | | |
3425 | 3432 | | |
| |||
4705 | 4712 | | |
4706 | 4713 | | |
4707 | 4714 | | |
| 4715 | + | |
| 4716 | + | |
| 4717 | + | |
| 4718 | + | |
4708 | 4719 | | |
4709 | 4720 | | |
4710 | 4721 | | |
| |||
4808 | 4819 | | |
4809 | 4820 | | |
4810 | 4821 | | |
| 4822 | + | |
| 4823 | + | |
| 4824 | + | |
| 4825 | + | |
4811 | 4826 | | |
4812 | 4827 | | |
4813 | 4828 | | |
| |||
9072 | 9087 | | |
9073 | 9088 | | |
9074 | 9089 | | |
| 9090 | + | |
| 9091 | + | |
| 9092 | + | |
| 9093 | + | |
| 9094 | + | |
9075 | 9095 | | |
| 9096 | + | |
9076 | 9097 | | |
9077 | 9098 | | |
9078 | 9099 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6811 | 6811 | | |
6812 | 6812 | | |
6813 | 6813 | | |
| 6814 | + | |
6814 | 6815 | | |
6815 | 6816 | | |
6816 | 6817 | | |
| |||
7797 | 7798 | | |
7798 | 7799 | | |
7799 | 7800 | | |
7800 | | - | |
7801 | 7801 | | |
7802 | 7802 | | |
7803 | 7803 | | |
7804 | 7804 | | |
7805 | 7805 | | |
7806 | 7806 | | |
7807 | 7807 | | |
7808 | | - | |
7809 | 7808 | | |
7810 | 7809 | | |
7811 | 7810 | | |
| |||
0 commit comments