iyashk-DB
Databricks Employee
Databricks Employee

2) Run many tables with a generic script (parameterized)

We suggest that you define a list that maps each Databricks source to its corresponding Oracle target and per-table options (partitions, mode, and pre/post SQL). Then loop over it in one notebook or job.

Something like as follows for an example (Python, single script):

# 1) Table manifest (could also come from a Delta table)
manifest = [
  {
    "source_table": "catalog.schema.table1",
    "target_table": "SCHEMA.TABLE1",
    "partitions": 16,
    "mode": "append"
  },
  {
    "source_table": "catalog.schema.table2",
    "target_table": "SCHEMA.TABLE2",
    "partitions": 8,
    "mode": "overwrite"  # or "append"
  },
  # ...
]

# 2) Secrets-backed credentials (see section 3)
oracle_user = dbutils.secrets.get("oracle-prod", "username")
oracle_pwd  = dbutils.secrets.get("oracle-prod", "password")

jdbc_url = "jdbc:oracle:thin:@//<host>:<port>/<service_name>"
common_props = {
  "user": oracle_user,
  "password": oracle_pwd,
  "driver": "oracle.jdbc.OracleDriver",
  # Optional write tuning:
  # "batchsize": "1000",
}

def write_one(spec):
  df = spark.read.table(spec["source_table"])
  n = int(spec.get("partitions", 8))
  mode = spec.get("mode", "append")
  (df.repartition(n)               # control parallelism responsibly
     .write
     .format("jdbc")
     .option("url", jdbc_url)
     .option("dbtable", spec["target_table"])
     .options(**common_props)
     .mode(mode)
     .save())

for spec in manifest:
  write_one(spec)
Why this works at scale:
  • You control write parallelism per table using repartition(N); keep N moderate (e.g., 8–32) to avoid overloading Oracle.

  • One notebook can process all tables; use Databricks Jobs to pass parameters (e.g., a manifest path or table filter) and to run subsets in parallel with controlled concurrency.

3) Hide credentials (service account / non‑human account)

Use Databricks Secrets so credentials never appear in code, logs, or UI:

# Store once in a secret scope (e.g., backed by a cloud key vault)
oracle_user = dbutils.secrets.get(scope="oracle-prod", key="username")
oracle_pwd  = dbutils.secrets.get(scope="oracle-prod", key="password")

props = {
  "user": oracle_user,
  "password": oracle_pwd,
  "driver": "oracle.jdbc.OracleDriver"
}

Databricks explicitly recommends storing JDBC usernames/passwords in secrets rather than embedding them in URLs or notebooks; retrieve them at runtime with dbutils.secrets.get(...). This works for both human users and service accounts created in Oracle for production use.