« SCALE Talk Slides and Audio | Main | A Guide to Hiring Programmers: The High Cost of Low Quality »

July 30, 2007

Which PostgreSQL backend am I using?

Someone asked me how to determine which PostgreSQL backend a particular client was connected to.  Everyone's first thought is to do a ps aux | grep postgres which will show you the IP and user, but if you have different processes connecting from the same IP with the same usernames, how do you know which is which?

One way to tell would be to see which queries are being executed by which backend and match that up to your client side.  But you can quickly get confused, especially if the various connections are all executing the same SQL statements, a web application for example.

The simplest way was suggested by Jacob Kaplan-Moss, which is to use the pg_backend_pid() function like:

SELECT pg_backend_pid();

I love it when the solution is something really simple!

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00d83420a30553ef00e3981e981e8833

Listed below are links to weblogs that reference Which PostgreSQL backend am I using?:

Comments

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been saved. Comments are moderated and will not appear until approved by the author. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment

Comments are moderated, and will not appear until the author has approved them.