简体   繁体   中英

Rails in production mode does not connect to second database

I am using rails 3.2.15. I have two postgresql databases one of them main and the other postgis. From model Postgis I make connection to postgis database like this:

class Postgis < ActiveRecord::Base
  establish_connection :postgis_db
  self.table_name = 'geometry_columns'
  self.inheritance_column = :_type_disabled
end

In development mode everything working. But when I switch to production web server fail to start with next exception

gems/activerecord-3.2.15/lib/active_record/connection_adapters/postgresql_adapter.rb:1163:in `exec': PG::UndefinedTable: ERROR:  relation "postgis" does not exist (ActiveRecord::StatementInvalid)
LINE 5:              WHERE a.attrelid = '"postgis"'::regclass
                                        ^
:             SELECT a.attname, format_type(a.atttypid, a.atttypmod),
                     pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
              FROM pg_attribute a LEFT JOIN pg_attrdef d
                ON a.attrelid = d.adrelid AND a.attnum = d.adnum
             WHERE a.attrelid = '"postgis"'::regclass
               AND a.attnum > 0 AND NOT a.attisdropped
             ORDER BY a.attnum

It does not connect to postgis database and try to find postgis table in main database. I try different ways to connect to postgis DB, but the result is same.

Edited:

database.yml :

postgis_db:
  adapter: postgresql
  encoding: utf8
  reconnect: false
  database: mydb_gis
  pool: 5
  username: osmsrv
  password: osmsrv
  host: localhost
  schema_search_path: public
production:
  adapter: postgresql
  encoding: utf8
  reconnect: false
  database: gis
  pool: 5
  username: osmsrv
  password: osmsrv
  host: localhost

I solved the problem. About 10 days ago I made model with connection to second DB and it worked fine. When I switch to production I was sure that connection works in development, but I was wrong. In development connection also not works. The problem was in gem 'texticle' "2.0". After removing it, connection works fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM