Can't get postgresql working

In the past, I've used mysql with rails without problem. I need to work
with postgresql, but I'm having trouble getting it working. I've seen
conflicting reports on what gems are needed. My latest install was

sudo gem install postgres --
--with-pgsql-include-dir=/Library/PostgreSQL8/include
--with-pgsql-lib-dir=/Library/PostgreSQL8/lib

(note: I did this blindly. It's about my 6th try to get proper gems in
place)

I'm running Rails 2.3.8 and PostgreSQL 8.4.2

My .yml configuration is
development:
  adapter: postgresql
  database: movies
  username: michael2
  port: 5432
  allow_concurrency: true
  encoding: SQL_ASCII

When I try to do a test connect with rake db:migrate, I get the
following:

rake db:migrate --trace
(in /oldhome/michael/projects/movies)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
syntax error on line 3, col 9: ` adapter: postgresql'
/usr/lib/ruby/1.8/yaml.rb:133:in `load'
/usr/lib/ruby/1.8/yaml.rb:133:in `load'

In the past, I've used mysql with rails without problem. I need to work
with postgresql, but I'm having trouble getting it working. I've seen
conflicting reports on what gems are needed. My latest install was

sudo gem install postgres --
--with-pgsql-include-dir=/Library/PostgreSQL8/include
--with-pgsql-lib-dir=/Library/PostgreSQL8/lib

(note: I did this blindly. It's about my 6th try to get proper gems in
place)

Not your error, but for what it's worth, I'm using the 'pg' gem without any issues.

I'm running Rails 2.3.8 and PostgreSQL 8.4.2

My .yml configuration is
development:
adapter: postgresql
database: movies
username: michael2
port: 5432
allow_concurrency: true
encoding: SQL_ASCII

When I try to do a test connect with rake db:migrate, I get the
following:

rake db:migrate --trace
(in /oldhome/michael/projects/movies)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
syntax error on line 3, col 9: ` adapter: postgresql'
/usr/lib/ruby/1.8/yaml.rb:133:in `load'
/usr/lib/ruby/1.8/yaml.rb:133:in `load'
        ---------

Can anyone offer some help? Thanks much

Rails is failing on a syntax error in your database.yml file. It has nothing to do with PostgreSQL at this point.

My guess is that instead of two leading spaces on that line you've got a tab. Or some other unicode character pretending to be a space...

Fix that and see what happens...

-philp

Philip Hallstrom wrote in post #969102:

Rails is failing on a syntax error in your database.yml file. It has
nothing to do with PostgreSQL at this point.

My guess is that instead of two leading spaces on that line you've got a
tab. Or some other unicode character pretending to be a space...

Fix that and see what happens...

-philp

That certainly changed the result. Now it's

rake db:migrate --trace
(in /oldhome/michael/projects/movies)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
rake aborted!
uninitialized constant
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::PGconn

Rails is failing on a syntax error in your database.yml file. It has
nothing to do with PostgreSQL at this point.

My guess is that instead of two leading spaces on that line you've got a
tab. Or some other unicode character pretending to be a space...

Fix that and see what happens...

-philp

That certainly changed the result. Now it's

rake db:migrate --trace
(in /oldhome/michael/projects/movies)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
rake aborted!
uninitialized constant
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::PGconn

Try the 'pg' gem.

Philip Hallstrom wrote in post #969122:

ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::PGconn

Try the 'pg' gem.

I just installed it. Same result.

I'm not sure my gem is installing correctly, though - or if there is
something else needed. Note the following:

   irb(main):001:0> require 'pg'
   => true
   irb(main):002:0> cn = PGconn.open(:dbname => 'movies')
   NameError: uninitialized constant PGconn
     from (irb):2

I really do appreciate this help.

Michael Satterwhite wrote in post #969123:

Philip Hallstrom wrote in post #969122:

ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::PGconn

Try the 'pg' gem.

I just installed it. Same result.

I'm not sure my gem is installing correctly, though - or if there is
something else needed. Note the following:

   irb(main):001:0> require 'pg'
   => true
   irb(main):002:0> cn = PGconn.open(:dbname => 'movies')
   NameError: uninitialized constant PGconn
     from (irb):2

That is strange. Maybe try to check which constants where added
when you execute the "require 'pg'" command ?

$ irb
ruby-1.9.2-p0 > c = Object.constants ; nil #=> nil (remember constants)
ruby-1.9.2-p0 > require 'pg' #=> true
ruby-1.9.2-p0 > Object.constants - c # which constants where added?
=> [:ConditionVariable, :Queue, :SizedQueue, :Etc, :RbConfig, :Config,
:CROSS_COMPILING, :Date, :Pathname, :PGError, :PGconn, :PGresult]
ruby-1.9.2-p0 > PGconn #=> PGconn (constant is defined )
ruby-1.9.2-p0 > cn = PGconn.open(:dbname => 'movies')
PGError: could not connect to server: No such file or directory
...

HTH,

Peter

Peter Vandenabeele wrote in post #969157:

That is strange. Maybe try to check which constants where added
when you execute the "require 'pg'" command ?

$ irb
ruby-1.9.2-p0 > c = Object.constants ; nil #=> nil (remember constants)
ruby-1.9.2-p0 > require 'pg' #=> true
ruby-1.9.2-p0 > Object.constants - c # which constants where added?
=> [:ConditionVariable, :Queue, :SizedQueue, :Etc, :RbConfig, :Config,
:CROSS_COMPILING, :Date, :Pathname, :PGError, :PGconn, :PGresult]
ruby-1.9.2-p0 > PGconn #=> PGconn (constant is defined )
ruby-1.9.2-p0 > cn = PGconn.open(:dbname => 'movies')
PGError: could not connect to server: No such file or directory
...

HTH,

Peter

First, I like your way of checking the constants. Being dense, I did
that manually when I had to - thanks much!

Now, something is DEFINITELY wrong. Here is the result of my run:

irb(main):001:0>c = Object.constants
   ---whole bunch of constants displayed ---
irb(main):002:0> require 'pg'
=> true
irb(main):003:0> Object.constants - c
=> []

What in heaven's name could cause this?

---Michael

Michael Satterwhite wrote in post #969166:

irb(main):001:0>c = Object.constants
   ---whole bunch of constants displayed ---
irb(main):002:0> require 'pg'
=> true
irb(main):003:0> Object.constants - c
=> []

What in heaven's name could cause this?

---Michael

More information:

I just uninstalled gem 'pg'. I then executed the following:

irb
irb(main):001:0> require 'pg'
=> true

In other words, it is still finding 'pg' after uninstalling the gem.
That's likely the problem. How can I find out where this is coming from
so I can get rid of it and reinstall pg?

As always, thanks to you experts.

Michael Satterwhite wrote in post #969123:

Philip Hallstrom wrote in post #969122:

ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::PGconn

Try the 'pg' gem.

I just installed it. Same result.

I'm not sure my gem is installing correctly, though - or if there is
something else needed. Note the following:

   irb(main):001:0> require 'pg'
   => true
   irb(main):002:0> cn = PGconn.open(:dbname => 'movies')
   NameError: uninitialized constant PGconn
     from (irb):2

Actually ... are you using ruby 1.8.x ?

Is that line

  irb(main):001> require 'pg'

really your first line in the irb session ?

Should you not do

  require 'rubygems'

first ? (IIRC, required in 1.8.x but no longer in 1.9.x)

My previous test was on ruby 1.9.2 and may have confused
both of us (sorry for that ...).

In ruby 1.8.7 (system ruby), I see this:

peterv@ASUS:~$ rvm use
Now using system ruby. # which 1.8.7.249-2 on Ubuntu 10.04
peterv@ASUS:~$ gem list | grep pg
pg (0.10.0)
peterv@ASUS:~$ irb
irb(main):001:0> require 'pg' # should NOT work yet
LoadError: no such file to load -- pg
  from (irb):1:in `require'
  from (irb):1
irb(main):002:0> require 'rubygems'
=> true
irb(main):003:0> require 'pg'
=> true
irb(main):004:0> Object.constants.grep(/PG/)
=> ["PGconn", "PGresult", "PGError"]

HTH,

Peter

Peter Vandenabeele wrote in post #969175:

Michael Satterwhite wrote in post #969123:

Philip Hallstrom wrote in post #969122:

ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::PGconn

Try the 'pg' gem.

I just installed it. Same result.

I'm not sure my gem is installing correctly, though - or if there is
something else needed. Note the following:

   irb(main):001:0> require 'pg'
   => true
   irb(main):002:0> cn = PGconn.open(:dbname => 'movies')
   NameError: uninitialized constant PGconn
     from (irb):2

Actually ... are you using ruby 1.8.x ?

Is that line

  irb(main):001> require 'pg'

really your first line in the irb session ?

Should you not do

  require 'rubygems'

first ? (IIRC, required in 1.8.x but no longer in 1.9.x)

I have the environment variable

   RUBYOPT=rubygems

set. This causes 1.8.x to automatically set rubygems as in 1.9.x.

Michael Satterwhite wrote in post #969181:

Peter Vandenabeele wrote in post #969175:

Michael Satterwhite wrote in post #969123:

...

I just installed it. Same result.

I'm not sure my gem is installing correctly, though - or if there is
something else needed. Note the following:

   irb(main):001:0> require 'pg'
   => true
   irb(main):002:0> cn = PGconn.open(:dbname => 'movies')
   NameError: uninitialized constant PGconn
     from (irb):2

Actually ... are you using ruby 1.8.x ?

Is that line

  irb(main):001> require 'pg'

really your first line in the irb session ?

Should you not do

  require 'rubygems'

first ? (IIRC, required in 1.8.x but no longer in 1.9.x)

I have the environment variable

   RUBYOPT=rubygems

set. This causes 1.8.x to automatically set rubygems as in 1.9.x.

Ah, thanks for that info.
It works that way here too.

peterv@ASUS:~$ export RUBYOPT=rubygems
peterv@ASUS:~$ echo $RUBYOPT
rubygems
peterv@ASUS:~$ irb
irb(main):001:0> require 'pg'
=> true
irb(main):002:0> Object.constants.grep(/PG/)
=> ["PGconn", "PGresult", "PGError"]

Peter

Peter Vandenabeele wrote in post #969183:

Ah, thanks for that info.
It works that way here too.

peterv@ASUS:~$ export RUBYOPT=rubygems
peterv@ASUS:~$ echo $RUBYOPT
rubygems
peterv@ASUS:~$ irb
irb(main):001:0> require 'pg'
=> true
irb(main):002:0> Object.constants.grep(/PG/)
=> ["PGconn", "PGresult", "PGError"]

Actually, yours works much better ... mine isn't working, remember. <g>

Any idea of how I can find where that bogus 'pg' is coming from? The gem
isn't installed anymore, but "require 'pg'" still returns true - loading
no constants.

Michael Satterwhite wrote in post #969184:

Peter Vandenabeele wrote in post #969183:

Ah, thanks for that info.
It works that way here too.

peterv@ASUS:~$ export RUBYOPT=rubygems
peterv@ASUS:~$ echo $RUBYOPT
rubygems
peterv@ASUS:~$ irb
irb(main):001:0> require 'pg'
=> true
irb(main):002:0> Object.constants.grep(/PG/)
=> ["PGconn", "PGresult", "PGError"]

Actually, yours works much better ... mine isn't working, remember. <g>

Any idea of how I can find where that bogus 'pg' is coming from? The gem
isn't installed anymore, but "require 'pg'" still returns true - loading
no constants.

Aha, this might hint where your seemingly
succeeded require is getting its input ?
After the require, the $LOAD_PATH has grown !

irb(main):004:0> puts $LOAD_PATH
/usr/local/lib/site_ruby/1.8
/usr/local/lib/site_ruby/1.8/i486-linux
/usr/local/lib/site_ruby/1.8/i386-linux
/usr/local/lib/site_ruby
/usr/lib/ruby/vendor_ruby/1.8
/usr/lib/ruby/vendor_ruby/1.8/i486-linux
/usr/lib/ruby/vendor_ruby
/usr/lib/ruby/1.8
/usr/lib/ruby/1.8/i486-linux
/usr/lib/ruby/1.8/i386-linux
.
=> nil
irb(main):005:0> require 'pg'
=> true
irb(main):006:0> puts $LOAD_PATH
/usr/lib/ruby/gems/1.8/gems/pg-0.10.0/bin
/usr/lib/ruby/gems/1.8/gems/pg-0.10.0/lib
/usr/lib/ruby/gems/1.8/gems/pg-0.10.0/ext
/usr/local/lib/site_ruby/1.8
/usr/local/lib/site_ruby/1.8/i486-linux
/usr/local/lib/site_ruby/1.8/i386-linux
/usr/local/lib/site_ruby
/usr/lib/ruby/vendor_ruby/1.8
/usr/lib/ruby/vendor_ruby/1.8/i486-linux
/usr/lib/ruby/vendor_ruby
/usr/lib/ruby/1.8
/usr/lib/ruby/1.8/i486-linux
/usr/lib/ruby/1.8/i386-linux
.
=> nil

Also, I had ran those 2 on my machine here (from the root directory):

peterv@ASUS:/$ find . -name 'pg.rb' 2>/dev/null
./home/peterv/.rvm/gems/ruby-1.9.2-p0/gems/pg-0.10.0/lib/pg.rb
./usr/lib/ruby/gems/1.8/gems/pg-0.10.0/lib/pg.rb

peterv@ASUS:/$ find . -name 'pg.so' 2>/dev/null

and that seems correct:
* 1 time pg.rb in .rvm/gems for 1.9.2 (from the first example I showed)
* 1 time pg.rb in /user/lib/gems/1.8 ... (system ruby)

no files pg.so found.

A long shot, but you could try that too and compare ...

HTH,

Peter

Peter Vandenabeele wrote in post #969187:

Michael Satterwhite wrote in post #969184:

Peter Vandenabeele wrote in post #969183:

Ah, thanks for that info.
It works that way here too.

peterv@ASUS:~$ export RUBYOPT=rubygems
peterv@ASUS:~$ echo $RUBYOPT
rubygems
peterv@ASUS:~$ irb
irb(main):001:0> require 'pg'
=> true
irb(main):002:0> Object.constants.grep(/PG/)
=> ["PGconn", "PGresult", "PGError"]

Actually, yours works much better ... mine isn't working, remember. <g>

Any idea of how I can find where that bogus 'pg' is coming from? The gem
isn't installed anymore, but "require 'pg'" still returns true - loading
no constants.

Aha, this might hint where your seemingly
succeeded require is getting its input ?
After the require, the $LOAD_PATH has grown !

THANK YOU, THANK YOU, THANK YOU!!!!

This piece led me to a rogue gem that I'd installed when I was trying to
get started. The require 'pg' is now giving the proper results and the
test

   rake db:migrate

connects to the database.

I *REALLY* appreciate this!

---Michael