Unrecognized error type (ActiveRecord::StatementInvalid: PG::ProgramLimitExceeded

メール送信中に、セルフホストされた Discourse のユーザーが以下をトリガーしました。

Message

未認識のエラータイプ (ActiveRecord::StatementInvalid: PG::ProgramLimitExceeded: ERROR:  index row size 2904 exceeds btree version 4 maximum 2704 for index "index_incoming_emails_on_error"
DETAIL:  Index row references tuple (1,9) in relation "incoming_emails".
HINT:  Values larger than 1/3 of a buffer page cannot be indexed.
Consider a function index of an MD5 hash of the value, or use full text indexing.
) when processing incoming email

Backtrace:
  /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/rack-mini-profiler-2.3.3/lib/patches/db/pg.rb:69:in `exec_params'
  /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/rack-mini-profiler-2.3.3/lib/patches/db/pg.rb:69:in `exec_params'
  /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/postgresql_adapter.rb:672:in `block (2 levels) in exec_no_cache'
  /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activesupport-6.1.4.1/lib/active_support/dependencies/interlock.rb:48:in `block in permit_concurrent_loads'
  /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activesupport-6.1.4.1/lib/active_support/concurrency/share_lock.rb:187:in `yield_shares'
  /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activesupport-6.1.4.1/lib/active_support/dependencies/interlock.rb:47:in `permit_concurrent_loads'
  /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/postgresql_adapter.rb:671:in `block in exec_no_cache'
  /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract_adapter.rb:696:in `block (2 levels) in log'
  /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activesupport-6.1.4.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in synchronize'
  /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activesupport-6.1.4.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
  /var/www/discourse/...

Backtrace

/var/www/discourse/lib/email/processor.rb:91:in `handle_failure'
/var/www/discourse/lib/email/processor.rb:28:in `rescue in process!'
/var/www/discourse/lib/email/processor.rb:17:in `process!'
/var/www/discourse/lib/email/processor.rb:14:in `process!'
/var/www/discourse/app/jobs/scheduled/poll_mailbox.rb:23:in `process_popmail'
/var/www/discourse/app/jobs/scheduled/poll_mailbox.rb:43:in `block (2 levels) in poll_pop3'
/usr/local/lib/ruby/2.7.0/net/pop.rb:667:in `each'
/usr/local/lib/ruby/2.7.0/net/pop.rb:667:in `each_mail'
/var/www/discourse/app/jobs/scheduled/poll_mailbox.rb:40:in `block in poll_pop3'
/usr/local/lib/ruby/2.7.0/net/pop.rb:532:in `start'

application_version 6e4af0e36f8bec32d77bdb3c0051088efa8069e0

「いいね!」 1

PG13をご利用ですか?

真空引きとインデックス再構築を試してみてはいかがでしょうか。それらを検索すれば例が見つかると思いますが、PostgreSQL 13 update がヒントになるかもしれません。

これは、受信したメールのエラーメッセージが大きすぎてインデックスに登録できないことを意味します。エラーの最初の100文字の安全な部分文字列にインデックスを付ける必要があります。

「いいね!」 3