PostgreSQL w Railsach - błąd podczas tworzenia bazy

mam problem z adaptacją postgresa. Poniżej przedstawiłem listing błędu przy próbie rake db:create

no such file to load -- pg C:/Ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.3/lib/active_support/depen cies.rb:239:in `require' C:/Ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.3/lib/active_support/depen cies.rb:239:in `block in require' C:/Ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.3/lib/active_support/depen cies.rb:225:in `block in load_dependency' C:/Ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.3/lib/active_support/depen cies.rb:596:in `new_constants_in' C:/Ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.3/lib/active_support/depen cies.rb:225:in `load_dependency' C:/Ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.3/lib/active_support/depen cies.rb:239:in `require' C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/connect _adapters/postgresql_adapter.rb:9:in `postgresql_connection' C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/connect _adapters/abstract/connection_pool.rb:228:in `new_connection' C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/connect _adapters/abstract/connection_pool.rb:236:in `checkout_new_connection' C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/connect _adapters/abstract/connection_pool.rb:190:in `block (2 levels) in checkout' C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/connect _adapters/abstract/connection_pool.rb:186:in `loop' C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/connect _adapters/abstract/connection_pool.rb:186:in `block in checkout' C:/Ruby/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize' C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/connect _adapters/abstract/connection_pool.rb:185:in `checkout' C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/connect _adapters/abstract/connection_pool.rb:93:in `connection' C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/connect _adapters/abstract/connection_pool.rb:316:in `retrieve_connection' C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/connect _adapters/abstract/connection_specification.rb:97:in `retrieve_connection' C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/connect _adapters/abstract/connection_specification.rb:89:in `connection' C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/railtie atabases.rake:56:in `create_database' C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/railtie atabases.rake:35:in `block (2 levels) in <top (required)>' C:/Ruby/lib/ruby/1.9.1/rake.rb:634:in `call' C:/Ruby/lib/ruby/1.9.1/rake.rb:634:in `block in execute' C:/Ruby/lib/ruby/1.9.1/rake.rb:629:in `each' C:/Ruby/lib/ruby/1.9.1/rake.rb:629:in `execute' C:/Ruby/lib/ruby/1.9.1/rake.rb:595:in `block in invoke_with_call_chain' C:/Ruby/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize' C:/Ruby/lib/ruby/1.9.1/rake.rb:588:in `invoke_with_call_chain' C:/Ruby/lib/ruby/1.9.1/rake.rb:581:in `invoke' C:/Ruby/lib/ruby/1.9.1/rake.rb:2041:in `invoke_task' C:/Ruby/lib/ruby/1.9.1/rake.rb:2019:in `block (2 levels) in top_level' C:/Ruby/lib/ruby/1.9.1/rake.rb:2019:in `each' C:/Ruby/lib/ruby/1.9.1/rake.rb:2019:in `block in top_level' C:/Ruby/lib/ruby/1.9.1/rake.rb:2058:in `standard_exception_handling' C:/Ruby/lib/ruby/1.9.1/rake.rb:2013:in `top_level' C:/Ruby/lib/ruby/1.9.1/rake.rb:1992:in `run' C:/Ruby/bin/rake:31:in `<main>'
config:
windows 7, ruby 1.92, rails 3, postgres 8.3 / 9.0, gem postgres-pg

A nie brakuje Ci przypadkiem gemu pg?

 gem install pg

[code]Building native extensions. This could take a while…
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.

C:/Ruby/bin/ruby.exe extconf.rb
checking for pg_config… no
checking for libpq-fe.h… *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.

Provided configuration options:
–with-opt-dir
–without-opt-dir
–with-opt-include
–without-opt-include=${opt-dir}/include
–with-opt-lib
–without-opt-lib=${opt-dir}/lib
–with-make-prog
–without-make-prog
–srcdir=.
–curdir
–ruby=C:/Ruby/bin/ruby
–with-pg
–without-pg
–with-pg-config
–without-pg-config
–with-pg-dir
–without-pg-dir
–with-pg-include
–without-pg-include=${pg-dir}/include
–with-pg-lib
–without-pg-lib=${pg-dir}/lib
C:/Ruby/lib/ruby/1.9.1/mkmf.rb:368:in try_do': The complier failed to generate an executable file. (RuntimeError) You have to install development tools first. from C:/Ruby/lib/ruby/1.9.1/mkmf.rb:452:intry_cpp’
from C:/Ruby/lib/ruby/1.9.1/mkmf.rb:853:in block in find_header' from C:/Ruby/lib/ruby/1.9.1/mkmf.rb:693:inblock in checking_for’
from C:/Ruby/lib/ruby/1.9.1/mkmf.rb:280:in block (2 levels) in postpone ' from C:/Ruby/lib/ruby/1.9.1/mkmf.rb:254:inopen’
from C:/Ruby/lib/ruby/1.9.1/mkmf.rb:280:in block in postpone' from C:/Ruby/lib/ruby/1.9.1/mkmf.rb:254:inopen’
from C:/Ruby/lib/ruby/1.9.1/mkmf.rb:276:in postpone' from C:/Ruby/lib/ruby/1.9.1/mkmf.rb:692:inchecking_for’
from C:/Ruby/lib/ruby/1.9.1/mkmf.rb:852:in find_header' from extconf.rb:123:in

Gem files will remain installed in C:/Ruby/lib/ruby/gems/1.9.1/gems/pg-0.10.0 fo
r inspection.
Results logged to C:/Ruby/lib/ruby/gems/1.9.1/gems/pg-0.10.0/ext/gem_make.out[/code]
a w database.yml mam:

  adapter: postgresql
checking for libpq-fe.h... *** extconf.rb failed ***

Brakuje pliku libpq-fe.h, jest on w plikach nagłówkowych klienta postgresa, w linuksach byłby to pakiet w stylu postgres-dev, ale jak to pod windowsem zrobić? Poguglaj za “windows postgres headers”, “windows pg gem”.

dodałem do PATH ścieżkę do postgresql/bin
teraz wywala coś takiego:

[code]Building native extensions. This could take a while…
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.

C:/Ruby/bin/ruby.exe extconf.rb
checking for pg_config… yes
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.

Provided configuration options:
–with-opt-dir
–without-opt-dir
–with-opt-include
–without-opt-include=${opt-dir}/include
–with-opt-lib
–without-opt-lib=${opt-dir}/lib
–with-make-prog
–without-make-prog
–srcdir=.
–curdir
–ruby=C:/Ruby/bin/ruby
–with-pg
–without-pg
–with-pg-config
–without-pg-config
extconf.rb:33:in ``’: No such file or directory - C:\Program Files\PostgreSQL\8.
3\bin\pg_config.exe --cflags (Errno::ENOENT)
from extconf.rb:33:in `’

Gem files will remain installed in C:/Ruby/lib/ruby/gems/1.9.1/gems/pg-0.10.0 fo
r inspection.
Results logged to C:/Ruby/lib/ruby/gems/1.9.1/gems/pg-0.10.0/ext/gem_make.out[/code]
ps> dodam, że przy rails 2.3.2 nie ma błędów od bazy.
ps2> zastanawiam się nad skorzystaniem jakiejś dystrybucji linuxa, czy w linuxie są też problemy przy użytkowaniu ruby+rails+postgres? co polecacie?

“C:\Program Files\PostgreSQL\8.3\bin\pg_config.exe” istnieje?

Linux albo MacOS X to najlepszy wybór dla programistów Rubiego w dłuższej perspektywie.

Po wypróbowaniu kilkunastu rozwiązań, w końcu udało się:

  1. instalujemy pg wersję 0.9.0,
gem install pg -v=0.9.0
  1. edytujemy gemfile,

#Comment out the sqlite3 requirement #gem 'sqlite3-ruby', :require => 'sqlite3' #Add a pg requirement gem 'pg', :require => 'pg'
3. sprawdzamy.

bundle install