[英]Dump postgres DB rails
There is a lot of info about how to dump a database so it can be moved into production, but none of it seems to mention what the username of the database should be. 关于如何转储数据库,以便可以将其移入生产环境,有很多信息,但是似乎都没有提到数据库的用户名。
This is from Heroku, but I can't find the username... 这是来自Heroku,但我找不到用户名...
PGPASSWORD=mypassword pg_dump -Fc --no-acl --no-owner -h localhost -U myuser mydb mydb.dump
This is from a rake task I found on Github 这是我在Github上发现的一个rake任务
desc "Dumps the database to db/APP_NAME.dump"
task :dump => :environment do
cmd = nil
with_config do |app, host, db, user|
cmd = "pg_dump --host #{host} --username #{user} --verbose --clean --no-owner --no-acl --format=c #{db} > #{Rails.root}/db/#{app}.dump"
end
puts cmd
exec cmd
end
def with_config
yield Rails.application.class.parent_name.underscore,
ActiveRecord::Base.connection_config[:host],
ActiveRecord::Base.connection_config[:database],
ActiveRecord::Base.connection_config[:username]
end
It generates the following command with the following error. 它生成带有以下错误的以下命令。
pg_dump --host --username --verbose --clean --no-owner --no-acl --format=c kelp_development > /home/yiti/code/ymagoon/kelp/db/kelp.dump
pg_dump: [archiver (db)] connection to database "kelp_development" failed: could not translate host name "--username" to address: Name or service not known
You can find the details about your postgres database on the Heroku Dashboard: 您可以在Heroku仪表板上找到有关postgres数据库的详细信息:
Don't forget the warning on this page: Please note that these credentials are not permanent. 不要忘记此页面上的警告: 请注意,这些凭据不是永久的。
As per the description and code shared it seems like you have not specified the host , database and username. 根据描述和共享的代码,似乎您尚未指定主机,数据库和用户名。
Below mentioned command shows that it is not picking up the configuration from the with_config method defined in the rake task. 下面提到的命令表明它没有从rake任务中定义的with_config方法中获取配置。
pg_dump --host --username --verbose --clean --no-owner --no-acl --format=c kelp_development > /home/yiti/code/ymagoon/kelp/db/kelp.dump
You can create a configuration object with the below mentioned code 您可以使用以下代码创建配置对象
config = Rails::Configuration.new
host = config.database_configuration[RAILS_ENV]["host"]
database = config.database_configuration[RAILS_ENV]["database"]
Get the database credentials from DATABASE_URL scheme://username:password@host:port/database 从DATABASE_URL方案://用户名:密码@主机:端口/数据库获取数据库凭证
Now you can directly dump the data to postgres database from the below mentioned commmad: 现在,您可以从下面提到的commmad直接将数据转储到postgres数据库:
pg_dump -h host_name -U user_name --verbose --clean --no-owner --no-acl --format=c db_name > path_to_dump_file.dump
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.