LoginSignup
29
38

More than 3 years have passed since last update.

Ruby on RailsのデータベースをPostgreSQLに設定する。

Last updated at Posted at 2015-11-18

ググッた情報でやっても
rake db:create
FATAL: Ident authentication failed for user "username"
がでてうまくいかなかったのでメモ

環境

Amazon-EC2
CentOS
Rails 4.2.4

やったこと

PostgreSQLのインストール

$ sudo yum -y install postgresql94
$ sudo yum -y install postgresql94-devel
$ sudo yum -y install postgresql94-server
$ psql --version
psql (9.4.5)

初期化からの起動

$ sudo /etc/init.d/postgresql94 initdb
$ sudo /etc/init.d/postgresql94 start

PostgreSQLアカウントの設定

$ sudo -u postgres psql
postgres=# alter role postgres with password 'hogehoge';
postgres=# alter role [user_name] with password '[password]';

データベースの作成

postgres=# create database [database_name] owner [user_name];

アクセス権限の設定

$ vim /var/lib/pgsql94/data/pg_hba.conf

local all all peer
local all all md5に変更

Railの設定

アプリの作成

$ rails new myapp -d postgresql

config/database.ymlの設定

default: &default
  adapter: postgresql
  encoding: utf8
  pool: 5
  username: [username]
  password: [password] 

development:
  <<: *default
  database: myapp_development

test:
  <<: *default
  database: myapp_test

production:
  <<: *default
  database: myapp_production

データベース作成

rake db:create

以上の手順で出来たんですが、これであっているのか分からないので何か気づいたらコメントお願いします。

29
38
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
29
38