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
I wrestled with this "Permission Denied" issue while trying to backup my PSQL database on an Ubuntu machine for a long time, and tried user access rights, superuser status, folder properties--lots of stuff. Finally, something worked that was ridiculously simple. In the command:
pg_dump -U username -O dbname > 'filename.sql'
Make sure you have quotes (single or double quotes seem to work) around the filename which follows the greater than (">") sign. The examples above do not have quotes around the filename. Once I tried that, I no longer received Permission Denied errors.