Showing posts with label Oracle. Show all posts
Showing posts with label Oracle. Show all posts

Monday, June 30, 2025

Sync data from Informix to Oracle using Debezium/Kafka Connect/Kafka/JDBC Sink

 Following commands and details will be helpful when configuring Debezium to sync data from Informix to Oracle database.

1. Docker compose to create Kafka connect, Kafka, Zookeeper

Copy Informix connector and streaming jar files into connectors directory in docker compose file exists

services:
  zookeeper:
    image: confluentinc/cp-zookeeper:7.5.0
    environment:
      ZOOKEEPER_CLIENT_PORT: 2181
    ports:
      - "2181:2181"
  kafka:
    image: confluentinc/cp-kafka:7.5.0
    ports:
      - "9092:9092"
    environment:
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092
      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
  connect:
    image: my-debezium-connect  # Custom image you’ll build below
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "8083:8083"
    environment:
      BOOTSTRAP_SERVERS: kafka:9092
      GROUP_ID: connect-cluster
      CONFIG_STORAGE_TOPIC: connect-configs
      OFFSET_STORAGE_TOPIC: connect-offsets
      STATUS_STORAGE_TOPIC: connect-status
      KEY_CONVERTER: org.apache.kafka.connect.json.JsonConverter
      VALUE_CONVERTER: org.apache.kafka.connect.json.JsonConverter
      CONFIG_STORAGE_REPLICATION_FACTOR: 1
      OFFSET_STORAGE_REPLICATION_FACTOR: 1
      STATUS_STORAGE_REPLICATION_FACTOR: 1
      VALUE_CONVERTER_SCHEMAS_ENABLE: "false"
      KEY_CONVERTER_SCHEMAS_ENABLE: "false"
    volumes:
      - ./connectors:/kafka/connectors

2. Build docker compose

sudo docker compose build --no-cache

3. Stop docker compose docker containers

sudo docker compose down

4. Start the docker compose containers

sudo docker compose up -d

5. Check the docker connect container logs

sudo docker compose logs -f connect

6. Informix Kafka connect json

{
  "name": "informix-source-connector",
  "config": {
    "connector.class": "io.debezium.connector.informix.InformixConnector",
    "tasks.max": "1",
    "database.hostname": "172.27.xx.xx",
    "database.port": "1528",
    "database.user": "xxxx",
    "database.password": "xxxx@23",
    "database.dbname": "xxxx",
    "database.server.name": "informix",
    "database.informixserver":"debezium_test",
    "topic.prefix": "informixcdc",
    "table.include.list": "table1",
    "snapshot.mode": "schema_only",
    "name": "informix-source-connector",
    "schema.history.internal.kafka.bootstrap.servers": "kafka:9092",
    "schema.history.internal.kafka.topic": "schema-changes.informix"
  }
}

7. Deploy Informix source connector to Kafka connect

curl -X POST http://localhost:8083/connectors -H "Content-Type: application/json" -d @informix-source.json|jq

8. Check the status of the connector

sudo curl http://localhost:8083/connectors/informix-source-connector/status | jq

9. Check the Kafka connect deployed connectors

curl -s http://localhost:8083/connector-plugins | jq

10. Delete Informix source connector

sudo curl -X DELETE http://localhost:8083/connectors/informix-source-connector

11. Login to Kafka connect container 

sudo docker exec -it cdc1-connect-1 sh

12. Oracle JDBC sink connector

{
  "name": "oracle-sink-connector",
  "config": {
    "connector.class": "io.debezium.connector.jdbc.JdbcSinkConnector",
    "tasks.max": "1",
    "topics": "informixcdc.informix.table1",

    "connection.url": "jdbc:oracle:thin:@//172.27.xx.xxx:1521/PDB_TST",
    "connection.username": "TEST",
    "connection.password": "test123",
    "connection.driver": "oracle.jdbc.OracleDriver",

    "insert.mode": "upsert",
    "delete.mode": "none",

    "primary.key.fields": "mobile_no",
    "primary.key.mode": "record_value",
    "table.name.format": "table1",

    "auto.evolve": "false",
    "auto.create": "false",
    "dialect.name": "OracleDatabase",

    "schema.evolution":"basic"

  }
}

13. Deploy Oracle sink connector

curl -X POST -H "Content-Type: application/json" --data @oracle-sink.json http://localhost:8083/connectors

14. Check Oracle sink connector status

curl http://localhost:8083/connectors/oracle-sink-connector/status|jq

15. Restart Oracle sink connector

curl -X POST http://localhost:8083/connectors/oracle-sink-connector/tasks/0/restart

16. Check configuration of Oracle connector

curl http://localhost:8083/connectors/oracle-sink-connector/config | jq

17. Login to Kafka and check first 5 messages in the Topic

docker exec -it cdc1-kafka_1 sh -c "kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic informixcdc.informix.table1 --from-beginning"

/bin/kafka-console-consumer   --bootstrap-server kafka:9092   --topic informixcdc.informix.smgt004   --from-beginning   --max-messages 5

18. Retrieve details of the Topic

/bin/kafka-topics --bootstrap-server kafka:9092 --describe --topic informixcdc.informix.smgt004




Monday, March 8, 2021

Retrieve few minutes older records from SQL in Oracle

You can use following SQL syntax to retrieve data in 5 minute interval in Oracle database. 

select * FROM test_table where added_time <= systimestamp - numtodsinterval(5,'MINUTE')

Above SQL returns values which are older than 5 minutes  than system time in added_time column.


Tuesday, January 19, 2021

Insert Timestamp to Oracle Timestamp in JAVA

 You can use following formatting to insert JAVA timestamp to Oracle Timestamp.

insert into test_table(added_time) values(TO_TIMESTAMP('2021-01-18 17:43:42.000000000', 'YYYY-MM-DD HH24:MI:SS.FF'))


Oracle Timestamp Issue

When querying Oracle Timestamp to JAVA Timestamp following error can be occurred. 

java.lang.ClassCastException: oracle.sql.TIMESTAMP cannot be cast to java.sql.Timestamp

This error can resolve using following two options.

1. Add JVM startup parameters. -Doracle.jdbc.J2EE13Compliant=true in the application

2. Add system properties in the application. System.getProperties().setProperty("oracle.jdbc.J2EE13Compliant", "true")

Reference site

https://docs.oracle.com/cd/B28359_01/java.111/b31224/datacc.htm


Tuesday, August 21, 2012

Oracle Toad database configuration

# tnsnames.ora Network Configuration File: C:\Oracle\product\11.2.0\client_1\network\admin\tnsnames.ora
# Generated by Oracle configuration tools.

CONFIGNAME=
  (DESCRIPTION=
    (ADDRESS_LIST=
      (ADDRESS=
        (PROTOCOL=TCP)
        (HOST=192.162.129.141)
        (PORT=1521)
      )
      (ADDRESS=
        (PROTOCOL=TCP)
        (HOST=192.165.119.161)
        (PORT=1521)
      )
    )
    (CONNECT_DATA=
      (SERVICE_NAME=ServiceName)
    )
  )

In Oracle Toad, it needs to configure Toad to connect to Oracle database. Store "tnsnames.ora" file at "C:\Oracle\product\11.2.0\client_1\network\admin\" directory. Then connect via Oracle Toad.

Friday, June 1, 2012

Oracle data format

When inserting data into Oracle Database it is needed to format data. Here, it is shown, how is TIMESTAMP is used in Oracle.

id_ref_no_seq.nextval call the sequence created before. It will increase ref_no value by one and insert back into database.

insert into TABLE_NAME(ref_no,start_time) values(id_ref_no_seq.nextval,TO_TIMESTAMP('2012-06-01 11:41:20.061', 'YYYY-MM-DD HH.MI.SSXFF'))