1. Importing Libraries

import subprocess
import time

2. wait_for_postgres Function

def wait_for_postgres(host, max_retries=5, delay_seconds=5):
    ...

This function's purpose is to repeatedly check if a PostgreSQL instance is ready to accept connections.

Inside the function:


3. Initializing the ELT Process

if not wait_for_postgres(host="source_postgres"):
    exit(1)

Before the main ELT process starts, the script ensures that the source PostgreSQL database is operational. If the database isn't ready after the specified number of retries, the script terminates with an error code (exit(1)).