psql fatal role does not exist

匿名 (未验证) 提交于 2019-12-03 02:45:02

问题:

I recently the lastest version of ubuntu and i'm not used to it yet. I had several problems connecting postgresql with pgadmin3.

I tryed to follow several tutorials to create a localhost server which I can use in pgadmin3. I didn't really hit the mark and I think I made it worse by installing, uninstalling, installing, uninstalling, trying answers I found... At this point I'm not sure my postgres is clean. It could be possible that I have two postgres installed, once again, I'm not sure. I tryed to uninstall it but I had an error which basicly said postgres wasn't in sudo.

The thing is I now have this error running psql in the console :

$psql psql: FATAL: role "user" does not exist  

I can't find the pg_hba.conf and at this point I'm too afraid to make things even worse by trying following any other posts.

How could I make this work?

回答1:

As pointed out in the comments, your pg_hba.conf seems fine.

Usually, the database will run as the postgres user (check ps aux | grep postgres to find out the username postgres is running under).

Log in as that user, for example sudo su - postgres, then create a user matching your normal Ubuntu user account (createuser username), and finally create a database with that same name and set the owner (-O) to that database user, like this: createdb -O username username).

That should make calling psql work, and pgadmin - as long as you start it as your default user, username - should work as well.

Edit: By default, psql will use your Linux username as default value for both the database-username and the database-name. You can override the username by using -U someotherusername, and connect to a different database by adding that DB name to the command line, such as psql someotherdbname. You might also find psql -l useful for listing the existing databases.



回答2:

sudo -u postgres createuser user 

may help you to create a new user with all the privileges of postgres



回答3:

Use the postgres user:

sudo su postgres 

and then use psql.

If you still face problems check this link: PostgreSQL error: Fatal: role "username" does not exist



回答4:

In windows 10 this works for fine

pg_restore --format=c --verbose --no-owner --no-privileges --dbname=MYDB --username=postgres --no-password --jobs=8 F:/MYBK.backup

--username=(role) and --no-password are necesaries



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!