Can’t I change directory to the current directory with permission denied

filespermissionspostgresql

I am trying to restore a database with the following command:

$ sudo -u postgres pg_restore -C -d dvdrental dvdrental.tar 
[sudo] password for t: 

However, I am receiving the following error message:

could not change directory to "/home/t/mydata/…/relation model/SQL/implementations/Implementations, i.e. relational database management systems/postgreSQL/general/web/postgresqltutorial/databases": Permission denied

pg_restore: [archiver] could not open input file "dvdrental.tar": No such file or directory

I was wondering why I can't change directory to the current directory with permission denied?

File permission bits are:

 -rw-rw-r-- 1 t t 2838016 May 26  2013 dvdrental.tar

Is it because one of its ancestry directory is not both readable and executable by any one? The file has many ancestry directories, and how can I verify that?

Best Answer

The current directory, and all its parent directories, have to be accessible for the postgres user, i.e. have the executable/searchable bit set for whichever owner/group/other permission applies on each directory when determining postgres’s permissions, or grant that permission using ACLs.

To check the permissions, use namei:

namei -l /path/to/directory

See How to check if a user can access a given file? for details.

Related Question