我忘记了在安装 postgres 时输入的密码 [英] I forgot the password I entered during postgres installation

查看:22
本文介绍了我忘记了在安装 postgres 时输入的密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我忘记或错误输入了 Postgres 默认用户的密码(在安装过程中).我似乎无法运行它,并收到以下错误:

psql:致命:用户hisham"的密码验证失败hisham-agil: hisham$ psql

无论如何要重置密码或如何创建具有超级用户权限的新用户?

我是 Postgres 的新手,并且是第一次安装它.我正在尝试将它与 Rails 一起使用,并且我正在运行 Mac OS X Lion.

解决方案

  1. 找到文件 pg_hba.conf - 它可能位于,例如在 /etc/postgresql-9.1/pg_hba.conf 中.

    cd/etc/postgresql-9.1/

  2. 备份

    cp pg_hba.conf pg_hba.conf-backup

  3. 放置以下行(作为第一行未注释的行,或作为唯一行):

<块引用>

对于以下所有事件(本地和主机),除了复制如果您没有任何部分,则必须按照以下方式进行更改,没有 MD5或 Peer authication 应该存在.

本地所有所有信任

  1. 重启你的 PostgreSQL 服务器(例如,在 Linux 上:)

    sudo/etc/init.d/postgresql restart

    如果服务(守护进程)没有开始在日志文件中报告:

    <块引用>

    此版本不支持本地连接

    你应该改变

    local all all tr​​ust

    托管所有 127.0.0.1/32 信任

  2. 您现在可以作为任何用户进行连接.以超级用户 postgres 身份连接(注意,超级用户名在您的安装中可能会有所不同.例如,在某些系统中,它称为 pgsql.)

    psql -U postgres

    psql -h 127.0.0.1 -U postgres

    (请注意,使用第一个命令时,您将不会始终与本地主机连接)

  3. 重置密码('将 my_user_name 替换为 postgres,因为您正在重置 postgres 用户)

    ALTER USER my_user_name with password 'my_secure_password';

  4. 恢复旧的pg_hba.conf,因为它非常危险保留

    cp pg_hba.conf-backup pg_hba.conf

  5. 重启服务器,以安全运行pg_hba.conf

    sudo/etc/init.d/postgresql restart

进一步阅读关于该 pg_hba 文件:http://www.postgresql.org/docs/9.1/static/auth-pg-hba-conf.html

I either forgot or mistyped (during the installation) the password to the default user of Postgres. I can't seem to be able to run it and I get the following error:

psql: FATAL:  password authentication failed for user "hisham"
hisham-agil: hisham$ psql 

Is there anyway to reset the password or how do I create a new user with superuser privileges?

I am new to Postgres and just installed it for the first time. I am trying to use it with Rails and I am running Mac OS X Lion.

解决方案

  1. find the file pg_hba.conf - it may be located, for example in /etc/postgresql-9.1/pg_hba.conf.

    cd /etc/postgresql-9.1/

  2. Back it up

    cp pg_hba.conf pg_hba.conf-backup

  3. place the following line (as either the first uncommented line, or as the only one):

For all occurrence of below (local and host) , exepct replication section if you don't have any it has to be changed as follow ,no MD5 or Peer autehication should be present.

local  all   all   trust

  1. restart your PostgreSQL server (e.g., on Linux:)

    sudo /etc/init.d/postgresql restart

    If the service (daemon) doesn't start reporting in log file:

    local connections are not supported by this build

    you should change

    local all all trust

    to

    host all all 127.0.0.1/32 trust

  2. you can now connect as any user. Connect as the superuser postgres (note, the superuser name may be different in your installation. In some systems it is called pgsql, for example.)

    psql -U postgres

    or

    psql -h 127.0.0.1 -U postgres

    (note that with the first command you will not always be connected with local host)

  3. Reset password ('replace my_user_name with postgres since you are resetting postgres user)

    ALTER USER my_user_name with password 'my_secure_password';

  4. Restore the old pg_hba.conf as it is very dangerous to keep around

    cp pg_hba.conf-backup pg_hba.conf

  5. restart the server, in order to run with the safe pg_hba.conf

    sudo /etc/init.d/postgresql restart

Further Reading about that pg_hba file: http://www.postgresql.org/docs/9.1/static/auth-pg-hba-conf.html

这篇关于我忘记了在安装 postgres 时输入的密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆