Creating a tablespace in postgresql

半城伤御伤魂 提交于 2020-01-22 13:28:05

问题


I'm trying to create a tablespace in postgres, but I'm getting ownership problems. The command I'm using is:

CREATE TABLESPACE magdat OWNER maggie LOCATION '/home/john/BSTablespace'

I get the error:

ERROR:  could not set permissions on directory "/home/john/BSTablespace": Operation not permitted

The folder belongs to postgres:postgres, I've tried changing it to maggie, but if I go :

chown maggie:postgres /home/john/BSTablespace

I get:

chown: invalid user: `maggie:postgres'

How come the user does not exist? If I list the users inside of postgres it does come up. Any ideas what I could be doing wrong?


回答1:


I would hazard a guess that the problem lies in the permissions of the parent directory "/home/john". Your home directory is probably setup so that only your user has access (i.e chmod 700) to it (it's a good thing for your home directory to be chmod 700, don't change it).

Doing something like:

mkdir /BSTablespace
chown postgres:postgres /BSTablespace

and then

CREATE TABLESPACE magdat OWNER maggie LOCATION '/BSTablespace';

should work fine.

Regarding the user maggie: database users are not the same as OS users. That isn't to say that you couldn't have a user in both places named maggie-- but you would need to create the user in both the database and the OS for that to happen.




回答2:


When you install Postgres on a Mac, and are trying to use PgAdmin to create your databases, tablespaces, etc. You need to know that the PgAdmin Utility is running under the postgres account that it created when you installed the postgres database and the utilities.

The postgres account is part of the _postgres group

( dscacheutil -q group|grep -i postgres command will list the group associated with the postgres account)

The best practice would be to create a new directory under root(/) for housing the tablespaces,(let us call it /postgresdata then make postgres:_postgres the owners of that directory, using the command below)

sudo chown postgres:_postgres /postgresdata

This should do it for you. You could then create a subdirectory under /postgresdata for each unique table space



来源:https://stackoverflow.com/questions/5208094/creating-a-tablespace-in-postgresql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!