database 试图在我的环境中设置 Postgres,但似乎无法获得对 intidb 的权限

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10431426/
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-08 08:32:28  来源:igfitidea点击:

Trying to get Postgres setup in my environment but can't seem to get permissions to intidb

databasepostgresqlchmodchown

提问by Jimmy Odom

I'm following the recent RailsCast on setting up PostgreSQL, but I'm unable to run the initdb /usr/local/var/postgrescommand. Each time I run it, I get this error:

我正在关注最近关于设置 PostgreSQL 的 RailsCast,但我无法运行该initdb /usr/local/var/postgres命令。每次运行它,我都会收到此错误:

The files belonging to this database system will be owned by user "Construct".
This user must also own the server process.

The database cluster will be initialized with locale en_US.UTF-8.
The default database encoding has accordingly been set to UTF8.
The default text search configuration will be set to "english".

creating directory /usr/local/var/postgres ... initdb: could not create directory "/usr/local/var": Permission denied

回答by Gaurav Swaroop

This should work just fine:

这应该可以正常工作:

# sudo mkdir /usr/local/var/postgres
# sudo chmod 775 /usr/local/var/postgres
# sudo chown construct /usr/local/var/postgres
# initdb /usr/local/var/postgres

use your username in place of construct. So, if your computer username is WDurant, the code will be:

使用您的用户名代替构造。因此,如果您的计算机用户名是 WDurant,则代码将是:

# sudo chown wdurant /usr/local/var/postgres

回答by Bodhi94

If you run on Arch Linux, use like this :

如果您在 Arch Linux 上运行,请像这样使用:

sudo mkdir /var/lib/postgres
sudo chmod 775 /var/lib/postgres
sudo chown postgres /var/lib/postgres

sudo -i -u postgres

[postgres]$ initdb --locale $LANG -E UTF8 -D '/var/lib/postgres/data'
[postgres]$ exit

sudo systemctl start postgresql.service

sudo -i -u postgres

回答by swasheck

You actually need to SUto the postgresuser

实际上,你需要SUpostgres用户

  • sudo su - postgres
  • sudo su - postgres

then you can run the command

然后你可以运行命令

  • initdb -E UTF8(I prefer setting this now because UTF8 is quite flexible and this will create all clusters as UTF8 [unless you explicitly specify otherwise])
  • initdb -E UTF8(我现在更喜欢设置它,因为 UTF8 非常灵活,这会将所有集群创建为 UTF8 [除非您另外明确指定])

then you need to create your user (if it hasn't already been created)

那么您需要创建您的用户(如果尚未创建)

  • $ createuser -s -U postgres
  • $ Enter name of role to add: {{ my login name }}(this appears to be Construct)
  • $ createuser -s -U postgres
  • $ Enter name of role to add: {{ my login name }}(这似乎是Construct

then you can exit out of postgres user and you can create your own database

然后你可以退出 postgres 用户,你可以创建自己的数据库

  • $ createdb
  • $ createdb

回答by derobert

Which user are you running initdb as? If you're not root, you likely don't have permission to create directories in /usr/local. I suggest creating /usr/local/var/postgres as root, and chown'ing it to construct:

您以哪个用户身份运行 initdb?如果您不是 root,您可能没有权限在 /usr/local 中创建目录。我建议以 root 身份创建 /usr/local/var/postgres,然后用 chown'ing 来构造:

# mkdir -m 0700 -p /usr/local/var/postgres
# chown construct /usr/local/var/postgres

Then your initdb (run as construct) should have permission.

然后你的 initdb(作为构造运行)应该有权限。

Also, note that Unix usernames are normally all-lowercase (but also case-sensitive); are you sureyour Construct user is actually capitalized? If so, are you really sureyour want it to be capitalized—-a lot of things will break.

另外,请注意 Unix 用户名通常都是小写的(但也区分大小写);你确定你的构造用户实际上是大写的吗?如果是这样,你真的确定你希望它被大写——很多事情都会破裂。

(FYI: For Unix questions like this, you may find Unix.SEor Ask Ubuntuprovide quicker answers)

(仅供参考:对于此类 Unix 问题,您可能会发现Unix.SEAsk Ubuntu提供更快的答案)