【问题标题】:Create user postgres on Ubuntu在 Ubuntu 上创建用户 postgres
【发布时间】:2015-07-02 16:34:40
【问题描述】:

所以我在 Ubuntu 上安装了 postgresql9.3。 现在我必须创建一个新用户。因此,使用超级用户 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 上的每个新用户都不需要这样做。

【问题讨论】:

标签: sql postgresql ubuntu


【解决方案1】:

您正在混合使用 PostgreSQL 用户和 UNIX 用户,这是完全不同的事情。

CREATE USER python with PASSWORD 'python';

该命令只创建PostgreSQL用户,不创建任何UNIX用户,可以通过/etc/passwd文件中显示用户列表来查看。

如果您还需要 UNIX 用户,则必须自己创建(或编写脚本)。

【讨论】:

  • 谢谢,我现在明白了:)
猜你喜欢
  • 1970-01-01
  • 2019-04-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-03-05
  • 2013-03-13
  • 2019-05-09
  • 1970-01-01
相关资源
最近更新 更多