2

我使用 V1 调用约定为 PG 编写了一个 C 扩展库。我的数据库是 8.4 版。我已经成功创建了新功能。

但是,当我调用我的新函数时,它会使服务器崩溃,并将以下消息发送到控制台:

The connection to the server was lost. Attempting reset: Failed.

服务器日志包含以下行:

server process (PID 14751) was terminated by signal 11: Segmentation fault

我想将 gdb 附加到 postgres 进程,看看是否可以获得堆栈跟踪,以帮助我开始调试。但是,当我跑步时

ps辅助| grep postgres

为了尝试定位 postgres 进程,似乎有几个名为 postgres 的进程。

如上所述,出于调试目的,我如何正确识别 postgres 服务器进程(重新启动后)?

4

2 回答 2

2

我刚刚找到了这个问题的答案。数据库名称也是 ps aux 输出的一部分。

例如:

postgres  1071  0.0  0.1 101120  5360 ?        S    Jan03   0:01 /usr/lib/postgresql/8.4/bin/postgres -D /var/lib/postgresql/8.4/main -c config_file=/etc/postgresql/8.4/main/postgresql.conf
postgres 11866  0.0  0.1  68444  4340 pts/1    S+   10:16   0:00 /usr/lib/postgresql/8.4/bin/psql postgres
postgres 14856  0.0  0.1 103612  4716 ?        Ss   14:56   0:00 postgres: postgres mydatabase [local] idle  
postgres 14894  0.0  0.0 101120  1640 ?        Ss   15:05   0:00 postgres: writer process  

本例中的进程 ID 为 14856

于 2012-01-04T15:10:49.867 回答
1

您可以像这样获取当前后端的 PID:

select pg_backend_pid();
于 2012-01-04T15:19:35.880 回答