LoginSignup
1
1

More than 5 years have passed since last update.

railsで開発環境のDBをPostgreSQLにするときにroleがローカルユーザー名になっててはまった話

Posted at

デフォルトのユーザー「postgres」でPostgreSQLにログインしたときにroleがローカルのユーザー名になっていて、修正に時間がとられたのでここにまとめておきます。結構強引に解決したので、扱いには注意が必要だと思います。

開発環境

  • windows7
  • ruby 2.4.5p335 (2018-10-18 revision 65137) [x64-mingw32]
  • Rails 5.2.3
  • psql (PostgreSQL) 10.7

事前準備

$ rails new YOUR_APP -d postgresql
$ rails g scaffold YOUR_MODEL_NAME
$ rails db:create db:migrate

エラー内容

該当コマンド:rails db:create db:migrate

$ rails db:create db:migrate
Created database '<app_name>'
FATAL:  role "<user_name>" does not exist
Couldn't create '<app_name>' database. Please check your configuration
rails aborted!
ActiveRecord::NoDatabaseError: FATAL:  role "<user_name>" does not exist.

解決法

PostgreSQLに管理者権限を持つ"postgres"でログインする。

psql --username=postgres

に管理者権限(ついでにログイン権限)を付加して、PostgreSQLから抜ける。

postgres=# CREATE ROLE <user_name> SUPERUSER;
postgres=# ALTER ROLE <user_name> LOGIN;
postgres=# \n

これで正常に動作するはずです。

参考サイト

エンジニアの入り口|【初心者向け】PostgreSQLのロールについて分かり易く解説
https://eng-entrance.com/postgresql-role

1
1
0

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
1
1