Logical decoding Output Plugins 분석 - kayform/bwcontrol GitHub Wiki

Logical decoding Output Plugins 분석

1.test decoding

1.1.Callback 역할

Callback function 역할 Calling time Caller process
_PG_output_plugin_init /2.callback 함수 등록 pg_create_logical_replication_slot backend process
pg_recvlogical에서 --create-slot -wal sender- backend 별도 세션수립
/2. pg_decode_startup Plugin을 초기화 replication slot이 생성 _PG_output_plugin_init
각종 옵션 설정
pg_decode_shutdown
pg_decode_begin_txn tx 시작을 로그에 Begin을기록 commit시점 begin시 call안됨 wal sender
pg_decode_commit_txn tx 시작을 로그에 commit을기록 commit시점 wal sender
pg_decode_change 변경된tuple을 format에 맞게 변환 commit시점 wal sender
pg_output_begin
pg_decode_filter

1.2.Call flow A. SQL에서 replication slot 생성 : pg_create_logical_replication_slot

  1. psql에 맵핑된 backend process에서 output plugin 초기화
  2. pg_recvlogical 실행(pg_decode_startup에 각종 옵션 전달)
  3. postgres내의 wal sender process 생성
  4. DML/DDL 실행
  5. backend process에서 intterupt 발생
  6. wal sender process에서 다음 순서로 call

WalSndLoop XLogSendLogical LogicalDecodingProcessRecord DecodeXactOp DecodeCommit pg_decode_begin_txn(plugin callback) pg_decode_change(plugin callback) pg_decode_commit_txn(plugin callback)

  1. 각각의 plugin callback에서 output stream에 로그기록("Logical Decoding Output Writers":https://www.postgresql.org/docs/9.5/static/logicaldecoding-writer.html
  2. Wal log to replication log(???)
  3. wal sender가 연결된 pg_recvlogical에 로그 전송("Synchronous Replication Support for Logical Decoding":https://www.postgresql.org/docs/9.5/static/logicaldecoding-synchronous.html) B. pg_recvlogical에서 replication slot 생성 : --create-slot option
  4. pg_recvlogical에서 -wal sender process로 직접 호출- 별도의 SQL세션 수립하여 backend process로 전달 이하 A 항과 동일

1.3.기타

2.wal2json

2.1.Callback 역할 : test_decoding 동일(function name만 다름) 2.2.Call flow : test_decoding 동일 2.3.기타

  1. json format 변환
  • 두가지 함수를 이용하여 json 변환 columns_to_stringinfo identity_to_stringinfo
  1. table schema 선택 전송
  • 두가지 flag를 이용하여 선택전송(plugin 내에서 구분) bool include_schemas; // qualify tables bool include_types; // include data types

3.bottlewater

3.1.Callback 역할 : test_decoding 동일(function name만 다름) 3.2.Call flow : test_decoding 동일 3.3.기타 avro 라이브러리를 이용하여 avro protocol format으로 로그저장