问题原文
原帖链接 · Lay González · CC BY-SA 3.0
I think that, accidentally, I changed my user to a role with no log in allowed. Now I can't even log in to give log in privileges to the role. Is there something I can do?
I think there was only 1 user and I don't know how to list all my users if I can't log in first.
Thanks
Addendum
I reinstalled postgres and it seems that no postgres user exists. I installed it via brew:
已采纳解答
原帖链接 · Erik Jones · CC BY-SA 3.0
The main superuser account is set up by initdb when run and will default to the current system user name, not postgres, unless an explicit -u/--username argument is given. From your above \du output it's clear that when you set up the server you did it with your laygr system user as that user is the database server's main superuser account.
Should you mess up your login privileges or forget your password you can get back into the server if you have write access to it's data directory in order to be able to edit pg_hba.conf. Just change the auth-method on the relevant line to trust and reload the server's config via pg_ctl reload. You can then log in, fix your user/password, and then revert the changes you made to pg_hba.conf and reload the config again.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
