如何第一次配置postgresql? [英] How to configure postgresql for the first time?

查看:451
本文介绍了如何第一次配置postgresql?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚安装了postgresql,我在安装过程中指定了密码x。
当我尝试 createdb 并指定任何密码时,我收到以下消息:


createdb:无法连接到数据库postgres:FATAL:用户密码认证失败

> createuser 。



我应该如何开始?
我可以将自己作为用户添加到数据库吗?

解决方案

其他答案不完全令我满意。


  1. 使用postgres连接到默认数据库:

    p>


    sudo -u postgres psql template1



  2. p>设置用户postgres的密码,然后退出psql(Ctrl-D):


    ALTER USER postgres使用加密密码'xxxxxxx';



  3. 编辑 pg_hba.conf 档案:


    sudo vim /etc/postgresql/9.1/main/pg_hba.conf


    并且在关于postgres的行上将peer改为md5:


    local       all       postgres       peer md5



  4. 重新启动数据库:


    sudo /etc/init.d / postgresql restart


    (这里可以检查它是否与 psql -U postgres 。)


  5. 创建与您同名的用户(要找到它,您可以键入 whoami ):


    createuser -U postgres -d -e -E -l -P -r -s < my_name>


    这些选项告诉postgresql创建一个用户登录,创建数据库,创建新角色,是超级用户,并且将具有加密密码。真正重要的是-P -E,这样你会被要求输入将被加密的密码,和-d,这样你可以做一个 createdb 。 / p>

    小心密码:它会首先询问您两次新密码(新用户),重复,然后一次postgres密码


  6. 再次编辑 pg_hba.conf 文件(参见步骤2) 3),并在关于所有其他用户的行上将peer改为md5:


    local    ;    all      全部      peer md5



  7. 重新启动(类似于第4步),并检查您是否可以不使用-U postgres登录:


    psql template1


    请注意,如果你只做一个 psql ,它将失败,因为它会尝试连接到一个与您同名的默认数据库(即。 whoami )。 template1是从头开始的管理数据库。


  8. 现在 createdb< dbname> 工作



I have just installed postgresql and I specified password x during installation. When I try to do createdb and specify any password I get the message:

createdb: could not connect to database postgres: FATAL: password authentication failed for user

Same for createuser.

How should I start? Can I add myself as a user to the database?

解决方案

The other answers were not completely satisfying to me. Here's what worked for postgresql-9.1 on Xubuntu 12.04.1 LTS.

  1. Connect to the default database with user postgres :

    sudo -u postgres psql template1

  2. Set the password for user postgres, then exit psql (Ctrl-D) :

    ALTER USER postgres with encrypted password 'xxxxxxx';

  3. Edit the pg_hba.conf file :

    sudo vim /etc/postgresql/9.1/main/pg_hba.conf

    And change "peer" to "md5" on the line concerning postgres :

    local      all     postgres     peer md5

  4. Restart the database :

    sudo /etc/init.d/postgresql restart

    (Here you can check it worked with psql -U postgres.)

  5. Create a user having the same name as you (to find it, you can type whoami) :

    createuser -U postgres -d -e -E -l -P -r -s <my_name>

    The options tell postgresql to create a user that can login, create databases, create new roles, is a superuser, and will have an encrypted password. The really important ones are -P -E, so that you're asked to type the password that will be encrypted, and -d so that you can do a createdb.

    Beware of passwords : it will first ask you twice the new password (for the new user), repeated, and then once the postgres password (the one specified on step 2).

  6. Again, edit the pg_hba.conf file (see step 3 above), and change "peer" to "md5" on the line concerning "all" other users :

    local      all     all     peer md5

  7. Restart (like in step 4), and check that you can login without -U postgres :

    psql template1

    Note that if you do a mere psql, it will fail since it will try to connect you to a default database having the same name as you (ie. whoami). template1 is the admin database that is here from the start.

  8. Now createdb <dbname> should work.

这篇关于如何第一次配置postgresql?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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