I get this error while trying to dump database, i entered
linuxuser $ sudo su postgres linuxuser $ [sudo] password for linuxuser:... $ pg_dump -h localhost mydb
Write into directory where postgres user has write access. For instance /tmp.
/tmp
$ pg_dump -h localhost mydb >/tmp/tempfile
In your attempt postgres user tries to create a file in some random directory belonging to the other user.