I have been trying to create a tablespace in postgresql 9.5 and I have been consistently getting issues with permission denied. I have finally decided I’m going to create a directory in
/ just to see if I could get anything to work but with no luck so far.
[root@server ~]# cd / [root@server /]# mkdir test [root@server /]# chown postgres:postgres test [root@server /]# su postgres bash-4.3$ psql psql (9.5.5) Type "help" for help. postgres=# CREATE TABLESPACE test LOCATION '/test'; ERROR: could not set permissions on directory "/test": Permission denied postgres=# \q bash-4.3$ cd test bash-4.3$ chmod 777 . bash-4.3$ ls -alh total 8.0K drwsrwsrwx. 2 postgres postgres 4.0K Jan 27 20:15 . dr-xr-xr-x. 19 root root 4.0K Jan 27 20:15 .. bash-4.3$ pwd -P /test bash-4.3$ psql psql (9.5.5) Type "help" for help. postgres=# CREATE TABLESPACE test LOCATION '/test'; ERROR: could not set permissions on directory "/test": Permission denied
I’ve even given the directory 777 and it is quite obviously owned by postgres. At this point I’m not sure what to do to get this to work. I’m running fedora-25. I would ideally like to not put this in
/ and actually put it on a separate disk but I can’t even get this basic case to work. Am I missing something obvious here?
You have SELinux enabled, and have missed that it is blocking this.
You can see the log entries in the audit log
The easiest way to resolve the problem is to use the default data directory location,
/var/lib/pgsql and to not try to override it. Rather, mount your storage at this location.
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.