I just tried installing Postgresql on a pretty standard/untweaked Ubuntu installation, and I got:

Setting up postgresql-8.4 (8.4.1-1) ...
 * Starting PostgreSQL 8.4 database server
 * The PostgreSQL server failed to start. Please check the log output.
                                                                         [fail]
invoke-rc.d: initscript postgresql-8.4, action "start" failed.
dpkg: error processing postgresql-8.4 (--configure):
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
 postgresql-8.4
E: Sub-process /usr/bin/dpkg returned an error code (1)

Looking at the logfile this produced, I found the lines:
2010-01-11 15:16:25 EST LOG: could not translate host name "localhost", service "5432" to address: Name or service not known
2010-01-11 15:16:25 EST WARNING: could not create listen socket for "localhost"
2010-01-11 15:16:25 EST FATAL: could not create any TCP/IP sockets

So that sucked. Digging around, it turns out this is due to Ubuntu bug 516312, and that a quick solution is to edit the file /etc/postgresql/8.4/main/postgresql.conf and change the line that reads

# - Connection Settings -
# listen_addresses = 'localhost'          # what IP address(es) to listen on;
                                        # comma-separated list of addresses;

into

# - Connection Settings -
listen_addresses = '127.0.0.1'          # what IP address(es) to listen on;
                                        # comma-separated list of addresses;

For some reason, despite an /etc/hosts file which contains the line 127.0.0.1 localhost, postgres can’t properly resolve the name “localhost”. I could care about why and try and find the source of the bug, but it just doesn’t matter much to me right now. As long as you only care about running it locally you can change that one line in the postgresql configuration file and everything should work. Now you know, and hopefully this will save someone some time.