What's the difference between sudo su - postgres and sudo -u postgres?
- by Craig Ringer
PostgreSQL users peer authentication on unix sockets by default, where the unix user must be the same as the PostgreSQL user. So people frequently use su or sudo to become the postgres superuser.
I often see people using constructs like:
sudo su - postgres
rather than
sudo -u postgres -i
and I'm wondering why. Similarly, I've seen:
sudo su - postgres -c psql
instead of
sudo -u postgres psql
Without the leading sudo the su versions would make some sense if you were on an old platform without sudo. But why on a less than prehisoric UNIX or Linux would you use sudo su ?