Heartbleed style OpenSSL zero day protection. An open to all environment, like the public Heroku postgres environment, is a huge attack surface.
Layers of security exist for this exact reason. If one fails, hopefully something else stops it.
> What is the advantage of listening on localhost compared to using a socket, with free access control?
Can install and use right away locally without figuring out where your distro puts the socket at.
Edit: Also no need to play with permissions of the socket in such a case.
Unless your local cluster doesn’t allocate your install on 5432 e.g. after cluster upgrade.
No need to play with permissions of the socket, because you ‘just’ use a socket that gives permission to everyone.
Modern linux security thinking is that any sort of code running inevitably leads to root privilege.
Put another way, any user can become root through privilege escalation, so access control is pointless, since any untrusted user can take over the machine.
The real unit of security is the whole OS (VM), not its internal user boundaries.
This kind of mindset exists but is not a consensus. And even if it became consensus, it would still take many, many years for most developers to stop using ssh forwarding with localhost listeners in a security reliant way.
Also, the loopback is used as a networking interconnect or guest->host channel for sandboxed containers and VMs, so it's security sensitive in this way.
What is the advantage of listening on localhost compared to using a socket, with free access control?