4

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.

John Bachir
  • 22,495
  • 29
  • 154
  • 227
Ortwin Gentz
  • 52,648
  • 24
  • 135
  • 213

4 Answers4

7

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.

dbenhur
  • 20,008
  • 4
  • 48
  • 45
5

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.

Ortwin Gentz
  • 52,648
  • 24
  • 135
  • 213
  • @KonstantinGredeskoul the latest source uses [`Shellwords.escape`](https://github.com/rails/rails/blob/3-2-stable/activerecord/lib/active_record/railties/databases.rake#L428) on the filename and database name, (but, curiously, not the search_path); so it's much better now. Though really using [`Open3::capture2`](http://www.ruby-doc.org/stdlib-2.0/libdoc/open3/rdoc/Open3.html#method-c-capture2) with array args is generally safer than [`Kernel::\``](http://www.ruby-doc.org/core-2.0/Kernel.html#method-i-60) – dbenhur Jan 26 '14 at 00:51
  • Thanks, I did research for given string. And for me it doesn't work because PATH in spring's environment did not contain path to pg_dump. – Евгений Масленков Feb 16 '16 at 12:07
1

I had a simillar problem with db:structure:dump on my setup. Rails 3.2.11 + JRuby 1.7.1[1.8 mode] Postgresql 9.1.7.

The only thing which really helped was downgrading activerecord_jdbc_adapter from version 1.2.5 to 1.2.2.

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

Hope it will help anybody.

Piotr Brudny
  • 654
  • 4
  • 16
0

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. Now when I run rake db:migrate, there are no pg_dump error. I hope this helps someone.

eduludi
  • 1,618
  • 21
  • 23