Changing Grails datasource to use PostgreSQL

18 01 2009

My database name is erace (not to have to type the actual name of the database each time I invoke psql).

  1. Get JDBC Driver for PostgreSQL
  2. Drop the jar in $project_home/lib
  3. Change $project_home/conf/DataSource.groovy to this:
    dataSource {
    	pooled = true
    	driverClassName = "org.postgresql.Driver"
    	username = "erace"
    	password = "passw0rd"
    }
    hibernate {
        cache.use_second_level_cache=true
        cache.use_query_cache=true
        cache.provider_class='com.opensymphony.oscache.hibernate.OSCacheProvider'
    }
    
    environments {
    	development {
    		dataSource {
    			dbCreate = "update" // one of 'create', 'create-drop','update'
    			url = "jdbc:postgresql:erace"
    		}
    	}
    	test {
    		dataSource {
    			dbCreate = "update"
    			url = "jdbc:postgresql:erace"
    		}
    	}
    	production {
    		dataSource {
    			dbCreate = "update"
    			url = "jdbc:postgresql:erace"
    		}
    	}
    }
            

Docs:
Grails Ref Guide on DataSource