0

创建rails new项目后,我已修改database.yml以连接到从节点维护的远程postgresql只读数据库:cardano-db-sync

development:
  <<: *default
  adapter: postgresql
  encoding: utf8
  database: cexplorer
  username: <%= ENV['PG_USERNAME'] %>
  password: <%= ENV['PG_PWD'] %>
  host: <%= ENV['IP_PG_SERVER'] %>
  port: 5432
  pool: 3 

运行后rake db:create我可以毫无问题地启动rails server和访问localhost:3000,没有给出关于数据库的错误。

连接到远程数据库psql cexplorer -U bswan -h xx.xxx.xx.xxx -p 5432没有问题,我可以看到填充数据库的表cexplorer

[backend] $ psql cexplorer -U user -h xx.xxx.xx.xxx -p 5432 
Password for user user: **

cexplorer=# \d
                    List of relations
 Schema |            Name             |   Type   | Owner 
--------+-----------------------------+----------+-------
 public | block                       | table    | user
 public | block_id_seq                | sequence | user
 public | delegation                  | table    | user
 public | delegation_id_seq           | sequence | user
 public | epoch                       | table    | user
...
...

问题

启动rails console以测试数据库我没有从连接的数据库返回任何表:

[backend] $ rails console
2.6.1 :001 > ActiveRecord::Base.connection.tables
 => [] 

我怎么看不到我看穿的桌子psql

2.6.1 :002 > ActiveRecord::Base.clear_all_connections!
 => [#<ActiveRecord::ConnectionAdapters::ConnectionPool:0x00007f9b034a5628 @mon_mutex=#<Thread::Mutex:0x00007f9b034a54c0>, @mon_mutex_owner_object_id=70151875930900, @mon_owner=nil, @mon_count=0, @query_cache_enabled=#<Concurrent::Map:0x00007f9b034a5498 entries=0 default_proc=#<Proc:0x00007f9b034a5380@/Users/sergio/.rvm/gems/ruby-2.6.1/gems/activerecord-6.0.3.4/lib/active_record/connection_adapters/abstract/query_cache.rb:32>>, @spec=#<ActiveRecord::ConnectionAdapters::ConnectionSpecification:0x00007f9b034a5ab0 @name="primary", @config={:adapter=>"postgresql", :encoding=>"utf8", :pool=>3, :database=>"cexplorer", :username=>nil, :password=>nil, :host=>nil, :port=>5432}, @adapter_method="postgresql_connection">, @checkout_timeout=5, @idle_timeout=300.0, @size=3, @thread_cached_conns=#<Concurrent::Map:0x00007f9b034a5330 entries=0 default_proc=nil>, @connections=[], @automatic_reconnect=true, @now_connecting=0, @threads_blocking_new_connections=0, @available=#<ActiveRecord::ConnectionAdapters::ConnectionPool::ConnectionLeasingQueue:0x00007f9b034a5150 @lock=#<ActiveRecord::ConnectionAdapters::ConnectionPool:0x00007f9b034a5628 ...>, @cond=#<MonitorMixin::ConditionVariable:0x00007f9b034a5128 @monitor=#<ActiveRecord::ConnectionAdapters::ConnectionPool:0x00007f9b034a5628 ...>, @cond=#<Thread::ConditionVariable:0x00007f9b034a5038>>, @num_waiting=0, @queue=[]>, @lock_thread=false, @reaper=#<ActiveRecord::ConnectionAdapters::ConnectionPool::Reaper:0x00007f9b034a4b60 @pool=#<ActiveRecord::ConnectionAdapters::ConnectionPool:0x00007f9b034a5628 ...>, @frequency=60.0>>] 
2.6.1 :003 > ActiveRecord::Base.connection.tables
 => [] 
4

0 回答 0