postgresql 在 Ubuntu 上创建用户 postgres
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29841269/
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
Create user postgres on Ubuntu
提问by lvthillo
So I have installed postgresql9.3 on Ubuntu. Now I have to create a new user. So everything is possible with the superuser postgres. But I need for every new db a new user.
所以我在 Ubuntu 上安装了 postgresql9.3。现在我必须创建一个新用户。因此,超级用户 postgres 一切皆有可能。但是对于每个新数据库,我都需要一个新用户。
So what I did:
所以我做了什么:
sudo -u postgres psql
CREATE USER python with PASSWORD 'python';
CREATE DATABASE dbpython;
GRANT ALL PRIVILEGES ON DATABASE dbpython to python;
I also modified the /etc/postgresql/9.1/main/pg_hba.conf file and change the authentication setting of local frompeer to md5.
我还修改了/etc/postgresql/9.1/main/pg_hba.conf文件,将local frompeer的认证设置改为md5。
After I've restarted postgres I want use my new user:
重新启动 postgres 后,我想使用我的新用户:
ubuntu@ip-172-31-33-139:~$ su python
No passwd entry for user 'python'
But
但
ubuntu@ip-172-31-33-139:~$ sudo service postgresql restart
* Restarting PostgreSQL 9.3 database server [ OK ]
ubuntu@ip-172-31-33-139:~$ psql -d dbpython -U python
Password for user python:
psql (9.3.6)
Type "help" for help.
dbpython=>
Why is that working and the su python isn't? Important remark: I dit not create a new python user in my Ubuntu, I hope this isn't necessary for every new user on postgres.
为什么这有效而 su python 无效?重要说明:我没有在我的 Ubuntu 中创建一个新的 python 用户,我希望这对于 postgres 上的每个新用户都不是必需的。
回答by Blackus
You are mixing PostgreSQL user and UNIX user, which is a totally different thing.
您正在混合使用 PostgreSQL 用户和 UNIX 用户,这是完全不同的事情。
CREATE USER python with PASSWORD 'python';
This command only create a PostgreSQL user and do not create any UNIX user, you can check it by displaying user list on /etc/passwd
file.
此命令只创建一个 PostgreSQL 用户,不创建任何 UNIX 用户,您可以通过在/etc/passwd
文件中显示用户列表来检查它。
If you also want a UNIX user, you will have to create it yourself (or scripting it).
如果您还需要 UNIX 用户,则必须自己创建(或编写脚本)。