9951 explained code solutions for 126 technologies


postgresqlHow do I set up a PostgreSQL Kafka Connector?


  1. Install the Confluent Platform to your machine.

  2. Create a Kafka Connector configuration file. The following example uses a file named postgres-sink.properties:

name=postgres-sink
connector.class=io.confluent.connect.jdbc.JdbcSinkConnector
tasks.max=1
connection.url=jdbc:postgresql://<hostname>:<port>/<database>
connection.user=<username>
connection.password=<password>
topics=<topic1>,<topic2>
auto.create=true
insert.mode=upsert
  1. Run the Kafka Connector with the configuration file:
$ confluent load postgres-sink -d postgres-sink.properties
  1. Verify that the connector is running:
$ confluent status connectors

Output example

postgres-sink               RUNNING
  1. Create a PostgreSQL table for the topics you specified:
CREATE TABLE <topic1> (
  id SERIAL,
  key VARCHAR(255),
  value VARCHAR(255)
);
  1. Publish messages to the topics you specified in the configuration file.

  2. Verify that the messages have been successfully sent to your PostgreSQL database.

Helpful links

Edit this code on GitHub