Well, like others mentioned before, it is not getting fully clear what You are trying to achieve. But, in any case, if this is Your problem .... On Thu, Sep 01, 2022 at 06:01:02PM -0400, Jeffrey Walton wrote: ! Hi Everyone, ! ! We are having a heck of a time getting PostreSQL utilities to honor ! home directories. For example, when I execute this script: ! ! sudo -H -u postgres PGPASSWORD=${password} \ ! psql -h "${hostname}" -U "${username}" -d "${database}" \ ! --command="..." ! ! It produces failures: ! ! could not change directory to "/home/jwalton/godojo": Permission denied ... this appears to me as rather a sudo issue. Because certainly psql cannot execute /as user postgres/ in a directory where user postgres is not allowed to enter. So sudo should fix that, and in my sudo installation I find either a "-D directory" option for sudo (that should change the directory accordingly) or a "--login" option (that would run a full login shell for the user postgres, which, alongside going to the postgres homedir, does a lot of other things which may or may not be desireable in your installation).