PostgreSQL 9.0 adds the feature for connections to set an application name that shows up in logs and the system view pg_stat_activity.
http://www.postgresql.org/docs/9.0/static/runtime-config-logging.html#RUNTIM...
All previous versions of PostgreSQL back to 7.4 were patched in minor releases in December 2009 so that they ignore this parameter e.g. http://www.postgresql.org/docs/9.0/static/release-7-4-27.html
But I think it would cause problems for servers that hadn't been updated.
Patch attached that works for me (both with and without setting application_name). But it is just a quick copy and paste job!
Chris