问题描述
尝试连接到我的postgres数据库时遇到严重问题。我运行 psql,然后收到此错误 psql:FATAL:角色不存在。然后,我使用psql -U postgres登录到postgres,尝试使用我的用户名创建角色,然后出现此错误角色已经存在。我到处搜寻解决方案。有人知道发生了什么吗?我使用的是Windows10。
I am having a serious issue trying to connect to my postgres database. I run 'psql' then I get this error "psql: FATAL: role "" does not exist". Then I log into postgres using psql -U postgres, tried creating a role with my username, then I get this error "role already exists". I searched all over for a solution. Does anyone know what's going on? I'm on Windows 10.
推荐答案
您可能安装了两个版本的postgres。至少在Ubuntu上,这就是我遇到的问题。我不得不(警告此操作可能会删除datbase,我不知道: sudo apt remove postgres\ *
),它将选择所有Postgres版本并卸载它们。
You may have two versions of postgres installed. At least, on Ubuntu, that's the problem I had. I had to (warning this may delete datbases, I do not know: sudo apt remove postgres\*
) which will select all versions of Postgres and uninstall them.
在Windows上,使用图形界面卸载后,您将确认没有其他Postgres服务器正在运行。
On Windows you'd verify no other postgres servers are running after uninstalling with the graphical interface.
然后重新安装正确版本的Postgres(对我来说,对于Odoo 11,它是9.4)
Then reinstall the correct version of Postgres (for me it was 9.4 for Odoo 11)
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install postgresql-9.4
然后,我做了:(仅POSIX系统需要 sudo
/ su
)
Then, I did: (sudo
/su
is required only for POSIX systems)
sudo su - postgres -c "createuser -s $USER"
sudo -u postgres psql -c "ALTER USER $USER WITH SUPERUSER;"
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO $USER;"
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO $USER;"
sudo -u postgres psql -c "CREATE DATABASE $USER;"
psql
如果您想要备份用户
sudo su - postgres -c "createuser -s backup"
sudo -u postgres psql -c "GRANT SELECT ON ALL TABLES IN SCHEMA public TO backup;"
sudo -u postgres psql -c "ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO backup;"
或者,您可以尝试使用pgadmin3,但是我发现该界面很困难
这篇关于Postgres错误:角色<用户名>不存在,角色<用户名>已经存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!