在 postgresql 中创建表空间

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5208094/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 22:51:05  来源:igfitidea点击:

Creating a tablespace in postgresql

postgresqltablespacechown

提问by The_Denominater

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

我正在尝试在 postgres 中创建一个表空间,但我遇到了所有权问题。我使用的命令是:

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 :

该文件夹属于 postgres:postgres,我尝试将其更改为 maggie,但是如果我去:

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?

用户怎么不存在?如果我在 postgres 中列出用户,它确实会出现。任何想法我可能做错了什么?

回答by gsiems

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).

我会猜测问题出在父目录“/home/john”的权限上。您的主目录可能已设置为只有您的用户可以访问(即 chmod 700)(您的主目录为 chmod 700 是一件好事,不要更改它)。

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.

关于用户 maggie:数据库用户与操作系统用户不同。这并不是说你不能在两个地方都有一个名为 maggie 的用户——但你需要在数据库和操作系统中创建用户才能实现这一点。

回答by KPonn

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

当您在 Mac 上安装 Postgres 并尝试使用它PgAdmin来创建数据库、表空间等时。您需要知道它是在安装 postgres 数据库和实用程序时创建PgAdmin Utilitypostgres帐户下运行的。

The postgres accountis part of the _postgresgroup

postgres account_postgres组的一部分

( dscacheutil -q group|grep -i postgrescommand will list the group associated with the postgresaccount)

dscacheutil -q group|grep -i postgres命令将列出与postgres帐户关联的组)

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

最佳实践是在 root( /)下创建一个新目录来容纳表空间,(让我们调用它/postgresdata然后postgres:_postgres使用下面的命令创建该目录的所有者)

sudo chown postgres:_postgres /postgresdata

sudo chown postgres:_postgres /postgresdata

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

这应该为你做。然后您可以/postgresdata为每个唯一的表空间创建一个子目录