Introduction
This Knowledge Base article provides guidance on resolving an issue where Terraform Enterprise (TFE) enters an error state and fails to start due to a read-only database transaction error. Despite a successful connection to the PostgreSQL database, TFE cannot perform necessary write operations, resulting in startup failures. This issue can occur in various database environments, including on-premise, or database on cloud.
Problem
TFE fails to register heartbeats or complete startup, displaying errors such as:
[ERROR] terraform-enterprise: error registering heartbeat: error="error registering node heartbeat: ERROR: cannot execute INSERT in a read-only transaction (SQLSTATE 25006)" node=245d75
and after a restart attempt:
[ERROR] terraform-enterprise: startup: error=\"error when creating migrations: ERROR: cannot execute TRUNCATE TABLE in a read-only transaction (SQLSTATE 25006) in line 0
Prerequisites
Cause
Solutions
Outcome