gpt4 book ai didi

ruby-on-rails - Ubuntu/Rails PG::InsufficientPrivilege: ERROR: permission denied to create database

转载 作者:行者123 更新时间:2023-12-04 18:45:54 28 4
gpt4 key购买 nike

我在我的 Ubuntu 16.04 Droplet 上托管一个 rails 应用程序。我已经配置了 Apache 并且得到了 FATAL: database "MyAppName_development" does not exist , raise ActiveRecord::NoDatabaseError.new(error.message, error)
数据库.yml

default: &default
adapter: postgresql
encoding: unicode
# For details on connection pooling, see rails configuration guide
# http://guides.rubyonrails.org/configuring.html#database-pooling
pool: 5

development:
<<: *default
database: MyAppName_development

test:
<<: *default
database: MyAppName_test

production:
<<: *default
database: MyAppName_production
username: myusername
password: <%= ENV['MYAPPNAME_DATABASE_PASSWORD'] %>

我从我的 Droplet 中运行了以下命令:
sudo -i -u postgres

psql

# Inside psql:
CREATE USER myusername WITH PASSWORD mypassword
CREATE DATABASE MyAppName_production
CREATE DATABASE MyAppName_test
CREATE DATABASE MyAppName_development
GRANT ALL PRIVILEGES ON DATABASE MyAppName_production to myusername
GRANT ALL PRIVILEGES ON DATABASE MyAppName_test to myusername
GRANT ALL PRIVILEGES ON DATABASE MyAppName_development to myusername
ALTER USER myusername CREATEDB
\q

exit

从我的 Droplet 中的 MyAppName 根目录中,我运行了 bundle exec rake db:drop ,然后 bundle exec rake db:create:all并得到以下信息:
PG::InsufficientPrivilege: ERROR:  permission denied to create database
: CREATE DATABASE "MyAppName_development" ENCODING = 'unicode'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `async_exec'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `block in execute'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract_adapter.rb:472:in `block in log'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.6/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract_adapter.rb:466:in `log'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/connection_adapters/postgresql/database_statements.rb:154:in `execute'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/connection_adapters/postgresql/schema_statements.rb:78:in `create_database'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/tasks/postgresql_database_tasks.rb:15:in `create'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/tasks/database_tasks.rb:93:in `create'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/tasks/database_tasks.rb:102:in `block in create_all'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/tasks/database_tasks.rb:284:in `block in each_local_configuration'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/tasks/database_tasks.rb:280:in `each_value'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/tasks/database_tasks.rb:280:in `each_local_configuration'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/tasks/database_tasks.rb:102:in `create_all'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/railties/databases.rake:11:in `block (3 levels) in <top (required)>'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/task.rb:248:in `block in execute'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/task.rb:243:in `each'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/task.rb:243:in `execute'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/task.rb:187:in `block in invoke_with_call_chain'
/home/myusername/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/task.rb:180:in `invoke_with_call_chain'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/task.rb:173:in `invoke'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/application.rb:150:in `invoke_task'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/application.rb:106:in `each'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/application.rb:106:in `block in top_level'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/application.rb:115:in `run_with_threads'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/application.rb:100:in `top_level'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/application.rb:78:in `block in run'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/application.rb:176:in `standard_exception_handling'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/application.rb:75:in `run'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/bin/rake:33:in `<top (required)>'
/home/myusername/.rvm/gems/ruby-2.3.1/bin/rake:23:in `load'
/home/myusername/.rvm/gems/ruby-2.3.1/bin/rake:23:in `<main>'
/home/myusername/.rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in `eval'
/home/myusername/.rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in `<main>'
Couldn't create database for {"username"=>"myusername", "adapter"=>"postgresql", "encoding"=>"unicode", "pool"=>5, "database"=>"MyAppName_development", "password"=>nil}
PG::InsufficientPrivilege: ERROR: permission denied to create database
: CREATE DATABASE "MyAppName_test" ENCODING = 'unicode'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `async_exec'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `block in execute'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract_adapter.rb:472:in `block in log'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.6/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract_adapter.rb:466:in `log'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/connection_adapters/postgresql/database_statements.rb:154:in `execute'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/connection_adapters/postgresql/schema_statements.rb:78:in `create_database'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/tasks/postgresql_database_tasks.rb:15:in `create'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/tasks/database_tasks.rb:93:in `create'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/tasks/database_tasks.rb:102:in `block in create_all'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/tasks/database_tasks.rb:284:in `block in each_local_configuration'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/tasks/database_tasks.rb:280:in `each_value'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/tasks/database_tasks.rb:280:in `each_local_configuration'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/tasks/database_tasks.rb:102:in `create_all'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/railties/databases.rake:11:in `block (3 levels) in <top (required)>'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/task.rb:248:in `block in execute'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/task.rb:243:in `each'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/task.rb:243:in `execute'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/task.rb:187:in `block in invoke_with_call_chain'
/home/myusername/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/task.rb:180:in `invoke_with_call_chain'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/task.rb:173:in `invoke'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/application.rb:150:in `invoke_task'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/application.rb:106:in `each'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/application.rb:106:in `block in top_level'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/application.rb:115:in `run_with_threads'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/application.rb:100:in `top_level'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/application.rb:78:in `block in run'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/application.rb:176:in `standard_exception_handling'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/application.rb:75:in `run'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/bin/rake:33:in `<top (required)>'
/home/myusername/.rvm/gems/ruby-2.3.1/bin/rake:23:in `load'
/home/myusername/.rvm/gems/ruby-2.3.1/bin/rake:23:in `<main>'
/home/myusername/.rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in `eval'
/home/myusername/.rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in `<main>'
Couldn't create database for {"username"=>"myusername", "adapter"=>"postgresql", "encoding"=>"unicode", "pool"=>5, "database"=>"MyAppName_test", "password"=>nil}
PG::InsufficientPrivilege: ERROR: permission denied to create database
: CREATE DATABASE "MyAppName_production" ENCODING = 'unicode'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `async_exec'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `block in execute'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract_adapter.rb:472:in `block in log'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.6/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract_adapter.rb:466:in `log'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/connection_adapters/postgresql/database_statements.rb:154:in `execute'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/connection_adapters/postgresql/schema_statements.rb:78:in `create_database'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/tasks/postgresql_database_tasks.rb:15:in `create'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/tasks/database_tasks.rb:93:in `create'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/tasks/database_tasks.rb:102:in `block in create_all'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/tasks/database_tasks.rb:284:in `block in each_local_configuration'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/tasks/database_tasks.rb:280:in `each_value'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/tasks/database_tasks.rb:280:in `each_local_configuration'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/tasks/database_tasks.rb:102:in `create_all'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/railties/databases.rake:11:in `block (3 levels) in <top (required)>'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/task.rb:248:in `block in execute'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/task.rb:243:in `each'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/task.rb:243:in `execute'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/task.rb:187:in `block in invoke_with_call_chain'
/home/myusername/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/task.rb:180:in `invoke_with_call_chain'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/task.rb:173:in `invoke'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/application.rb:150:in `invoke_task'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/application.rb:106:in `each'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/application.rb:106:in `block in top_level'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/application.rb:115:in `run_with_threads'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/application.rb:100:in `top_level'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/application.rb:78:in `block in run'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/application.rb:176:in `standard_exception_handling'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/application.rb:75:in `run'
/home/myusername/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/bin/rake:33:in `<top (required)>'
/home/myusername/.rvm/gems/ruby-2.3.1/bin/rake:23:in `load'
/home/myusername/.rvm/gems/ruby-2.3.1/bin/rake:23:in `<main>'
/home/myusername/.rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in `eval'
/home/myusername/.rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in `<main>'
Couldn't create database for {"username"=>"myusername", "adapter"=>"postgresql", "encoding"=>"unicode", "pool"=>5, "database"=>"MyAppName_production", "password"=>nil}

最佳答案

我建议您可以在迁移之前在 postgres 中重置数据库。

pg:reset DATABASE_NAME

然后在你的项目目录中
rake db:schema:load
rake db:migrate

如果你有种子数据
rake db:seed

关于ruby-on-rails - Ubuntu/Rails PG::InsufficientPrivilege: ERROR: permission denied to create database,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41401397/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com