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

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

问题描述

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

psql: FATAL:  password authentication failed for user "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 或应该出现同伴共阳极化.

local  all   all   trust

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

    sudo /etc/init.d/postgresql restart

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

    此构建不支持

    本地连接

    您应该更改

    local all all trust

    host all all 127.0.0.1/32 trust

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

    psql -U postgres

    psql -h 127.0.0.1 -U postgres

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

  3. 重置密码(由于您要重置 postgres 用户,请用 postgres 替换my_user_name)

    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天全站免登陆