Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. I'm using Rails 3.2.3 and PostgreSQL 9.0.5. Other tasks like db:migrate or db:rollback work just fine.

like image 692
Ortwin Gentz Avatar asked Dec 13 '22 03:12

Ortwin Gentz


2 Answers

The pg_dump command is executed in activerecord/lib/active_record/railties/databases.rake at line 428.

`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. 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.

like image 133
dbenhur Avatar answered Dec 28 '22 17:12

dbenhur


Thanks to dbenhur I found the issue. I have a space in the path of my filename. Changing line 392 of activerecord/lib/active_record/railties/databases.rake to

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

(adding the single quotes around #{filename}) fixes the issue.

like image 27
Ortwin Gentz Avatar answered Dec 28 '22 17:12

Ortwin Gentz