home
diamond Go Premium
Data Engineering Path  ·  PySpark

Scenario: External Database JDBC

Scenario: Migrating Data from PostgreSQL to Snowflake

The Challenge

A data engineering pipeline needs to pull millions of records from a legacy transactional PostgreSQL database, apply business transformations, and load the enriched dataset into a Snowflake cloud warehouse. The job requires third-party JDBC drivers and Snowflake connector classes that are not pre-packaged in the standard PySpark environment.


1. Optimal Spark-Submit Configuration

spark-submit \
    --master yarn \
    --deploy-mode cluster \
    --name "Postgres-To-Snowflake-Migration" \
    --num-executors 8 \
    --executor-cores 4 \
    --executor-memory 12g \
    --driver-memory 6g \
    --jars hdfs:///connectors/postgresql-42.5.1.jar,hdfs:///connectors/spark-snowflake_2.12-2.11.0-spark_3.3.jar,hdfs:///connectors/snowflake-jdbc-3.13.22.jar \
    --conf spark.sql.shuffle.partitions=100 \
    hdfs:///scripts/db_migration_job.py \
    --postgres_url "jdbc:postgresql://postgres-db.internal:5432/orders" \
    --snowflake_stage "my_snowflake_stage"

2. Parameter Explanations & Rationale

  • --jars ...: Essential for database connectors. We pass a comma-separated list of JDBC and third-party connector .jar files stored on HDFS. spark-submit automatically distributes these files to the Spark Driver and all Spark Executor JVMs, making the database connector classes available to the classloader at runtime.
  • Moderate Executor Sizes: Pulling data from transactional databases (PostgreSQL) is constrained by the database's database connection pool limits and CPU. Running too many concurrent executors or tasks will overwhelm PostgreSQL, resulting in connection timeouts. Sizing 8 executors with 4 cores (32 tasks total) provides a safe, parallel read rate.
  • spark.sql.shuffle.partitions=100: Set lower than the 200 default to match the moderate scale of database ingestion pipelines.
Find this content helpful? ☕ Buy me a coffee

Entity Details

Create New Item

celebration
Enjoying the free content?

Create a free account to track your progress and save your place.

Create Free Account
help

Submit Technical Query

Have a question or run into an issue? Describe it below, upload an optional screenshot, and our engineering team will answer it!

image Attach image (optional)

Submit Feedback

build Free Developer Utility Free Tool
gavel

Privacy & Legal Disclaimer

1. Client-Side Browser Processing

All utility tools on DeepEngineerHub (including Image to PDF, Text Formatters, JSON Converters, and Encryptors) execute 100% locally within your client browser using WebAssembly and JavaScript. No uploaded images, text, or documents are transmitted, collected, or stored on remote servers.

2. Limitation of Liability ("As-Is" Provision)

Tools and services are provided free of charge for convenience and educational purposes "as-is" without warranties of any kind. DeepEngineerHub shall not be held liable for any data loss, formatting inconsistencies, or indirect damages resulting from tool usage.

3. Open Source & Third-Party Software

Certain utilities utilize open-source client libraries (such as jsPDF, Mermaid.js, Pyodide) licensed under MIT, Apache, or BSD open licenses. All intellectual property remains with their respective copyright holders.