Skip Navigation
Show nav
Heroku Dev Center Dev Center
  • Get Started
  • Documentation
  • Changelog
  • Search
Heroku Dev Center Dev Center
  • Get Started
    • Node.js
    • Ruby on Rails
    • Ruby
    • Python
    • Java
    • PHP
    • Go
    • Scala
    • Clojure
    • .NET
  • Documentation
  • Changelog
  • More
    Additional Resources
    • Home
    • Elements
    • Products
    • Pricing
    • Careers
    • Help
    • Status
    • Events
    • Podcasts
    • Compliance Center
    Heroku Blog

    Heroku Blog

    Find out what's new with Heroku on our blog.

    Visit Blog
  • Log in or Sign up
View categories

Categories

  • Heroku Architecture
    • Compute (Dynos)
      • Dyno Management
      • Dyno Concepts
      • Dyno Behavior
      • Dyno Reference
      • Dyno Troubleshooting
    • Stacks (operating system images)
    • Networking & DNS
    • Platform Policies
    • Platform Principles
    • Buildpacks
  • Developer Tools
    • AI Tools
    • Command Line
    • Heroku VS Code Extension
  • Deployment
    • Deploying with Git
    • Deploying with Docker
    • Deployment Integrations
  • Continuous Delivery & Integration (Heroku Flow)
    • Continuous Integration
  • Language Support
    • Node.js
      • Troubleshooting Node.js Apps
      • Working with Node.js
      • Node.js Behavior in Heroku
    • Ruby
      • Rails Support
        • Working with Rails
      • Working with Bundler
      • Working with Ruby
      • Ruby Behavior in Heroku
      • Troubleshooting Ruby Apps
    • Python
      • Working with Python
      • Background Jobs in Python
      • Python Behavior in Heroku
      • Working with Django
    • Java
      • Java Behavior in Heroku
      • Working with Java
      • Working with Maven
      • Working with Spring Boot
      • Troubleshooting Java Apps
    • PHP
      • PHP Behavior in Heroku
      • Working with PHP
    • Go
      • Go Dependency Management
    • Scala
    • Clojure
    • .NET
      • Working with .NET
  • Databases & Data Management
    • Heroku Postgres
      • Postgres Basics
      • Postgres Getting Started
      • Postgres Performance
      • Postgres Data Transfer & Preservation
      • Postgres Availability
      • Postgres Special Topics
      • Heroku Postgres Advanced (Limited GA)
      • Migrating to Heroku Postgres
    • Heroku Key-Value Store
    • Apache Kafka on Heroku
    • Other Data Stores
  • AI
    • Inference Essentials
    • Inference API
    • Inference Quick Start Guides
    • AI Models
    • Tool Use
    • AI Integrations
    • Vector Database
  • Monitoring & Metrics
    • Logging
  • App Performance
  • Add-ons
    • All Add-ons
  • Collaboration
  • Security
    • App Security
    • Identities & Authentication
      • Single Sign-on (SSO)
    • Private Spaces
      • Infrastructure Networking
    • Compliance
  • Heroku Enterprise
    • Enterprise Accounts
    • Enterprise Teams
  • Patterns & Best Practices
  • Extending Heroku
    • Platform API
    • App Webhooks
    • Heroku Labs
    • Building Add-ons
      • Add-on Development Tasks
      • Add-on APIs
      • Add-on Guidelines & Requirements
    • Building CLI Plugins
    • Developing Buildpacks
    • Dev Center
  • Accounts & Billing
  • Troubleshooting & Support
  • Integrating with Salesforce
    • Heroku AppLink
      • Heroku AppLink Reference
      • Working with Heroku AppLink
      • Getting Started with Heroku AppLink
    • Heroku Connect (Salesforce sync)
      • Heroku Connect Administration
      • Heroku Connect Reference
      • Heroku Connect Troubleshooting
    • Other Salesforce Integrations
  • Databases & Data Management
  • Heroku Postgres
  • Postgres Performance
  • Correctly Establishing Postgres Connections in Forked Environments

Correctly Establishing Postgres Connections in Forked Environments

English — 日本語に切り替える

Table of Contents [expand]

  • Forked Environments
  • Database Connection Pools
  • Configure Ruby on Rails
  • Configure Unicorn
  • Configure Resque
  • Sidekiq

Last updated June 10, 2026

Postgres connections persist across requests to improve app performance and reduce the impact and costs of re-establishing a connection for every invocation. In forked environments, you must establish connections after the fork completes so that each process has its own connection.

Forked Environments

Frameworks and libraries that fork processes require you to establish Postgres connections after the fork completes. This process makes sure each forked process has its own connection, avoiding common connection errors such as no connection to the server, SSL SYSCALL error: EOF detected, and SSL error: decryption failed or bad record mac.

The sections in the rest of the article provide connection configuration best practices for common frameworks and libraries.

Database Connection Pools

When using a fork-based server, each fork receives its own database connection pool. For this reason, most apps using fork-based web servers perform best when you set the app-level connection pool (Rails, Sequel, Django) to size 1, or disable it entirely.

Using too many database connections can result in performance degradation and out-of-memory errors from the database servers. The database server also starts rejecting new connections when you reach your database’s connection limit.

Apps that require multiple simultaneous transactions within a single HTTP request are an exception to this guidance.

Configure Ruby on Rails

See Concurrency and Database Connections in Ruby with ActiveRecord for more details.

Configure Unicorn

Unicorn is a Rack HTTP server that uses forked processes to handle incoming requests. Configure the database connection behavior in the unicorn.conf configuration file.

See Concurrency and Database Connections in Ruby with ActiveRecord for configuration details.

Configure Resque

Resque uses forking to create new worker processes. Disconnect the main process connection before forking to avoid consuming unnecessary resources, and establish a worker connection after the fork occurs. See the Resque hooks documentation for more details.

Include the following configuration in the initializer configuration to clean up and re-establish the connections:

  Resque.before_fork do
    defined?(ActiveRecord::Base) and
      ActiveRecord::Base.connection.disconnect!
  end

  Resque.after_fork do
    defined?(ActiveRecord::Base) and
      ActiveRecord::Base.establish_connection
  end

Sidekiq

Sidekiq uses threads to handle many jobs at the same time in the same process. To prevent sharing of connections, you must configure the Sidekiq server to establish its own connection correctly.

You can specify this behavior by cleaning up and re-establishing connections in a Sidekiq initializer.

See Concurrency and Database Connections for Background Workers for details.

Feedback

Log in to submit feedback.

Information & Support

  • Getting Started
  • Documentation
  • Changelog
  • Compliance Center
  • Training & Education
  • Blog
  • Support Channels
  • Status

Language Reference

  • Node.js
  • Ruby
  • Java
  • PHP
  • Python
  • Go
  • Scala
  • Clojure
  • .NET

Other Resources

  • Careers
  • Elements
  • Products
  • Pricing
  • RSS
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku Blog
    • Heroku News Blog
    • Heroku Engineering Blog
  • Twitter
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku
    • Heroku Status
  • Github
  • LinkedIn
  • © 2026 Salesforce, Inc. All rights reserved. Various trademarks held by their respective owners. Salesforce Tower, 415 Mission Street, 3rd Floor, San Francisco, CA 94105, United States
  • heroku.com
  • Legal
  • Terms of Service
  • Privacy Information
  • Responsible Disclosure
  • Trust
  • Contact
  • Cookie Preferences
  • Your Privacy Choices