How to Connect Airflow to oracle database

后端 未结 5 1262
情歌与酒
情歌与酒 2020-12-29 13:46

I am trying to create a connection to an oracle db instance (oracle:thin) using Airflow.

According to their documentation I entered my hostname followed by port numb

相关标签:
5条回答
  • 2020-12-29 13:55

    After digging into the source code, this is what finally how it worked for me:

    Conn Type: Oracle

    Host: example.com

    schema: username

    login: username

    port: port number

    extra: {"sid": "my sid", "dsn": "example.com"}

    0 讨论(0)
  • 2020-12-29 13:57

    this worked for me in extra field

    { "dsn":"192.168.x.x" , "service_name":"some.service.name" }
    

    I get from https://github.com/apache/airflow/blob/master/airflow/hooks/oracle_hook.py#L49

    0 讨论(0)
  • 2020-12-29 13:57

    If anyone just does not see the connection in the Ad hoc query dropdown - you need to install the adapter: pip install cx_Oracle on the airflow server.

    0 讨论(0)
  • 2020-12-29 14:05

    for service name usage, if you leave (port, schema and extra) empty, you can put the full oracle connection descriptor under Host:

    (DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = mysidname)))

    0 讨论(0)
  • 2020-12-29 14:07

    You have a problem in your connection settings, either your setting is not loading properly to the oracle hook or you are missing a python package that save/load your connection settings. You can test it by hard coding your credentials.

    https://github.com/airbnb/airflow/blob/master/airflow/hooks/oracle_hook.py

    conn = self.get_connection(self.oracle_conn_id)
    dsn = conn.extra_dejson.get('dsn', None)
    sid = conn.extra_dejson.get('sid', None)
    service_name = conn.extra_dejson.get('service_name', None)
    if dsn and sid and not service_name:
        dsn = cx_Oracle.makedsn(dsn, conn.port, sid)
        conn = cx_Oracle.connect(conn.login, conn.password, dsn=dsn)
    elif dsn and service_name and not sid:
        dsn = cx_Oracle.makedsn(dsn, conn.port, service_name=service_name)
        conn = cx_Oracle.connect(conn.login, conn.password, dsn=dsn)
    else:
        conn = cx_Oracle.connect(conn.login, conn.password, conn.host)
    
    0 讨论(0)
提交回复
热议问题