2

これは本当に私を行き詰まらせます.Rails 4にpostgresを使用しようとするのは少し初心者です.

私はpostgresをインストールしました:

$ psql --version
psql (PostgreSQL) 9.1.10
contains support for command-line editing

$ sudo apt-get install libpq-devうまくいった

私はgem 'pg'自分のgemfileに持っています

config/database.ymlのように見える:

development:
  adapter: postgresql
  encoding: unicode
  database: myafricastyle_development
  host: localhost
  pool: 5
  username: myafricastyle
  password: myafricastyle

データベースを作成します。$ sudo -u postgres createdb myafricastyle_development

データベースは次のとおりです。

$ psql
psql (9.1.10)
Type "help" for help.

jasonshark=# \l
                                           List of databases
           Name            |   Owner    | Encoding |   Collate   |    Ctype    |   Access privileges   
---------------------------+------------+----------+-------------+-------------+-----------------------
 jasonshark                | jasonshark | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 myafricastyle_development | postgres   | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 postgres                  | postgres   | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 template0                 | postgres   | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
                           |            |          |             |             | postgres=CTc/postgres
 template1                 | postgres   | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
                           |            |          |             |             | postgres=CTc/postgres
(5 rows)

しかし、その後、Rails プロジェクト ディレクトリ内にセットアップしようとすると、次のようになります。

$ rake db:create:all
FATAL:  password authentication failed for user "myafricastyle"
FATAL:  password authentication failed for user "myafricastyle"

編集: これは私のpg_hba.confファイルです:

local   all             postgres                                md5

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     md5
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local   replication     postgres                                md5
#host    replication     postgres        127.0.0.1/32            md5
#host    replication     postgres        ::1/128                 md5

編集を行ったときにsudo gedit pg_hba.conf、フォルダーがちょっとファンキーに見えるようにしましたが:

/etc/postgresql/9.1/main$ ls
environment  pg_hba.conf   pg_ident.conf    start.conf
pg_ctl.conf  pg_hba.conf~  postgresql.conf

何を変更できますか?

4

1 に答える 1

1

ユーザーを作成する必要があります。

sudo -u postgres createuser myafricastyle

ユーザーを作成したら、次のドキュメントに記載されているように、pg_hba.conf ファイルも編集する必要があります。

http://www.postgresql.org/docs/9.1/static/auth-pg-hba-conf.html

于 2013-11-12T10:23:12.437 に答える