@@ -32,6 +32,7 @@ module Database.PostgreSQL.Simple.Notification
3232 ( Notification(..)
3333 , getNotification
3434 , getNotificationNonBlocking
35+ , getBackendPID
3536 ) where
3637
3738import Control.Concurrent
@@ -101,3 +102,14 @@ getNotificationNonBlocking conn =
101102 case mmsg' of
102103 Just msg -> return $! Just $! convertNotice msg
103104 Nothing -> return Nothing
105+
106+-- | Returns the process 'CPid' of the backend server process
107+-- handling this connection.
108+--
109+-- The backend PID is useful for debugging purposes and for comparison
110+-- to NOTIFY messages (which include the PID of the notifying backend
111+-- process). Note that the PID belongs to a process executing on the
112+-- database server host, not the local host!
113+
114+getBackendPID :: Connection -> IO CPid
115+getBackendPID conn = withConnection conn PQ.backendPID