所以我在Ubuntu上安装了postgresql9.3。 现在我必须创建一个新用户。所以 super 用户 postgres 一切皆有可能。但我需要为每个新数据库创建一个新用户。
所以我做了什么:
sudo -u postgres psql
CREATE USER python with PASSWORD 'python';
CREATE DATABASE dbpython;
GRANT ALL PRIVILEGES ON DATABASE dbpython to python;
我还修改了/etc/postgresql/9.1/main/pg_hba.conf 文件,将本地frompeer 的身份验证设置更改为md5。
在我重新启动 postgres 之后,我想使用我的新用户:
ubuntu@ip-172-31-33-139:~$ su python
No passwd entry for user 'python'
但是
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=>
为什么它有效而 su python 无效? 重要说明:我没有在我的 Ubuntu 中创建一个新的 python 用户,我希望这不是每个 postgres 上的新用户都需要的。
最佳答案
您混合了 PostgreSQL 用户和 UNIX 用户,这是完全不同的事情。
CREATE USER python with PASSWORD 'python';
此命令只创建一个PostgreSQL用户,不创建任何UNIX用户,您可以通过在/etc/passwd
文件中显示用户列表来查看。
如果您还需要 UNIX 用户,则必须自己创建(或编写脚本)。
关于sql - 在 Ubuntu 上创建用户 postgres,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29841269/