Can't import db from sql file

[user@localhost ~]$ sudo -u postgres psql
[sudo] password for user: 
could not change directory to "/home/user"
psql (9.2.24)
Type "help" for help.

postgres=# \c db
You are now connected to database "db" as user "postgres".
rob=# \i /home/user/Downloads/dump.sql
/home/user/Downloads/dump.sql: `Permission denied`

[root@localhost user]# ls -Z /home/user/Downloads/dump.sql
-rw-rw-rw-. postgres postgres unconfined_u:object_r:user_home_t:s0 dump.sql

Q: Why Permission denied? How can I fix it?

CentOS 7.2.1511

  • 3
    the postgres OS user does not have access to /home/user. – dezso Sep 6 '18 at 15:25
  • 1
    Do you really need to import that dump as the user postgres? – Colin 't Hart Sep 6 '18 at 15:35

Try to move the file into /tmp folder, I hope this will work.

In PostgreSQL you run into error with having permission on the the file but not all the folders/directories before it.

Not the answer you're looking for? Browse other questions tagged or ask your own question.