LoginSignup
0
0

More than 1 year has passed since last update.

Rails、PostgreSQLで ActiveRecord::StatementInvalid: PG::InsufficientPrivilege: ERROR: must be owner of database my_app_test と怒られる

Last updated at Posted at 2023-03-15

困ったこと

RSpec流そうとしたら怒られました。

$ be rspec                           
rails aborted!
ActiveRecord::StatementInvalid: PG::InsufficientPrivilege: ERROR:  must be owner of database my_app_test

解決

databaseの設定でuserをチェックします。

config/database.yml
default: &default
  username: <%= ENV.fetch("DBUSER") { "postgres" } %>

test:
  <<: *default
  database: my_app_test
  host: localhost

rails dbでDBに入り、\lでデータベースのリストを表示。
Ownerの欄を見ると、postgresではない人がいる。
ALTER DATABASE <DB名> OWNER TO <ユーザー名>;でオーナーを変更。

$ rails db
psql (13.10)
Type "help" for help.

my_app_development=# \l
                                             List of databases
               Name                |    Owner    | Encoding | Collate | Ctype |      Access privileges      
-----------------------------------+-------------+----------+---------+-------+-----------------------------
 my_app_test                       | kakudaisuke | UTF8     | C       | C     | 


my_app_development=# ALTER DATABASE my_app_test OWNER TO postgres;
ALTER DATABASE
my_app_development=# \l
                                             List of databases
               Name                |    Owner    | Encoding | Collate | Ctype |      Access privileges      
-----------------------------------+-------------+----------+---------+-------+-----------------------------
 my_app_test                       | postgres    | UTF8     | C       | C     | 


my_app_development=# exit

これで解決しました。

参考
https://stackoverflow.com/questions/7210563/rake-aborted-error-must-be-owner-of-database

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