Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Commit

Permalink
Stop all background workers for the duration of the upgrade
Browse files Browse the repository at this point in the history
This commit stops bgws while upgrading the Promscale extension.
This prevents lock contention between jobs and upgrades and thus
seems safer.
  • Loading branch information
cevian committed May 23, 2022
1 parent e21d231 commit 0bebfdf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,13 @@ fn render_bootstrap(manifest_dir: &str) -> String {
ext_schema_path.push("migration/bootstrap/001-create-ext-schema.sql");
let ext_schema_sql = wrap(ext_schema_path.as_path(), &Incremental);

let stop_bgw_sql =
include_str!("migration/bootstrap/002-stop-bgw.sql").to_string();

let mut result = String::from("");
result.push_str(&migration_table_sql);
result.push_str(&ext_schema_sql);
result.push_str(&stop_bgw_sql);
result
}

Expand Down
12 changes: 12 additions & 0 deletions migration/bootstrap/002-stop-bgw.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- stop all background workers in the current db so they don't interfere
-- with the upgrade (by e.g. holding locks).
--
-- Note: this stops the scheduler (and thus all jobs)
-- and waits for the current txn (the one doing the upgrade) to finish
-- before starting it up again. Thus, no jobs will be running during
-- the upgrade.

-- TimescaleDB itself does the same thing:
-- https://github.com/timescale/timescaledb/blob/72d03e6f7d30cc4794c9263445f14199241e2eb5/sql/updates/pre-update.sql#L34
SELECT _timescaledb_internal.restart_background_workers();

0 comments on commit 0bebfdf

Please sign in to comment.