我刚刚安装了一个外部 HD 来存储我的新表空间。
postgres@vostro ~ $ df -k
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sdb1 480589520 71580 456082280 1% /mnt/DB
postgres@vostro ~ $ ls -l /mnt/DB/
total 4
drwxrwxrwx 2 postgres postgres 4096 May 25 17:02 postgres
demisc@vostro /mnt $ mount | grep -i sdb1
/dev/sdb1 on /mnt/DB type ext4 (rw,nosuid,nodev,relatime,data=ordered)
Run Code Online (Sandbox Code Playgroud)
我授予了所有必要的权限,以便 posgres 可以在/mnt/DB/postgres
. 以下是用户组:
postgres@vostro ~ $ id
uid=123(postgres) gid=131(postgres) groups=131(postgres),112(ssl-cert),1000(demisc)
Run Code Online (Sandbox Code Playgroud)
发生在运行 create tablespace 命令时,我得到以下信息:
postgres=# create tablespace ts_project location '/mnt/DB/postgres';
ERROR: could not set permissions on directory "/mnt/DB/postgres":
Permission denied
Run Code Online (Sandbox Code Playgroud)
我缺少什么?
ls -ln /mnt/DB/postgres
Run Code Online (Sandbox Code Playgroud)
返回:
demisc@vostro /mnt/DB $ ls -ln /mnt/DB/postgres/
total 0
Run Code Online (Sandbox Code Playgroud)
一切看起来都不错。postgres 用户没有理由不能创建表空间。如果我切换到 postgres 并尝试在路径中创建文件或目录,它工作正常。
创建表空间时,postgres 在内部执行调用chmod 0700
来检查您指定的目录是否存在并且拥有正确的所有者。
显然,在您的情况下,postgres 操作系统用户无法执行此 chmod 调用。您可以通过手动设置正确的权限来解决该问题(请参阅问题本身的评论),这一事实也证实了这一点。
不幸的是,我很难判断权限分配出了什么问题,也许是由于 SELinux 的作用。
运行部分源代码的链接chmod
。https://doxygen.postgresql.org/backend_2commands_2tablespace_8c.html#af268dfe1eb53bf570eceec80b993e66a
postgres 邮件列表中的相关讨论。早在 2008 年,它就被认为不是一个错误。https://www.postgresql.org/message-id/200804191238.m3JCcfcJ076060%40wwwmaster.postgresql.org