PostgreSQL error: Fatal: role “username” does not exist

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

问题:

I'm setting up my PostgreSQL 9.1. I can't do anything with PostgreSQL: can't createdb, can't createuser; all operations return the error message

Fatal: role h9uest does not exist

h9uest is my account name, and I sudo apt-get install PostgreSQL 9.1 under this account.
Similar error persists for the root account.

回答1:

You probably need to use the system user postgres to create your database - as long as you haven't set up (and given the necessary privileges to) a database user named "h9uest" that corresponds to your system user of the same name, so it is enabled by the default ident authentication method.

sudo su - postgres

Or the more modern form:

sudo -u postgres -i

As recommended here and here.

Then try again. Type exit when done with operating as system user postgres.

Read about database roles and client authentication in the manual.



回答2:

After trying many other peoples solutions, and without success, this answer finally helped me.

https://stackoverflow.com/a/16974197/2433309

In short, running

sudo -u postgres createuser owning_user

creates a role with name owning_user (in this case, h9uest). After that you can run rake db:create from the terminal under whatever account name you set up without having to enter into the postgres environment.



回答3:

sudo su - postgres  psql template1

creating role on pgsql with privilege as "superuser"

CREATE ROLE username superuser; eg. CREATE ROLE demo superuser;

Then create user

CREATE USER username;  eg. CREATE USER demo;

Assign privilege to user

GRANT ROOT TO username;

And then enable login that user, so you can run e.g.: psql template1, from normal $ terminal:

ALTER ROLE username WITH LOGIN;


回答4:

Installing postgres using apt-get does not create a user role or a database.

To create a superuser role and a database for your personal user account:

sudo -u postgres createuser -s $(whoami); createdb $(whoami)



回答5:

This works for me:

psql -h localhost -U postgres


回答6:

In local user prompt, not root user prompt, type

sudo -u postgres createuser 

Then enter password for local user.

Then enter the previous command that generated "role 'username' does not exist."

Above steps solved the problem for me. If not, please send terminal messages for above steps.



回答7:

Working method,

  1. vi /etc/postgresql/9.3/main/pg_hba.conf
  2. local all postgres peer here change peer to trust
  3. restart, sudo service postgresql restart

  4. now try, psql -U postgres



回答8:

Follow These Steps and it Will Work For You :

  1. run msfconsole
  2. type db_console
  3. some information will be shown to you chose the information who tell you to make: db_connect user:pass@host:port.../database sorry I don't remember it but it's like this one then replace the user and the password and the host and the database with the information included in the database.yml in the emplacement: /usr/share/metasploit-framework/config
  4. you will see. rebuilding the model cache in the background.
  5. Type apt-get update && apt-get upgrade after the update restart the terminal and lunch msfconsole and it works you can check that by typing in msfconsole: msf>db_status you will see that it's connected.


回答9:

Uninstalling everything and keeping Postgres.app:

brew cask uninstall postgres brew uninstall postgres brew cask install postgres rm -rf /Applications/Postgres93.app/ # shutdown any postgres instance # open postgres.app -> "Initialize"

I wanted PostgreSQL 9.6



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