Restrict root user access to postgres user I know this is a little weird but bear with me. 

If a hacker gains access to a server's root user, he can type "su postgres" and then "psql" and boom - instant access to everything.

I was wondering if there was any possible way to block the root user from switching to the postgres user. In other words, I want to force a postgres-specific password to be used before postgres access is granted.

Is there any way to do this? Or is the root user always God?
You cannot do what you are asking.

Here's what you should do instead:


Run your database on its own computer in its own network segment. Don't run anything else on that computer (save backup / monitoring agents)
Use a separate management network for server management / backup / monitoring
Send your db + os security logs to another machine and use a software tool to monitor them and send alerts
Don't connect to database from web servers as a superuser