Most commonly because you'd like to use JDBC to connect to your local Postgres server without using password auth. Very quickly you'll realise Unix sockets aren't supported in Java, so you can't use peer
authentication.
First, ensure your /var/lib/pgsql/pg_hba.conf
uses ident
for TCP/IP connections:
# IPv4 local connections:
host all all 127.0.0.1/32 ident