The following error occurred while attempting to use gdb to debug errors in Apache Age. The postgres server was started using pg_ctl
and a connection to a database was established using psql
. The running process ID (pid) of psql was found using the SELECT pg_backend_pid()
command. However, when attempting to attach gdb to the psql process using gdb --pid 4585
, the following error message was received:
Attaching to process 4585
Could not attach to process. If your uid matches the uid of the target
process, check the setting of /proc/sys/kernel/yama/ptrace_scope, or try
again as the root user. For more details, see /etc/sysctl.d/10-ptrace.conf
ptrace: Operation not permitted.
Afterwards, I attempted to run gdb with elevated privileges by using the command sudo gdb --pid 4585
. However, the following error message was displayed:
Starting program: /home/mohayu/Desktop/age_installation/pg/postgresql-11.18/bin/postgres
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
"root" execution of the PostgreSQL server is not permitted.
The server must be started under an unprivileged user ID to prevent
possible system security compromise. See the documentation for
more information on how to properly start the server.
[Inferior 1 (process 5056) exited with code 01]
If you are unsure about the reasons behind the errors occurring, just tell me on how to debug Apache Age with gdb.
2
Answers
Run
gdb
while you are the user who owns the PostgreSQL processes, usuallypostgres
.Make sure you have the PostgreSQL debugging symbols installed and that the extension is built with
-g
or-ggdb
.With your first approach, using
gdb --pid 4585
, I got the same error. Although in the second approach usingsudo
I was successful, I have another suggestion:First, try just the
sudo gdb
command. The system must return the following:Then, use the
attach [ID]
command replacing[ID]
with the pid. If it succeeds, the terminal will return something similar to the following messages: