简体   繁体   中英

ActiveRecord::StatementInvalid: PG::InsufficientPrivilege: ERROR: permission denied to create database in the rails 7

I got this below error while creating a database in the rails application

$ rails db:create
PG::InsufficientPrivilege: ERROR:  permission denied to create database
Couldn't create 'app_development' database. Please check your configuration.
rake aborted!
ActiveRecord::StatementInvalid: PG::InsufficientPrivilege: ERROR:  permission denied to create database

Caused by:
PG::InsufficientPrivilege: ERROR:  permission denied to create database

Tasks: TOP => db:create
(See full trace by running task with --trace)

This solution is worked for me, You can try the same if you face this error while rails db:create in the rails application.

$ sudo -u postgres -i
$ psql
postgres=# ALTER USER user_name CREATEDB;
ALTER ROLE
postgres=# create database "database_name" owner "user_name";
CREATE DATABASE
postgres=# GRANT ALL PRIVILEGES ON  DATABASE database_name to user_name;
GRANT
postgres=# ALTER DATABASE blog_development owner to user_name;
ALTER DATABASE

after the above steps run this rails db:create and it will work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM