Ruby Error

ActiveRecord::ConnectionNotEstablished

ActiveRecord::ConnectionNotEstablished is raised when Rails cannot connect to the database. This can happen at startup or during runtime if the connection is lost.

Common causes

  • Database server not running
  • Incorrect database credentials
  • Wrong database host/port
  • Connection pool exhausted
  • Network connectivity issues

How to fix it

  • Verify database server is running
  • Check database.yml credentials
  • Test connection with rails db commands
  • Increase connection pool size
  • Check firewall/network settings

Example

ActiveRecord::ConnectionNotEstablished example
# Error when database unavailable
User.first  # => ActiveRecord::ConnectionNotEstablished

# Check database.yml
default: &default
  adapter: postgresql
  host: <%= ENV.fetch("DATABASE_HOST", "localhost") %>
  username: <%= ENV.fetch("DATABASE_USER", "postgres") %>
  password: <%= ENV.fetch("DATABASE_PASSWORD", "") %>
  pool: <%= ENV.fetch("RAILS_MAX_THREADS", 5) %>

# Test connection
# $ rails db:ping  (Rails 7.1+)
# $ rails runner "ActiveRecord::Base.connection"

# Reconnect if connection lost
ActiveRecord::Base.connection_pool.with_connection do |conn|
  conn.execute("SELECT 1")
end

Track ActiveRecord::ConnectionNotEstablished with Checkend

Checkend automatically captures ActiveRecord::ConnectionNotEstablished errors in your Ruby application with full context:

  • Complete backtrace with syntax highlighting
  • Request context (URL, params, headers)
  • Automatic grouping of similar errors
  • Instant notifications when errors occur

Stop debugging in production

Get full error context and fix issues faster with self-hosted error tracking.