# File lib/jdbc_adapter/jdbc_postgre.rb, line 229
    def structure_dump
      abcs = ActiveRecord::Base.configurations

      database = nil
      if abcs[RAILS_ENV]["url"] =~ /\/([^\/]*)$/
        database = $1
      else
        raise "Could not figure out what database this url is for #{abcs[RAILS_ENV]["url"]}"
      end
    
      ENV['PGHOST']     = abcs[RAILS_ENV]["host"] if abcs[RAILS_ENV]["host"]
      ENV['PGPORT']     = abcs[RAILS_ENV]["port"].to_s if abcs[RAILS_ENV]["port"]
      ENV['PGPASSWORD'] = abcs[RAILS_ENV]["password"].to_s if abcs[RAILS_ENV]["password"]
      search_path = abcs[RAILS_ENV]["schema_search_path"]
      search_path = "--schema=#{search_path}" if search_path

      @connection.connection.close
      begin
        file = "db/#{RAILS_ENV}_structure.sql"
        `pg_dump -i -U "#{abcs[RAILS_ENV]["username"]}" -s -x -O -f #{file} #{search_path} #{database}`
        raise "Error dumping database" if $?.exitstatus == 1
        
        # need to patch away any references to SQL_ASCII as it breaks the JDBC driver
        lines = File.readlines(file)
        File.open(file, "w") do |io|
          lines.each do |line|
            line.gsub!(/SQL_ASCII/, 'UNICODE')
            io.write(line)
          end
        end
      ensure
        reconnect!
      end  
    end