2015-05-28 62 views
0

我已經創造了PostgreSQL數據庫的新用戶,PostgreSQL用戶登錄

create user newusr with password 'password'; 
postgres=# alter user newusr with superuser; 

,但我不能用這個用戶名登錄...

sudo -u newusr psql 

爲什麼以及如何更改這個? 我在ubuntu上

+1

'psql -U newusr'呢? –

+0

您是否嘗試過指定「主機」? -h 127.0.0.1 http://www.postgresql.org/docs/current/static/auth-pg-hba-conf.html – voytech

+1

'sudo -u newusr'切換到不同的** Linux **用戶,它不會將您登錄到數據庫中。根本不需要使用'sudo'。只需使用'psql -u newusr' –

回答

0

Postgres通常維護一個完全獨立的Ubuntu用戶列表。要創建一個linux用戶,您通常會使用如下命令:useradd

您發出的CREATE USER命令爲數據庫創建了一個新用戶。這意味着您可以(取決於pg_hba.conf設置)使用用戶名newusr和密碼「password」連接到postgres數據庫。

通常使用的命令,例如:

psql -U newusr 

您使用變化的操作系統用戶sudo命令。在這種特殊情況下,我假設它有消息示數,如:

sudo: unknown user: newusr 
sudo: unable to initialize policy plugin 

這是因爲newusr只存在於數據庫中。