2015-04-24 43 views
7

所以我在Ubuntu上安裝了postgresql9.3。 現在我必須創建一個新用戶。所以一切都可能與超級用戶postgres。但我需要爲每個新的數據庫創建一個新用戶。在Ubuntu上創建用戶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的我想用我的新用戶:

[email protected]:~$ su python 
No passwd entry for user 'python' 

[email protected]:~$ sudo service postgresql restart 
* Restarting PostgreSQL 9.3 database server        [ OK ] 
[email protected]:~$ psql -d dbpython -U python 
Password for user python: 
psql (9.3.6) 
Type "help" for help. 

dbpython=> 

這是爲什麼努力和蘇蟒是不是? 重要說明:我不會在我的Ubuntu中創建一個新的python用戶,我希望這對postgres上的每個新用戶都不是必需的。

+0

可能重複[如何在全新安裝後登錄並驗證Postgresql?](http://stackoverflow.com/questions/2172569/how-do-i-login-and-authenticate-to-postgresql-新鮮安裝後) –

回答

11

你在混合PostgreSQL用戶和UNIX用戶,這是完全不同的東西。

CREATE USER python with PASSWORD 'python'; 

該命令只創建一個PostgreSQL用戶,不產生任何UNIX用戶,您可以通過/etc/passwd文件顯示的用戶列表進行檢查。

如果您還需要UNIX用戶,則必須自己創建(或編寫腳本)。

+0

謝謝,我現在明白了:) – lvthillo