Linux 调试postgreSQL server进程(如何识别正确的进程id)
我使用V1调用约定为PG编写了一个C扩展库。我的数据库是8.4版。 我已经成功地创建了新函数 但是,当我调用新函数时,它会使服务器崩溃,并向控制台发送以下消息:Linux 调试postgreSQL server进程(如何识别正确的进程id),linux,postgresql,ps,Linux,Postgresql,Ps,我使用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附加到postgr
The connection to the server was lost. Attempting reset: Failed.
服务器日志包含以下行:
server process (PID 14751) was terminated by signal 11: Segmentation fault
我想将gdb附加到postgres进程,并查看是否可以获得堆栈跟踪,以帮助我开始调试。然而,当我跑的时候
ps aux|grep postgres
为了定位postgres进程,似乎有几个进程称为postgres
如何正确识别postgres服务器进程(重新启动后)以进行上述调试?我刚刚找到了答案。数据库名称也是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您可以按如下方式获取当前后端的PID:
select pg_backend_pid();