About the permissions:
Don’t forget that to access a file you need permissions on all directories in the path. So if, for example, the OS user postgres
does not have permissions on the /home/MyUser
directory, you get the observed error message.
About \copy
:
You have to use the -c
option to supply a command to psql
:
$ psql -c "\copy sample FROM '/home/MyUser/data/TableName.csv' WITH (FORMAT CSV)"