본문으로 건너뛰기

4.1 Linux I/O 경로

PostgreSQL의 read와 write는 syscall 하나로 끝나지 않습니다. Buffer manager, filesystem page cache, block layer, virtual device, physical storage를 지나며 각 계층에서 queue가 생길 수 있습니다.

Buffered write는 syscall이 빨리 끝나도 dirty page가 뒤늦게 device로 내려갑니다. fsync는 필요한 data가 durable해질 때까지 기다리므로 commit latency는 storage flush 동작에 민감합니다.

장치 mapping

lsblk -o NAME,TYPE,SIZE,FSTYPE,MOUNTPOINTS
findmnt -T "$PGDATA"
ls -l /sys/class/block

Cloud volume, LVM, dm-crypt, RAID가 겹치면 iostat에 여러 device가 보입니다. PostgreSQL data directory가 실제로 어느 장치와 mount option을 사용하는지 먼저 매핑합니다.

관측할 단계

  • Application: query와 commit latency
  • PostgreSQL: read/write time, checkpoint, WAL sync
  • Kernel: block request latency와 queue
  • Device: throughput, IOPS, error
  • Platform: volume credit, throttling, network storage 상태

한 계층의 metric만으로 원인을 확정하지 않습니다. 예를 들어 device utilization 100%는 병렬 처리 가능한 NVMe와 단일 spindle에서 의미가 다릅니다.