Showing posts with label PostgreSQL. Show all posts
Showing posts with label PostgreSQL. Show all posts

Wednesday, February 8, 2012

RVM, jRuby, ActiveRecord::ConnectionNotEstablished, and PostgreSQL

I generated a new Rails 3 app with a PostgreSQL backend.  I was using the latest jRuby.

I started the server and got :

ActiveRecord::ConnectionNotEstablished

That was annoying.
I connected to the database from the command line and from another tool.
I ran rails console and got the following :

ArgumentError: syntax error on line 42, col 0: `'
                    load at org/yecht/ruby/YParser.java:152
                    load at /home/[USER NAME]/.rvm/rubies/jruby-1.6.5/lib/ruby/1.8/yaml.rb:134
  database_configuration at /home/[USER NAME]/.rvm/gems/jruby-1.6.5/gems/railties-3.2.1/lib/rails/application/configuration.rb:115


Taking a look at yaml.rb line 134 clued me in that I was using the wrong jRuby compatibility.

RVM to the rescue.  RVM is just pure goodness.  It really makes switching rubies a breeze.

The executive summary is that RVM makes it easy to run multiple versions of Ruby and/or Ruby gems.  To use jRuby :

rvm use jRuby

It even makes it easy to set jRuby's version compatibility.  RVM  allows you to specify hooks to run after its' methods.

jRuby 1.6.x has 1.8 and 1.9 Ruby compatibility.  To use 1.9 just add an "after_use" hook (this is detailed on the RVM site).

Monday, November 29, 2010

Recursive setfacl or how to add your PostgreSQL data directory to Git

This was an interesting annoyance.

I was working on some examples and wanted to be able to delete everything cleanly after I was done.

I had an instance of JBoss and wanted PostgreSQL to use a local directory for data.

My directory structure was :
example/
data
jboss-eap-5.1
logs

I had a user "postgres" to run PostgreSQL. Since the rest of the directory was created by me, "jeremy," I used setfacl to add "postgres" to the data directory:
setfacl -m u:postgres:rwx ./data/

When I ran :
initdb -D data/

It wasn't happy. I got :
"initdb: could not change permissions of directory"

Next up was :
sudo chown -R postgres:postgres data/

That worked for "initdb." I was able to su to the "postgres" user and execute "initdb" in "data/."

I was happy until I tried to add "data/" to Git :
[jeremy@jeremy example]$ git add data
error: open("data/PG_VERSION"): Permission denied
error: unable to index file data/PG_VERSION
fatal: adding files failed

setfacl to the rescue!
sudo setfacl -Rm u:jeremy:rwx ./data/

Unfortunately I got the same error.
I was missing the important "d" argument. The following worked :
sudo setfacl -Rm u:jeremy:rwx,d:u:jeremy:rwx ./data/
"sudo" was necessary because of changing the ownership to the "postgres" user.

I added everything to Git.

The moral of this rambling story : use the "d" flag with setfacl to cascade permissions to the files.