postgresql 如何检查postgres用户和密码?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15008204/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 00:03:23  来源:igfitidea点击:

How to check postgres user and password?

postgresql

提问by ThiagoLeal

A friend of mine done this config on my mac. But I don't know the username and password he had chosen.

我的一个朋友在我的 mac 上完成了这个配置。但我不知道他选择的用户名和密码。

回答by Thilo

You will not be able to find out the password he chose. However, you may create a new user or set a new password to the existing user.

您将无法找到他选择的密码。但是,您可以为现有用户创建新用户或设置新密码。

Usually, you can login as the postgres user:

通常,您可以以 postgres 用户身份登录:

Open a Terminal and do sudo su postgres. Now, after entering your admin password, you are able to launch psqland do

打开终端并执行sudo su postgres. 现在,输入您的管理员密码后,您就可以启动psql并执行

CREATE USER yourname WITH SUPERUSER PASSWORD 'yourpassword';

This creates a new admin user. If you want to list the existing users, you could also do

这将创建一个新的管理员用户。如果你想列出现有用户,你也可以这样做

\du

to list all users and then

列出所有用户,然后

ALTER USER yourusername WITH PASSWORD 'yournewpass';

回答by lite

You may change the pg_hba.conf and then reload the postgresql. something in the pg_hba.conf may be like below:

您可以更改 pg_hba.conf,然后重新加载 postgresql。pg_hba.conf 中的内容可能如下所示:

# "local" is for Unix domain socket connections only
local   all             all                                     trust
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust

then you change your user to postgresql, you may login successfully.

然后你把你的用户改成postgresql,你就可以成功登录了。

su postgresql