Transaction
autocommit
세션을 시작할 때 설정한다.
conn = psycopg2.connect(
dbname="your_dbname",
user="your_username",
password="your_password",
host="your_host",
port="your_port"
)
conn.autocommit = True
autocommit=True
- 모든 SQL statement가 바로 물리 테이블에 커밋된다.
- 이를 바꾸고 싶다면 BEGIN;END; 혹은 BEGIN;COMMIT;(ROLLBACK)을 사용
autocommit=False
- SQL statement가 커밋되지 않는다.
- 커넥션 객체의 .commit()과 .rollback() 함수로 커밋할지 말지 결정한다.
Airflow
DAG
dag = DAG(
"dag_v1",
start_date=datetime(2020,8,7,hour=0,minute=00),
schedule="0 * * * *",
tags=["example"],
catchup=False,
default_args=default_args
)
- start_date
- catchup
- start_date부터 현재까지 시간중에 실행되지 않은 Dag들을 실행해준다.
- can be used to do one-off backfilling
- Full Refresh의 경우 catchup을 False로 해줘야 한다.
- schedule
- None, @once, @hourly, @daily, @weekly, @monthly, @yearly
- None이나 @once로 다른 dag가 끝났을 때 실행하도록 할 수 있다.
-

CLI 명령어
- airflow dags list
- airflow tasks DAG이름
- airflow tasks test DAG이름 Task이름 날짜
- 날짜는 YYYY-MM-DD
- start_date보다 과거인 경우는 실행이 되지만 오늘 날짜보다 미래인 경우에는 실행이 안된다.
- execution_date의 값이 된다.
- test대신 run을 쓸 수 있다.
- test: 메타데이터 디비에 안남는다.
- run: 메타데이터 디비에 남는다.