Jim*_*dom 27 database postgresql chmod chown
我正在关注最近设置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
小智 56
这应该工作得很好:
# 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
使用您的用户名代替构造.因此,如果您的计算机用户名是WDurant,则代码为:
# sudo chown wdurant /usr/local/var/postgres
如果你在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
实际上,你需要SU给postgres用户
sudo su - postgres然后你可以运行命令
initdb -E UTF8 (我现在更喜欢设置它,因为UTF8非常灵活,这将创建所有簇作为UTF8 [除非你另外明确指定])那么你需要创建你的用户(如果它还没有创建)
$ createuser -s -U postgres$ Enter name of role to add: {{ my login name }}(这似乎是Construct)那么你可以退出postgres用户,你可以创建自己的数据库
$ createdb| 归档时间: | 
 | 
| 查看次数: | 30316 次 | 
| 最近记录: |