-
Notifications
You must be signed in to change notification settings - Fork 22
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
Automatically do post upgrade steps (vacuum analyze, database reindexing) #50
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7ea0a4b
Automatically analyze & reindex the database cluster after upgrade
justinclift 6d4a9e7
One-shot mode shouldn't start PG if theres no upgrade to do
justinclift db51d2d
Lets not keep a separate log file hanging around
justinclift dcbed7e
Add reasonable initial tests of 'one shot' mode
justinclift 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 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 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 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 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 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,90 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
if [ $# -ne 2 ]; then | ||
echo "Required number of arguments not passed to post upgrade script. 2 expected, $# received" | ||
exit 1 | ||
fi | ||
|
||
PGDATA=$1 | ||
PGAUTO_ONESHOT=$2 | ||
|
||
# Wait for PostgreSQL to start and become available | ||
COUNT=0 | ||
RUNNING=1 | ||
while [ $RUNNING -ne 0 ] && [ $COUNT -le 20 ]; do | ||
# Check if PostgreSQL is running yet | ||
echo "------ Checking if PostgreSQL is running, loop count ${COUNT} ------" | ||
set +e | ||
pg_isready -q | ||
RUNNING=$? | ||
set -e | ||
|
||
if [ $RUNNING -eq 0 ]; then | ||
echo "PostgreSQL is running. Post upgrade tasks will start shortly" | ||
else | ||
echo "PostgreSQL is not yet running, lets wait then try again..." | ||
sleep 3 | ||
fi | ||
|
||
COUNT=$((COUNT+1)) | ||
done | ||
|
||
if [ $RUNNING -ne 0 ]; then | ||
echo "PostgreSQL did not start before timeout expired" | ||
exit 2 | ||
fi | ||
|
||
# Get the list of databases in the database cluster | ||
DB_LIST=$(echo 'SELECT datname FROM pg_catalog.pg_database WHERE datistemplate IS FALSE' | psql -1t --csv postgres) | ||
|
||
# Update query planner statistics | ||
echo "----------------------------" | ||
echo "Updating query planner stats" | ||
echo "----------------------------" | ||
|
||
for DATABASE in ${DB_LIST}; do | ||
echo "VACUUM (ANALYZE, VERBOSE, INDEX_CLEANUP FALSE)" | psql -t --csv "${DATABASE}" | ||
done | ||
|
||
echo "-------------------------------------" | ||
echo "Finished updating query planner stats" | ||
echo "-------------------------------------" | ||
|
||
# Reindex the databases | ||
echo "------------------------" | ||
echo "Reindexing the databases" | ||
echo "------------------------" | ||
|
||
# For each database, reindex it | ||
for DATABASE in ${DB_LIST}; do | ||
echo "-------------------------------" | ||
echo "Starting reindex of ${DATABASE}" | ||
echo "-------------------------------" | ||
|
||
echo 'REINDEX DATABASE CONCURRENTLY' | psql -t --csv "${DATABASE}" | ||
|
||
echo "-------------------------------" | ||
echo "Finished reindex of ${DATABASE}" | ||
echo "-------------------------------" | ||
done | ||
|
||
echo "-------------------------------" | ||
echo "End of reindexing the databases" | ||
echo "-------------------------------" | ||
|
||
# If "one shot" mode was requested, then shut down PostgreSQL | ||
if [ "x${PGAUTO_ONESHOT}" = "xyes" ]; then | ||
andyundso marked this conversation as resolved.
Show resolved
Hide resolved
|
||
echo "****************************************************************************************************" | ||
echo "'One shot' automatic upgrade was requested, so exiting now that the post upgrade tasks have finished" | ||
echo "****************************************************************************************************" | ||
pg_ctl stop -D "${PGDATA}" | ||
else | ||
echo "*************************************************************************************************" | ||
echo "Post upgrade tasks have finished successfully. PostgreSQL should now be fully updated and online" | ||
echo "*************************************************************************************************" | ||
fi | ||
|
||
# Run a sync before exiting, just to ensure everything is flushed to disk before docker terminates the process | ||
sync |
This file contains 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 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,4 +1,3 @@ | ||
version: "2.1" | ||
x-redash-service: &redash-service | ||
image: redash/redash:10.1.0.b50633 | ||
depends_on: | ||
|
This file contains 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,4 +1,3 @@ | ||
version: "2.1" | ||
x-redash-service: &redash-service | ||
image: redash/redash:10.1.0.b50633 | ||
depends_on: | ||
|
This file contains 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,4 +1,3 @@ | ||
version: "2.1" | ||
x-redash-service: &redash-service | ||
image: redash/redash:10.1.0.b50633 | ||
depends_on: | ||
|
This file contains 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,4 +1,3 @@ | ||
version: "2.1" | ||
x-redash-service: &redash-service | ||
image: redash/redash:10.1.0.b50633 | ||
depends_on: | ||
|
This file contains 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,4 +1,3 @@ | ||
version: "2.1" | ||
x-redash-service: &redash-service | ||
image: redash/redash:10.1.0.b50633 | ||
depends_on: | ||
|
This file contains 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,4 +1,3 @@ | ||
version: "2.1" | ||
x-redash-service: &redash-service | ||
image: redash/redash:10.1.0.b50633 | ||
depends_on: | ||
|
This file contains 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,4 +1,3 @@ | ||
version: "2.1" | ||
x-redash-service: &redash-service | ||
image: redash/redash:10.1.0.b50633 | ||
depends_on: | ||
|
This file contains 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,4 +1,3 @@ | ||
version: "2.1" | ||
x-redash-service: &redash-service | ||
image: redash/redash:10.1.0.b50633 | ||
depends_on: | ||
|
This file contains 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,4 +1,3 @@ | ||
version: "2.1" | ||
x-redash-service: &redash-service | ||
image: redash/redash:10.1.0.b50633 | ||
depends_on: | ||
|
This file contains 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,4 +1,3 @@ | ||
version: "2.1" | ||
x-redash-service: &redash-service | ||
image: redash/redash:10.1.0.b50633 | ||
depends_on: | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good messages, will make it very clear to users what is happening.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. 😄