DBAtlas · 데이터베이스 운영 아틀라스

logical replication 충돌 해결(disable_on_error, SKIP)

PostgreSQL논리 복제

명령어

-- 1) Prevent a failing apply worker from looping forever:
ALTER SUBSCRIPTION sub_app SET (disable_on_error = true);
-- 2) Find the finish LSN of the conflicting transaction in the subscriber log:
--    CONTEXT: ... in transaction 749, finished at 0/5035378
-- 3a) Preferred: fix/delete the conflicting row on the subscriber, then re-enable:
ALTER SUBSCRIPTION sub_app ENABLE;
-- 3b) Or skip the whole remote transaction (NONE of its changes are applied on the subscriber):
ALTER SUBSCRIPTION sub_app SKIP (lsn = '0/5035378');
ALTER SUBSCRIPTION sub_app ENABLE;
SELECT subname, subenabled, subskiplsn FROM pg_subscription;

하는 일

중복 키, 행 누락, 권한 문제 같은 오류로 subscriber의 apply가 멈추면 disable_on_error가 subscription을 자동으로 비활성화한다. 충돌 데이터를 수정한 후 ENABLE하거나, 로그의 'finished at' LSN으로 식별되는 원격 트랜잭션 전체를 SKIP한다.

사용 시점

subscriber에 대한 직접 쓰기, 불완전한 초기 복사, 양방향 쓰기 때문에 apply worker가 실패하고 계속 재시작할 때.

주의

SKIP은 해당 트랜잭션의 충돌하지 않는 변경도 버리므로 양쪽이 영구적으로 달라진다. 데이터 수정을 우선하고, SKIP 후에는 테이블을 비교한다. 충돌이 해결될 때까지 publisher의 slot은 WAL을 계속 쌓는다. 권한으로 subscriber 테이블에 대한 애플리케이션 쓰기를 막는다.

DBAtlas에서 열기 →

관련 항목