简体   繁体   English

rake db:structure:在PostgreSQL / Rails 3.2下转储失败

[英]rake db:structure:dump fails under PostgreSQL / Rails 3.2

I get this error message: 我收到此错误消息:

pg_dump: too many command-line arguments (first is "demo_db")
Try "pg_dump --help" for more information.
rake aborted!
Error dumping database

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

This used to work under Rails 3.1. 这曾经在Rails 3.1下工作。 I'm using Rails 3.2.3 and PostgreSQL 9.0.5. 我正在使用Rails 3.2.3和PostgreSQL 9.0.5。 Other tasks like db:migrate or db:rollback work just fine. db:migrate或db:rollback等其他任务工作正常。

The pg_dump command is executed in activerecord/lib/active_record/railties/databases.rake at line 428 . pg_dump命令在第428行的activerecord / lib / active_record / railties / databases.rake中执行

`pg_dump -i -s -x -O -f #{Shellwords.escape(filename)} #{search_path} #{Shellwords.escape(config['database'])}`

Try setting a breakpoint there and seeing what actual command is being run. 尝试在那里设置断点并查看正在运行的实际命令。

All those options are valid for Pg9.0.x, so I suspect there's something funny in abcs[Rails.env]['schema_search_path'] which confuses psql's option parsing. 所有这些选项对Pg9.0.x都有效,所以我怀疑在abcs[Rails.env]['schema_search_path']中有一些有趣的东西会混淆psql的选项解析。 Note the search_path construction doesn't quote the --schema argument, so a search_path_part with an embedded space will parse as a partial schema name followed by a word which isn't preceded by an option, so psql will interpret it as a database name, then complain when it gets to the real database name later. 请注意, search_path构造不引用--schema参数,因此具有嵌入空间的search_path_part将解析为部分模式名称,后跟一个前面没有选项的单词,因此psql会将其解释为数据库名称,然后在它稍后到达真实数据库名称时抱怨。

Thanks to dbenhur I found the issue. 感谢dbenhur,我发现了这个问题。 I have a space in the path of my filename. 我的文件名路径中有一个空格。 Changing line 392 of activerecord/lib/active_record/railties/databases.rake to activerecord/lib/active_record/railties/databases.rake第392行更改为

pg_dump -i -s -x -O -f '#{filename}' #{search_path} #{abcs[Rails.env]['database']}

(adding the single quotes around #{filename} ) fixes the issue. (在#{filename}周围添加单引号)可以解决问题。

I had a simillar problem with db:structure:dump on my setup. 我的db:structure:dump在我的设置上有一个simillar问题。 Rails 3.2.11 + JRuby 1.7.1[1.8 mode] Postgresql 9.1.7. Rails 3.2.11 + JRuby 1.7.1 [1.8模式] Postgresql 9.1.7。

The only thing which really helped was downgrading activerecord_jdbc_adapter from version 1.2.5 to 1.2.2. 唯一真正有用的是将activerecord_jdbc_adapter从版本1.2.5降级到1.2.2。

gem 'activerecord-jdbc-adapter', '1.2.2'
gem "activerecord-jdbcpostgresql-adapter", '1.2.2'

Hope it will help anybody. 希望它会对任何人有所帮助。

I fixed this (dark) issue by creating a new app with postgresql as database ( rails new MyApp -d postgresql ), and then move all my old app files (/app folder, migrations, and some /config files) to new one. 我通过创建一个以postgresql作为数据库的新应用程序( rails new MyApp -d postgresql )修复了这个(黑暗)问题,然后将我所有的旧应用程序文件(/ app文件夹,迁移和一些/配置文件)移动到新的应用程序文件。 Now when I run rake db:migrate, there are no pg_dump error. 现在当我运行rake db:migrate时,没有pg_dump错误。 I hope this helps someone. 我希望这可以帮助别人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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