-
Notifications
You must be signed in to change notification settings - Fork 0
add option to retry on lock_not_available #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rapimo
wants to merge
2
commits into
master
Choose a base branch
from
retry
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| -- complain if script is sourced in psql, rather than via CREATE EXTENSION | ||
| \echo Use "ALTER EXTENSION mvtbl UPDATE TO '0.0.3'" to load this file. \quit | ||
|
|
||
| CREATE FUNCTION mvtbl(tbl text, tblspace text, retries int, sleep_sec int DEFAULT 10) | ||
| RETURNS bigint AS | ||
| $$ | ||
| DECLARE | ||
| res bigint; | ||
| BEGIN | ||
| FOR i in 1..retries LOOP | ||
| BEGIN | ||
| res = mvtbl(tbl, tblspace); | ||
| EXIT; | ||
| EXCEPTION WHEN lock_not_available THEN | ||
| IF i = retries THEN | ||
| RAISE; | ||
| END IF; | ||
| PERFORM pg_sleep(sleep_sec); | ||
| END; | ||
| END LOOP; | ||
| RETURN res; | ||
| END; | ||
| $$ LANGUAGE plpgsql STRICT; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| -- complain if script is sourced in psql, rather than via CREATE EXTENSION | ||
| \echo Use "ALTER EXTENSION mvtbl UPDATE TO '0.0.2'" to load this file. \quit | ||
|
|
||
| DROP FUNCTION mvtbl(tbl text, tblspace text, retries int, sleep_sec int) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| -- complain if script is sourced in psql, rather than via CREATE EXTENSION | ||
| \echo Use "CREATE EXTENSION mvtbl" to load this file. \quit | ||
|
|
||
| CREATE FUNCTION mvtbl(tbl text, tblspace text) | ||
| RETURNS bigint AS | ||
| $$ | ||
| DECLARE | ||
| r RECORD; | ||
| tbl_oid oid := tbl::regclass::oid; | ||
| res bigint = 0; | ||
| BEGIN | ||
| EXECUTE format($sql$ ALTER TABLE %s SET TABLESPACE %s $sql$, tbl, tblspace); | ||
| SELECT pg_catalog.pg_total_relation_size(tbl) INTO res; | ||
|
|
||
| FOR r IN SELECT | ||
| c2.oid::regclass as iname | ||
| FROM pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index i | ||
| WHERE c.oid = tbl_oid AND c.oid = i.indrelid AND i.indexrelid = c2.oid | ||
| ORDER BY i.indisprimary DESC, i.indisunique DESC, c2.relname LOOP | ||
|
|
||
| EXECUTE format($sql$ ALTER INDEX %s SET TABLESPACE %s $sql$, r.iname, tblspace); | ||
| END LOOP; | ||
| RETURN res; | ||
| END; | ||
| $$ LANGUAGE plpgsql STRICT; | ||
|
|
||
| CREATE FUNCTION mvtbl(tbl text, tblspace text, retries int, sleep_sec int DEFAULT 10) | ||
| RETURNS bigint AS | ||
| $$ | ||
| DECLARE | ||
| res bigint; | ||
| BEGIN | ||
| FOR i in 1..retries LOOP | ||
| BEGIN | ||
| res = mvtbl(tbl, tblspace); | ||
| EXIT; | ||
| EXCEPTION WHEN lock_not_available THEN | ||
| IF i = retries THEN | ||
| RAISE; | ||
| END IF; | ||
| PERFORM pg_sleep(sleep_sec); | ||
| END; | ||
| END LOOP; | ||
| RETURN res; | ||
| END; | ||
| $$ LANGUAGE plpgsql STRICT; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| # mvtbl extension | ||
| comment = 'Helper to move tables around tablespaces' | ||
| default_version = '0.0.2' | ||
| default_version = '0.0.3' | ||
| relocatable = true | ||
| requires = '' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.