Add BLOB/large object verification script for backup diagnostics
This commit is contained in:
@@ -6,44 +6,53 @@
|
|||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
NEW_VALUE=${1:-256}
|
NEW_VALUE=${1:-256}
|
||||||
|
|
||||||
CONFIG_FILE="$(sudo -u postgres psql -t -c "SHOW config_file;" | tr -d '[:space:]')"
|
CONFIG_FILE="/var/lib/pgsql/data/postgresql.conf"
|
||||||
if [ -z "$CONFIG_FILE" ]; then
|
|
||||||
echo "Could not locate postgresql.conf; aborting"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "postgres config file: $CONFIG_FILE"
|
|
||||||
BACKUP_FILE="${CONFIG_FILE}.bak.$(date +%s)"
|
BACKUP_FILE="${CONFIG_FILE}.bak.$(date +%s)"
|
||||||
|
|
||||||
|
echo "PostgreSQL config file: $CONFIG_FILE"
|
||||||
|
|
||||||
# Create a backup
|
# Create a backup
|
||||||
sudo cp "$CONFIG_FILE" "$BACKUP_FILE"
|
sudo cp "$CONFIG_FILE" "$BACKUP_FILE"
|
||||||
sudo chown postgres:postgres "$BACKUP_FILE"
|
|
||||||
chmod 600 "$BACKUP_FILE"
|
|
||||||
|
|
||||||
echo "Backup written to $BACKUP_FILE"
|
echo "Backup written to $BACKUP_FILE"
|
||||||
|
|
||||||
# Use sed to update (or add) setting
|
# Check if setting exists (commented or not)
|
||||||
# If the setting is present (commented or uncommented), replace the line. Otherwise append.
|
if sudo grep -qE "^\s*#?\s*max_locks_per_transaction\s*=" "$CONFIG_FILE"; then
|
||||||
if sudo grep -q "^\s*max_locks_per_transaction\s*=\s*" "$CONFIG_FILE"; then
|
|
||||||
echo "Updating existing max_locks_per_transaction to $NEW_VALUE"
|
echo "Updating existing max_locks_per_transaction to $NEW_VALUE"
|
||||||
sudo sed -ri "s#^\s*#?max_locks_per_transaction\s*=.*#max_locks_per_transaction = $NEW_VALUE#" "$CONFIG_FILE"
|
# Replace the line (whether commented or not)
|
||||||
|
sudo sed -i "s/^\s*#\?\s*max_locks_per_transaction\s*=.*/max_locks_per_transaction = $NEW_VALUE/" "$CONFIG_FILE"
|
||||||
else
|
else
|
||||||
echo "Adding max_locks_per_transaction = $NEW_VALUE to config"
|
echo "Adding max_locks_per_transaction = $NEW_VALUE to config"
|
||||||
echo "\n# Increased by fix_max_locks.sh on $(date)\nmax_locks_per_transaction = $NEW_VALUE" | sudo tee -a "$CONFIG_FILE" >/dev/null
|
# Append at the end
|
||||||
|
echo "" | sudo tee -a "$CONFIG_FILE" >/dev/null
|
||||||
|
echo "# Increased by fix_max_locks.sh on $(date)" | sudo tee -a "$CONFIG_FILE" >/dev/null
|
||||||
|
echo "max_locks_per_transaction = $NEW_VALUE" | sudo tee -a "$CONFIG_FILE" >/dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Ensure correct permissions
|
# Ensure correct permissions
|
||||||
sudo chown postgres:postgres "$CONFIG_FILE"
|
sudo chown postgres:postgres "$CONFIG_FILE"
|
||||||
sudo chmod 600 "$CONFIG_FILE"
|
sudo chmod 600 "$CONFIG_FILE"
|
||||||
|
|
||||||
|
# Test the config before restarting
|
||||||
|
echo "Testing PostgreSQL config..."
|
||||||
|
sudo -u postgres /usr/bin/postgres -D /var/lib/pgsql/data -C max_locks_per_transaction 2>&1 | head -5
|
||||||
|
|
||||||
# Restart PostgreSQL and verify
|
# Restart PostgreSQL and verify
|
||||||
echo "Restarting PostgreSQL service..."
|
echo "Restarting PostgreSQL service..."
|
||||||
sudo systemctl restart postgresql
|
sudo systemctl restart postgresql
|
||||||
sleep 2
|
sleep 3
|
||||||
|
|
||||||
echo "Verifying new value:"
|
if sudo systemctl is-active --quiet postgresql; then
|
||||||
|
echo "✅ PostgreSQL restarted successfully"
|
||||||
sudo -u postgres psql -c "SHOW max_locks_per_transaction;"
|
sudo -u postgres psql -c "SHOW max_locks_per_transaction;"
|
||||||
|
else
|
||||||
|
echo "❌ PostgreSQL failed to start!"
|
||||||
|
echo "Restoring backup..."
|
||||||
|
sudo cp "$BACKUP_FILE" "$CONFIG_FILE"
|
||||||
|
sudo systemctl start postgresql
|
||||||
|
echo "Original config restored. Check /var/log/postgresql for errors."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
echo "If the restart fails, you can restore the previous config with:\n sudo cp $BACKUP_FILE $CONFIG_FILE && sudo systemctl restart postgresql"
|
echo ""
|
||||||
|
echo "Success! Backup available at: $BACKUP_FILE"
|
||||||
exit 0
|
exit 0
|
||||||
|
|||||||
Reference in New Issue
Block a user