本節提供使用 Debezium PostgreSQL 來源連接器時,常見問題的疑難排解指引,包括下列連接器類型:
快照失敗
如果使用者沒有資料表結構定義的 USAGE 權限,連接器就無法建立初始快照,並會發生下列錯誤:
Snapshotting of table SCHEMA.TABLE failed
如要解決這個問題,請使用 GRANT SQL 指令,在結構定義上授予 USAGE 權限:
GRANT USAGE ON SCHEMA SCHEMA_NAME TO ROLE_NAME;
無法建立複製時段
如果為同一個 PostgreSQL 資料庫伺服器建立多個連接器,這些連接器必須使用不同的複製運算單元。否則會發生下列錯誤:
io.debezium.DebeziumException: Creation of replication slot failed; when setting up multiple connectors
for the same database host, please make sure to use a distinct replication slot name for each.
at io.debezium.connector.postgresql.PostgresConnectorTask.tryToCreateSlot(PostgresConnectorTask.java:282)
您也可能會看到類似下列內容的錯誤:
io.debezium.DebeziumException: Failed to start replication stream at LSN{0/80002808}; when setting
up multiple connectors for the same database host, please make sure to use a distinct replication
slot name for each.
如要解決這個問題,請將 slot.name 設為不重複的值。詳情請參閱 Debezium 說明文件中的「Setting up multiple connectors for same database server」。
建立或更新出版品時發生錯誤
Debezium PostgreSQL 連接器會從資料庫的發布項目讀取變更事件。如果連接器無法存取或建立發布內容,連接器記錄檔中可能會顯示下列章節列出的錯誤。
出版品不存在
如果 publication.autocreate.mode=disabled 和出版品不存在,就會發生下列錯誤:
org.apache.kafka.connect.errors.ConnectException: Publication PUBLICATION autocreation is disabled, please
create one and restart the connector.
at io.debezium.connector.postgresql.connection.PostgresReplicationConnection.initPublication(PostgresReplicationConnection.java:163)
如要解決這項錯誤,請手動建立發布項目,或將 publication.autocreate.mode 設為 all_tables 或 filtered。
無法更新已篩選的出版品
如果 publication.autocreate.mode=filtered 無法更新現有發布內容,就會發生下列錯誤:
org.apache.kafka.connect.errors.ConnectException: Unable to update filtered publication PUBLICATION for
"SCHEMA"."TABLE"
at io.debezium.connector.postgresql.connection.PostgresReplicationConnection.createOrUpdatePublicationModeFilterted(PostgresReplicationConnection.java:227)
at io.debezium.connector.postgresql.connection.PostgresReplicationConnection.initPublication(PostgresReplicationConnection.java:191)
如要解決這個問題,請確認資料庫使用者是發布內容的擁有者。
無法建立經過篩選的出版品
如果 publication.autocreate.mode=filtered 和連接器無法建立新的發布項目,就會發生下列錯誤:
org.apache.kafka.connect.errors.ConnectException: Unable to create filtered publication PUBLICATION for
"SCHEMA"."TABLE"
at io.debezium.connector.postgresql.connection.PostgresReplicationConnection.createOrUpdatePublicationModeFilterted(PostgresReplicationConnection.java:227)
at io.debezium.connector.postgresql.connection.PostgresReplicationConnection.initPublication(PostgresReplicationConnection.java:171)
如要解決這個問題,請確認資料庫使用者對資料庫具有 CREATE 權限,且是內含資料表的擁有者。
所有資料表的發布作業已啟用
如果 publication.autocreate.mode=filtered 和出版品已使用 FOR ALL TABLES 建立,就會發生下列錯誤:
io.debezium.DebeziumException: A logical publication for all tables named 'PUBLICATION' for plugin
'PGOUTPUT' and database 'DATABASE' is already active on the server and can not be altered. If you need to
exclude some tables or include only specific subset, please recreate the publication with necessary
configuration or let plugin recreate it by dropping existing publication. Otherwise please change the
'publication.autocreate.mode' property to 'all_tables'.
at io.debezium.connector.postgresql.connection.PostgresReplicationConnection.initPublication(PostgresReplicationConnection.java:181)
發生這項錯誤的原因是,連接器會嘗試變更所有資料表的發布項目中的資料表。如要解決這個問題,請捨棄現有發布項目,然後重新啟動連接器。或者,將「publication.autocreate.mode」更新為 all_tables。
必須是超級使用者,才能建立 FOR ALL TABLES 發布項目
如果 publication.autocreate.mode=all_tables 和連接器嘗試建立新的發布項目,可能會發生下列錯誤:
io.debezium.jdbc.JdbcConnectionException: ERROR: must be superuser to create FOR ALL TABLES publication
at io.debezium.connector.postgresql.connection.PostgresReplicationConnection.initPublication(PostgresReplicationConnection.java:207)
如果資料庫使用者不是超級使用者 (或在 Cloud SQL 中沒有 cloudsqlsuperuser 角色),就無法使用 FOR ALL TABLES 建立發布項目,因此會發生這個錯誤。如要解決這項錯誤,請執行下列任一操作:
- 手動建立發布項目。
- 將
publication.autocreate.mode更新為不同的值。 - 授予資料庫使用者
SUPERUSER(或 Cloud SQL 中的cloudsqlsuperuser)。 不過,一般不建議使用這個選項,因為這些角色會略過資料庫中的權限檢查。