How to trace the postgres?

From: Wen Yi <896634148(at)qq(dot)com>
To: pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: How to trace the postgres?
Date: 2023-06-12 10:37:39
Message-ID: tencent_1C2195E258DC80A4A35C3AEB0657334CD909@qq.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi team,
Now I am start to analyse the process of the postgres, using the gdb.
As you can see, at the beginnning of my work, I use the ps to find the postgres's process.

[postgres(at)fedora postgresql]$ ps -ef | grep postgres
postgres&nbsp;&nbsp; 67468&nbsp;&nbsp;&nbsp; 1599&nbsp; 0 08:11 ?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 00:00:01 /home/postgres/pgsql/lib/bin/postgres -D /home/postgres/pgsql/data
postgres&nbsp;&nbsp; 67471&nbsp;&nbsp; 67468&nbsp; 0 08:11 ?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 00:00:00 postgres: checkpointer
postgres&nbsp;&nbsp; 67472&nbsp;&nbsp; 67468&nbsp; 0 08:11 ?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 00:00:00 postgres: background writer
postgres&nbsp;&nbsp; 67474&nbsp;&nbsp; 67468&nbsp; 0 08:11 ?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 00:00:00 postgres: walwriter
postgres&nbsp;&nbsp; 67475&nbsp;&nbsp; 67468&nbsp; 0 08:11 ?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 00:00:00 postgres: autovacuum launcher
postgres&nbsp;&nbsp; 67476&nbsp;&nbsp; 67468&nbsp; 0 08:11 ?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 00:00:00 postgres: logical replication launcher
root&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 90486&nbsp;&nbsp; 90459&nbsp; 0 14:32 pts/0&nbsp;&nbsp;&nbsp; 00:00:00 su postgres
postgres&nbsp;&nbsp; 90494&nbsp;&nbsp; 90486&nbsp; 0 14:32 pts/0&nbsp;&nbsp;&nbsp; 00:00:00 bash
postgres&nbsp;&nbsp; 90526&nbsp;&nbsp; 90494&nbsp; 0 14:32 pts/0&nbsp;&nbsp;&nbsp; 00:00:00 psql
postgres&nbsp;&nbsp; 90527&nbsp;&nbsp; 67468&nbsp; 0 14:32 ?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 00:00:00 postgres: postgres postgres [local] idle
root&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 90680&nbsp;&nbsp; 90652&nbsp; 0 14:33 pts/2&nbsp;&nbsp;&nbsp; 00:00:00 su postgres
postgres&nbsp;&nbsp; 90683&nbsp;&nbsp; 90680&nbsp; 0 14:33 pts/2&nbsp;&nbsp;&nbsp; 00:00:00 bash
postgres&nbsp;&nbsp; 90766&nbsp;&nbsp; 90683&nbsp; 0 14:33 pts/2&nbsp;&nbsp;&nbsp; 00:00:00 ps -ef
postgres&nbsp;&nbsp; 90767&nbsp;&nbsp; 90683&nbsp; 0 14:33 pts/2&nbsp;&nbsp;&nbsp; 00:00:00 grep --color=auto postgres

After that, I use the gdp to debug one of the postgres's process

[postgres(at)fedora postgresql]$ gdb -p 67468

WaitEventSetWait (set=0x25221d8, timeout=60000, occurred_events=0x7ffe2ea9df70, nevents=64, wait_event_info=0) at latch.c:1478
1478&nbsp;&nbsp;&nbsp; in latch.c
(gdb) next
1480&nbsp;&nbsp;&nbsp; in latch.c
(gdb) next
1481&nbsp;&nbsp;&nbsp; in latch.c
(gdb) next
1484&nbsp;&nbsp;&nbsp; in latch.c
(gdb) next
1487&nbsp;&nbsp;&nbsp; in latch.c
(gdb) next
1490&nbsp;&nbsp;&nbsp; in latch.c
(gdb) next
1492&nbsp;&nbsp;&nbsp; in latch.c
(gdb) next
1493&nbsp;&nbsp;&nbsp; in latch.c
(gdb) next
1494&nbsp;&nbsp;&nbsp; in latch.c
(gdb) next
1495&nbsp;&nbsp;&nbsp; in latch.c
(gdb) next

With the gdb's work, I use the psql to send the query to the postgres.

One thing confuses me is, I really don't know how to trace the postgres's process, I try to trace the background writer, the walwriter but I still don't know what is them work logical.

I think they seem to work in a loop(I read the related code, that's true), but what I want to verify is to identify all the functions and objects involved in the entire process of PGSQL (from syntax parsing to rewriting, from rewriting to optimization, and from optimization to execution).

Can someone give me some advice?
Thanks in advance!

Yours,
Wen Yi

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Lorusso Domenico 2023-06-12 15:15:08 Re: Question about where to deploy the business logics for data processing
Previous Message Wei Wang (Fujitsu) 2023-06-12 01:47:02 RE: Support logical replication of DDLs