我在Ubuntu 16.04上安装了PostgreSQL 9.5。由于它位于SSD上,而且我不想太频繁地写入它,我宁愿将大部分数据保存在我最近安装并分区到Ext4文件系统的硬盘(通过SATA连接)上。 (Postgres安装在SSD上)
我正在尝试使用以下所有权和位置设置在硬盘驱动器上创建表空间:
root@mycomp:/media/me/EXT4_LARGE# ls -la
total 36
drwx------ 6 me root 4096 Nov 30 23:17 .
drwxr-x---+ 5 me root 4096 Nov 30 23:09 ..
drwx------ 2 root root 16384 Nov 30 21:59 lost+found
drwx------ 2 postgres postgres 4096 Nov 30 22:25 pg_data
从psql
命令行:
postgres=# CREATE TABLESPACE hdd_ts LOCATION
'/media/me/EXT4_LARGE/pg_data';
ERROR: could not set permissions on
directory "/media/me/EXT4_LARGE/pg_data": Permission denied
我尝试在各种配置中修改所有权设置,但没有一个能够正常工作。
如何在硬盘上获取表空间?
答案 0 :(得分:2)
In Linux, users need the 'x' permission on the parent directory to be able to enter the directory and access files and directories inside it.
They need also need the 'w' permission to make any changes to entries in that directory.
From your printout:
drwx------ 6 me root 4096 Nov 30 23:17 .
This tells me that only the user me
has x
and w
permissions on the directory /media/me/EXT4_LARGE
. So the user postgres
will not be able to change permissions of /media/me/EXT4_LARGE/pgdata
, nor even see inside it.
A quick and dirty solution would be:
chmod a+rwx /media/me/EXT4_LARGE
The drawback of that solution is it would give ALL users read/write access to EXT4_LARGE. A more fine grained approach would be to create a group and assign group permissions.
Also it might be unwise to give postgres access to the whole EXT4_LARGE filesystem, so as per some of the comments, you might want to create another directory level in between, eg:
mkdir -p /media/me/EXT4_LARGE/db/pgdata
chown postgres:postgres /media/me/EXT4_LARGE/db
chown postgres:postgres /media/me/EXT4_LARGE/db/pgdata
chmod a+x /media/me/EXT4_LARGE/
Note that the x
permission is needed on all parent directories, so you might have to adjust /media/me
and /media
.