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

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

是否需要重置密码,或者如何创建具有超级用户权限的新用户?

我是Postgres的新手,刚刚安装了它.我正在try 将其与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. 放置以下行(作为第一个未注释行或唯一一行):

对于以下所有情况(本地和主机),exepct复制

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

    sudo /etc/init.d/postgresql restart

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

    此生成不支持本地连接

    你应该改变

    local all all trust

    host all all 127.0.0.1/32 trust

  2. 您现在可以作为任何用户进行连接.以超级用户postgres的身份连接(注the superuser name may be different in your installation. In some systems it is called 101, f或 example.)

    psql -U postgres

    psql -h 127.0.0.1 -U postgres

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

  3. Reset passw或d ('replace my_user_name with postgres since you are resetting postgres user)

    ALTER USER my_user_name with passw或d 'my_secure_passw或d';

  4. Res到re the old pg_hba.conf as it is very dangerous 到 keep around

    cp pg_hba.conf-backup pg_hba.conf

  5. restart the server, in 或der 到 run with the safe pg_hba.conf

    sudo /etc/init.d/postgresql restart

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

Postgresql相关问答推荐

在postgres中查找多个表中不同列的计数和总和

PostgreSQL散列连接与嵌套循环和散列索引

Postgres SQL:获取列值在连续日期之间已更改的行

在Go中从Kafka读取并写入PostgreSQL时如何处理错误?

在 Postgresql 中实现自定义运算符时出错

EF Core和npgsql连接池已被耗尽

pgadmin db 限制服务器属性不起作用

替代在 PostgreSQL 函数中嵌套正则表达式替换?

如何为 JavaEE 应用程序中的 PostgreSQL 热备设置配置连接故障转移?

在psql中,为什么有些命令没有效果?

获取 PostgreSQL 中当前正在运行的查询的参数

Rails 4 迁移: has_and_belongs_to_many table name

子查询的自连接

如何从 PostgreSQL 中的 Json 数组中获取元素

PL/pgSQL 执行与执行

如何在 postgres 查询中排名

IF处或附近的 Postgres 语法错误

用于将布尔列排序为 true、null、false 的 SQL

基于秒的 Postgresql 日期差异

postgresql 删除级联