惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

L
LangChain Blog
AWS News Blog
AWS News Blog
Last Week in AI
Last Week in AI
宝玉的分享
宝玉的分享
The Cloudflare Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 三生石上(FineUI控件)
腾讯CDC
Apple Machine Learning Research
Apple Machine Learning Research
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
人人都是产品经理
人人都是产品经理
WordPress大学
WordPress大学
爱范儿
爱范儿
IT之家
IT之家
博客园 - 叶小钗
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
S
SegmentFault 最新的问题
L
Lohrmann on Cybersecurity
Scott Helme
Scott Helme
G
GRAHAM CLULEY
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
美团技术团队
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
V
Visual Studio Blog
博客园 - 聂微东
有赞技术团队
有赞技术团队
J
Java Code Geeks
小众软件
小众软件
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
V
V2EX
The Last Watchdog
The Last Watchdog
S
Securelist
博客园 - Franky
罗磊的独立博客
阮一峰的网络日志
阮一峰的网络日志
AI
AI
雷峰网
雷峰网
博客园 - 司徒正美
L
LINUX DO - 热门话题
月光博客
月光博客
大猫的无限游戏
大猫的无限游戏
Hugging Face - Blog
Hugging Face - Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
L
LINUX DO - 最新话题
TaoSecurity Blog
TaoSecurity Blog
Cisco Talos Blog
Cisco Talos Blog
K
Kaspersky official blog
H
Hacker News: Front Page
量子位
Latest news
Latest news

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
PostgreSQL 08007 오류 원인과 해결 방법 완벽 가이드
umzzil nng · 2026-05-31 · via DEV Community

umzzil nng

08007 transaction resolution unknown 는?

PostgreSQL 에러 코드 08007 transaction resolution unknown2단계 커밋(Two-Phase Commit, 2PC) 과정에서 트랜잭션의 최종 상태(커밋 또는 롤백 여부)를 결정할 수 없을 때 발생하는 에러입니다. 분산 트랜잭션 환경에서 PREPARE TRANSACTION 이후 네트워크 장애, 코디네이터 크래시, 또는 참여 노드 간의 통신 단절이 발생하면 해당 트랜잭션이 "미결(in-doubt)" 상태로 남게 됩니다. 이 상태에서 PostgreSQL은 트랜잭션을 커밋해야 할지 롤백해야 할지 독자적으로 판단할 수 없기 때문에, 외부 개입 없이는 자동으로 해결되지 않아 운영 환경에서 심각한 장애로 이어질 수 있습니다.


주요 발생 원인

1. 2단계 커밋 코디네이터(Coordinator) 장애

분산 트랜잭션에서 코디네이터 역할을 하는 미들웨어(예: Java의 JTA, Pgpool-II, 또는 커스텀 애플리케이션)가 PREPARE TRANSACTION을 실행한 이후 크래시되거나 네트워크 연결이 끊어지면, 참여 PostgreSQL 노드는 트랜잭션의 최종 결정을 통보받지 못합니다. 이 경우 pg_prepared_xacts 시스템 뷰에 해당 트랜잭션이 지속적으로 남아 있게 되고, 관련 잠금(lock)이 해제되지 않아 다른 트랜잭션이 블로킹되는 연쇄 장애가 발생할 수 있습니다.

2. 네트워크 파티션(Network Partition) 또는 타임아웃

분산 시스템에서 PREPARE TRANSACTION 이후 참여 노드들 간에 네트워크 파티션이 발생하거나, 코디네이터의 응답 타임아웃이 너무 짧게 설정된 경우 트랜잭션 결정 메시지가 전달되지 않을 수 있습니다. 특히 클라우드 환경이나 멀티 리전 구성에서는 일시적인 네트워크 지연만으로도 이 상황이 빈번하게 재현될 수 있으며, 운영자가 인지하지 못한 채 미결 트랜잭션이 누적되는 경우가 많습니다.

3. 애플리케이션의 잘못된 2PC 구현 또는 예외 처리 누락

PREPARE TRANSACTION을 명시적으로 사용하는 커스텀 애플리케이션에서 예외 처리 로직이 불완전할 경우, COMMIT PREPARED 또는 ROLLBACK PREPARED를 호출하지 않고 커넥션이 닫히는 상황이 발생합니다. JDBC, libpq 등을 직접 제어하는 코드에서 트랜잭션 ID 관리나 에러 핸들링이 제대로 구현되지 않으면, 데이터베이스 서버는 해당 트랜잭션의 의도를 알 수 없는 상태로 방치됩니다.


해결 방법

1단계: 현재 미결 트랜잭션 현황 파악

먼저 pg_prepared_xacts 뷰를 통해 현재 준비(prepared) 상태로 남아 있는 트랜잭션 목록을 확인합니다.

-- 미결 트랜잭션 전체 조회
SELECT 
    gid,
    prepared,
    owner,
    database,
    transaction,
    EXTRACT(EPOCH FROM (now() - prepared)) / 60 AS minutes_pending
FROM pg_prepared_xacts
ORDER BY prepared ASC;

오래된 미결 트랜잭션이 존재한다면(예: 수 분 이상 지속), 운영 환경에서 잠금 경합을 유발하고 있을 가능성이 높습니다.

2단계: 관련 잠금 현황 확인

미결 트랜잭션이 어떤 잠금을 보유하고 있는지 확인하여 영향 범위를 파악합니다.

-- 미결 트랜잭션의 잠금 정보 확인
SELECT 
    pxacts.gid,
    pxacts.prepared,
    pxacts.owner,
    locks.locktype,
    locks.relation::regclass AS locked_relation,
    locks.mode,
    locks.granted
FROM pg_prepared_xacts pxacts
JOIN pg_locks locks 
    ON locks.transactionid = pxacts.transaction
        OR locks.virtualtransaction = '-1/' || pxacts.transaction::text
ORDER BY pxacts.prepared;

3단계: 코디네이터와 협의하여 트랜잭션 결정

원칙적으로는 코디네이터 시스템(애플리케이션 서버 또는 미들웨어)의 트랜잭션 로그를 확인하여 해당 gid의 원래 의도가 커밋인지 롤백인지를 먼저 파악해야 합니다. 코디네이터 로그를 통해 의도를 확인한 뒤, 아래와 같이 처리합니다.

-- 코디네이터 로그 확인 후 커밋이 맞는 경우
COMMIT PREPARED 'your_transaction_gid_here';

-- 코디네이터 로그 확인 후 롤백이 맞는 경우
ROLLBACK PREPARED 'your_transaction_gid_here';

⚠️ 주의: COMMIT PREPARED 또는 ROLLBACK PREPARED는 슈퍼유저이거나 해당 트랜잭션의 소유자만 실행할 수 있습니다. 반드시 코디네이터의 의사결정 로그를 확인한 후 실행하세요.

4단계: 슈퍼유저로 강제 정리 (긴급 상황)

코디네이터 시스템이 복구 불가능하고 비즈니스적 판단에 의해 롤백이 안전한 경우, 슈퍼유저 권한으로 강제 롤백할 수 있습니다.

-- 슈퍼유저로 강제 롤백 (긴급 시에만 사용)
-- 먼저 gid 목록을 확인하고 하나씩 처리
DO $$
DECLARE
    r RECORD;
BEGIN
    FOR r IN 
        SELECT gid 
        FROM pg_prepared_xacts 
        WHERE prepared < now() - INTERVAL '30 minutes'
          AND database = current_database()
    LOOP
        RAISE NOTICE '롤백 처리 중: %', r.gid;
        EXECUTE 'ROLLBACK PREPARED ' || quote_literal(r.gid);
    END LOOP;
END;
$$;

5단계: 정리 후 상태 검증

-- 처리 후 미결 트랜잭션이 없는지 최종 확인
SELECT COUNT(*) AS remaining_prepared_transactions
FROM pg_prepared_xacts
WHERE database = current_database();

-- 잔여 잠금 확인
SELECT pid, usename, application_name, wait_event_type, wait_event, state, query
FROM pg_stat_activity
WHERE wait_event_type = 'Lock'
ORDER BY state_change;


예방 방법

1. 미결 트랜잭션 모니터링 자동화 및 알림 설정

pg_prepared_xacts를 주기적으로 모니터링하여 일정 시간(예: 5분) 이상 해결되지 않은 준비 트랜잭션이 존재할 경우 즉시 알림을 받을 수 있도록 설정합니다. Prometheus + postgres_exporter를 사용하는 환경이라면 아래와 같은 쿼리를 커스텀 메트릭으로 등록하거나, pg_cron을 이용한 자동 감사 로그를 구성할 수 있습니다.

-- pg_cron을 이용한 주기적 감사 로그 (예: 매 5분마다 실행)
-- pg_cron 확장이 설치된 환경에서 사용
SELECT cron.schedule(
    'check_prepared_xacts',
    '*/5 * * * *',
    $$
    INSERT INTO dba_audit.prepared_xact_log (gid, prepared, owner, database, logged_at)
    SELECT gid, prepared, owner, database, now()
    FROM pg_prepared_xacts
    WHERE prepared < now() - INTERVAL '5 minutes';
    $$
);

-- 모니터링용 뷰 생성
CREATE OR REPLACE VIEW dba_monitor.v_stale_prepared_xacts AS
SELECT 
    gid,
    prepared,
    owner,
    database,
    EXTRACT(EPOCH FROM (now() - prepared)) / 60 AS minutes_pending,
    CASE 
        WHEN prepared < now() - INTERVAL '30 minutes' THEN 'CRITICAL'
        WHEN prepared < now() - INTERVAL '10 minutes' THEN 'WARNING'
        ELSE 'INFO'
    END AS severity
FROM pg_prepared_xacts
ORDER BY prepared ASC;

2. max_prepared_transactions 파라미터 및 2PC 사용 정책 명문화

실제로 2단계 커밋을 사용하지 않는 서비스라면, postgresql.conf에서 max_prepared_transactions = 0으로 설정하여 PREPARE TRANSACTION 자체를 비활성화하는 것이 가장 안전한 예방책입니다. 2PC를 반드시 사용해야 하는 경우에는 코디네이터 장애 시 자동 복구 절차(예: 코디네이터 재시작 후 미결 트랜잭션 재처리 로직)를 문서화하고, 트랜잭션 GID 네이밍 규칙을 표준화하여 추적성을 확보해야 합니다.

-- 현재 max_prepared_transactions 설정 확인
SHOW max_prepared_transactions;

-- 2PC 미사용 환경에서는 0으로 설정 권장 (postgresql.conf 수정 후 재시작 필요)
-- max_prepared_transactions = 0

-- GID 네이밍 규칙 예시: {서비스명}_{코디네이터ID}_{타임스탬프}
-- 'payment-svc_coord01_20240115T143022Z'
-- 이렇게 하면 어떤 서비스의 어떤 코디네이터가 생성한 트랜잭션인지 즉시 파악 가능


관련 에러

  • 08000 connection_exception: 일반적인 커넥션 수준의 예외로, 네트워크 단절로 인해 08007로 이어지는 선행 에러로 나타날 수 있습니다.
  • 08003 connection_does_not_exist: 트랜잭션 진행 중 커넥션이 소멸된 경우 발생하며, 2PC 코디네이터 측에서 이 에러를 수신한 후 미결 트랜잭션이 08007 상황을 만들 수 있습니다.
  • 40001 serialization_failure / 40P01 deadlock_detected: 미결 트랜잭션이 잠금을 보유한 채 해소되지 않을 경우, 다른 트랜잭션에서 교착 상태나 직렬화 실패로 이어지는 연쇄 에러를 유발합니다.
  • 57P01 admin_shutdown / 57P02 crash_shutdown: 코디네이터 노드의 비정상 종료 시 발생하며, 이후 재시작 과정에서 08007 상태의 미결 트랜잭션 처리가 필요해지는 트리거 역할을 합니다.