Postgres入门级问题

时间:2012-08-10 10:53:21

标签: postgresql heroku

我最近搬到了Postgres并且遇到了形式的间歇性错误:

PGError: FATAL:  terminating connection due to administrator command
SSL connection has been closed unexpectedly: 
        SELECT a.attname, format_type(a.atttypid, a.atttypmod), 
               d.adsrc, a.attnotnull
          FROM pg_attribute a LEFT JOIN pg_attrdef d
            ON a.attrelid = d.adrelid AND a.attnum = d.adnum
         WHERE a.attrelid = '"xxxxxx"'::regclass
           AND a.attnum > 0 AND NOT a.attisdropped
         ORDER BY a.attnum

vendor/bundle/ruby/1.9.1/gems/activerecord-3.0.11/lib/active_record/
connection_adapters/postgresql_adapter.rb:505:in `exec'

我可以做些什么来解决这个问题(除了回到旧的Postgres Addon,这是我认为的临时解决方案。)

1 个答案:

答案 0 :(得分:5)

理想情况下,您的应用应该通过重新尝试其工作而不会误导用户来透明地应对数据库错误。如果空闲数据库后端从它下面关闭,它应该不关心,它应该只是建立一个新连接并再次启动事务。我不知道Rails和ActiveRecord如何实现这一点。

另见问题What's the cause of "PGError: FATAL: terminating connection due to administrator command" on heroku?

似乎Heroku会在他们进行维护时有时会杀死后端并重新启动服务器,这可能会解释您的问题,如果您的使用非常罕见。