使用root 用戶 su postgres
切換到postgres用戶時 提示
could not change directory to "/root"
使用
su - postgres
su命令和su -命令區別就是:
su只是切換了root身份,但Shell環境仍然是普通用戶的Shell;而su -連用戶和Shell環境一起切換成root身份了。只有切換了Shell環境才不會出現PATH環境變量錯誤,報command not found的錯誤。
su切換成root用戶以后,pwd一下,發現工作目錄仍然是普通用戶的工作目錄;而用su -命令切換以后,工作目錄變成root的工作目錄了。