[英]PostgreSQL create tablespace no permission
I've got a problem when I create tablespace for PostgreSQL. 为PostgreSQL创建表空间时出现问题。 The following are the steps:
步骤如下:
mkdir /postgres
chown postgres.postgres /postgres
su - postgres
psql
create tablespace p1 location '/postgres'
In this step I got a error: 在这一步,我得到一个错误:
could not set permissions on directory "/postgres": Permission denied
The directory ownership is correct: 目录所有权是正确的:
[root@dev ~]# ls -la /postgres
总用量 8
drwxr-xr-x. 2 postgres postgres 4096 12月 2 13:17 .
dr-xr-xr-x. 28 root root 4096 12月 3 06:57 ..
the user is postgres
用户是
postgres
[root@dev contrib]# ps -ef|grep postgres
postgres 1971 1 0 08:21 ? 00:00:01 /usr/bin/postmaster -p 5432 -D /var/lib/pgsql/data
I'm running on CentOS. 我在CentOS上运行。
fix: setenforce 0 修复:setenforce 0
At a wild guess I'd say you're on Mac OS X and your PostgreSQL is running as the user postgres_
(note the underscore), as is used by some PostgreSQL packages. 我可以说是您在Mac OS X上,而PostgreSQL正在以
postgres_
用户身份运行(请注意下划线),就像某些PostgreSQL软件包所使用的那样。
ps -ef | grep postgres
ps -ef | grep postgres
or ps aux|grep postgres
should show you what user the server is running as. ps -ef | grep postgres
或ps aux|grep postgres
应该向您显示服务器以什么用户身份运行。 Make sure the directory is owned by that user. 确保目录归该用户所有。
Update based on extra info in comments: 根据评论中的其他信息进行更新 :
You're on CentOS, not Mac OS X. Your PostgreSQL is running as user postgres
, which is the same owner as the directory. 您使用的是CentOS,而不是Mac OSX。PostgreSQL以用户
postgres
身份运行,该用户与目录相同。 It thus seems likely that you are having issues with SELinux . 因此,似乎您在SELinux上遇到了问题。 If, for testing purposes only , you run:
如果仅出于测试目的运行:
setenforce 0
are you then able to run the CREATE TABLESPACE
command? 然后可以运行
CREATE TABLESPACE
命令吗? ( DROP
the tablespace after creating it with SELinux temporarily off; if you don't, and restart, PostgreSQL will fail to start up). (暂时关闭SELinux创建表空间后,
DROP
表空间;如果不这样做,则重新启动表空间,PostgreSQL将无法启动)。
If creation fails with SELinux temporarily disabled, you must either exempt PostgreSQL from your SELinux policy, create the tablespace at a location that the SELinux policy permits, or set appropriate SELinux attributes on the tablespace directory so that PostgreSQL can manipulate it. 如果创建失败并暂时禁用SELinux,则必须从PostgreSQL的SELinux策略中免除PostgreSQL,在SELinux策略允许的位置创建表空间,或者在表空间目录中设置适当的SELinux属性,以便PostgreSQL可以对其进行操作。 Or you can turn SELinux off entirely, but that's not really preferable.
或者,您可以完全关闭SELinux,但这并不是真正可取的。
There might be hints in dmesg, or in CentOS's SELinux helper tool, to tell you specific SELinux booleans you can turn on or off to control this. dmesg或CentOS的SELinux帮助器工具中可能会暗示一些特定的SELinux布尔值,您可以打开或关闭来控制它。 See the help for the
setsebool
command, the Fedora Security Guide , the CentOS SELinux howto , etc. 请参阅
setsebool
命令的帮助,《 Fedora安全指南》 ,《 CentOS SELinux howto 》等。
Perhaps the best option is to just change the SELinux context of the file. 也许最好的选择是仅更改文件的SELinux上下文。 See the documentation .
请参阅文档 。 You can use
chcon
, but then the change will be lost after a file system relabel. 您可以使用
chcon
,但是在重新标记文件系统后,更改将丢失。 It's better to use semanage
as discussed in the next page of the linked manual. 这是更好地使用
semanage
作为链接手册的下页讨论。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.