vaefremov95 commented on issue #77606: URL: https://github.com/apache/airflow/issues/77606#issuecomment-7185206737
@adiranjan25 Hi, and thanks for the reply! I'm glad the topic is of interest. As I said, this is just one variant of implementation, the one we use at our company, so it should not be treated as the final design. I can explain why TRUNCATE and COPY are in separate transactions there, because it was a deliberate choice. TRUNCATE takes an ACCESS EXCLUSIVE lock that is held until the end of the transaction. If TRUNCATE and a long COPY run in the same transaction, everyone who queries the destination table is blocked for the whole load, which can take a long time. In `pg_stat_activity` this looks confusing: the users' SELECTs wait on a lock, and the COPY that holds it looks like an ordinary running query. So we keep the TRUNCATE short and in its own transaction. That is also why we load only into a staging table. If a COPY fails, an empty staging table is harmless. The second step then moves the data into the main table in a single transaction (e.g. `INSERT ... SELECT` or a delete + insert), so readers of the main table never see an empty or half-loaded state. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
