I'm following the recent RailsCast on setting up PostgreSQL, but I'm unable to run the initdb /usr/local/var/postgres
command. Each time I run it, I get this error:
我正在跟踪最近的RailsCast设置PostgreSQL,但是我无法运行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
4 个解决方案
#1
47
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
#2
5
You actually need to SU
to the postgres
user
实际上,您需要向postgres用户提供SU
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
- $ createuser -s -U postgres
-
$ Enter name of role to add: {{ my login name }}
(this appears to beConstruct
) - $输入要添加的角色名:{{我的登录名}(这看起来是构造)
then you can exit out of postgres user and you can create your own database
然后可以退出postgres用户并创建自己的数据库
$ createdb
- createdb美元
#3
3
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 as的哪个用户?如果您不是root用户,您可能没有权限在/usr/ local.com中创建目录。我建议将/usr/local/var/postgres作为根,并将其chown构建:
# 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 sure your Construct user is actually capitalized? If so, are you really sure your want it to be capitalized—-a lot of things will break.
另外,请注意,Unix用户名通常都是小写的(但也区分大小写);您确定您的构造用户实际上是资本化的吗?如果是的话,你真的确定你想让它资本化吗?很多东西都会坏掉。
(FYI: For Unix questions like this, you may find Unix.SE or Ask Ubuntu provide quicker answers)
(供参考:对于像这样的Unix问题,您可以找到Unix。SE或问Ubuntu提供更快的答案)
#4
2
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
#1
47
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
#2
5
You actually need to SU
to the postgres
user
实际上,您需要向postgres用户提供SU
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
- $ createuser -s -U postgres
-
$ Enter name of role to add: {{ my login name }}
(this appears to beConstruct
) - $输入要添加的角色名:{{我的登录名}(这看起来是构造)
then you can exit out of postgres user and you can create your own database
然后可以退出postgres用户并创建自己的数据库
$ createdb
- createdb美元
#3
3
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 as的哪个用户?如果您不是root用户,您可能没有权限在/usr/ local.com中创建目录。我建议将/usr/local/var/postgres作为根,并将其chown构建:
# 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 sure your Construct user is actually capitalized? If so, are you really sure your want it to be capitalized—-a lot of things will break.
另外,请注意,Unix用户名通常都是小写的(但也区分大小写);您确定您的构造用户实际上是资本化的吗?如果是的话,你真的确定你想让它资本化吗?很多东西都会坏掉。
(FYI: For Unix questions like this, you may find Unix.SE or Ask Ubuntu provide quicker answers)
(供参考:对于像这样的Unix问题,您可以找到Unix。SE或问Ubuntu提供更快的答案)
#4
2
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