I have a software written in Python which accesses a postgres database. In order to allow several instances of the software, on one of the screens I need what is the connection identity so I check the PID by accessing the DB and retrieving it through the function pg_backend_pid().

Everything works fine except that when I check the PID of the instance in pg_backend_pid() I get a PID number that does not exist in the pg_stat_activity table. In fact i can identify the PID number of my instance in the table but it is different than the number I received through the function pg_backend_pid().

I would be happy if someone could help me understand why the PID I got from the function is different than what exists in the table.

Thanks in advance.

  • 1
    Perhaps pg_backend_pid is being run from a separate process that terminates once the backend pid is obtained? pg_stat is not a historical table - it only shows current pids. From the docs, " Process ID of the server process attached to the current session" – Victor Di Leo Aug 28 '18 at 14:37
  • In other words, your software apparently creates new connections. – CL. Aug 29 '18 at 7:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.