Add vacuum helper — please read the docstring before using
This commit is contained in:
parent
d657c8375a
commit
4c29bcc54c
1 changed files with 8 additions and 0 deletions
|
|
@ -6,3 +6,11 @@ def write_to_redshift(df: pd.DataFrame, table: str, conn_str: str, if_exists: st
|
||||||
engine = create_engine(conn_str)
|
engine = create_engine(conn_str)
|
||||||
rows = df.to_sql(table, engine, if_exists=if_exists, index=False, method="multi", chunksize=1000)
|
rows = df.to_sql(table, engine, if_exists=if_exists, index=False, method="multi", chunksize=1000)
|
||||||
return rows or 0
|
return rows or 0
|
||||||
|
|
||||||
|
|
||||||
|
def vacuum_table(table: str, conn_str: str) -> None:
|
||||||
|
"""Run VACUUM on a table. Do not run during business hours.
|
||||||
|
I learned this the hard way. - c.bauer"""
|
||||||
|
engine = create_engine(conn_str)
|
||||||
|
with engine.connect() as conn:
|
||||||
|
conn.execute(text(f"VACUUM FULL {table}"))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue