locking

Provides insight into how to safely manage locks and coordinate resource access in multithreaded programs.

Updated Jun 1, 2026
One-click install
npx skills add https://github.com/matejformanek/postgres-claude --skill locking
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: locking
Source: https://github.com/matejformanek/postgres-claude/tree/main/.claude/skills/locking
Command: npx skills add https://github.com/matejformanek/postgres-claude --skill locking

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This skill prevents silent deadlocks, race conditions, and performance bottlenecks by providing an authoritative, cited operational framework for managing PostgreSQL shared memory and lock primitives.

Core Features & Use Cases

  • Lock Taxonomy Guidance: Navigate the six-layer PG lock hierarchy from atomics and spinlocks to heavyweight and predicate locks.
  • Deadlock Prevention: Apply canonical acquisition order rules for partitioned LWLocks to avoid silent system hangs.
  • Use Case: When implementing a new background worker or modifying shared memory structures, use this skill to verify your lock acquisition order and ensure your code adheres to the strict safety rules required for backend stability.

Quick Start

Use the locking skill to review the proposed lock acquisition order for the new shared memory struct in the current patch.

Frequently Asked Questions about locking

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent deadlocks when acquiring PostgreSQL LWLocks in shared memory?

Prevent PostgreSQL deadlocks by applying canonical lock acquisition order rules for partitioned LWLocks. Adhering strictly to documented lock-ordering rules ensures system stability and avoids silent system hangs during concurrent shared memory access.

What is the correct lock hierarchy for managing PostgreSQL concurrency primitives?

The PostgreSQL lock hierarchy consists of six layers, ranging from atomics and spinlocks to lightweight locks (LWLocks), heavyweight locks, and predicate locks. Navigating this taxonomy correctly is essential for safe backend development and patch review.

When do I need memory barriers for PostgreSQL backend development?

Memory barriers are required when implementing background workers or modifying shared memory structures in PostgreSQL. Strict adherence to memory barrier requirements ensures correct synchronization and prevents race conditions during concurrent access.

How do I diagnose race conditions in PostgreSQL shared memory structures?

Diagnose PostgreSQL race conditions by reviewing your code against the operational framework for lock primitives. Verify your lock acquisition order and ensure adherence to safety rules to identify and prevent silent concurrency bottlenecks.

Can I use standard lock ordering rules for new PostgreSQL background workers?

Yes, when implementing a new background worker, use canonical acquisition order rules for partitioned LWLocks to verify your lock acquisition sequence. This ensures your code adheres to strict safety rules required for backend stability.

Why does my PostgreSQL backend hang silently during concurrent shared memory access?

Silent PostgreSQL backend hangs often result from incorrect lock acquisition order causing deadlocks. Applying canonical acquisition order rules for partitioned LWLocks prevents these silent system hangs and resolves performance bottlenecks.