Skip to content

Added ENV for autovacuum_vacuum_scale_factor and autovacuum_analyze_scale_factor #4

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
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Miggets7
Copy link
Contributor

No description provided.

@Miggets7 Miggets7 requested a review from richturner May 28, 2025 09:14
@richturner
Copy link
Member

Fixes openremote/openremote#1423

@Miggets7 Miggets7 force-pushed the feature/auto_full_vacuum branch from 0ba4bb8 to 98e0202 Compare June 25, 2025 09:16
@MartinaeyNL MartinaeyNL linked an issue Jun 25, 2025 that may be closed by this pull request
@Miggets7 Miggets7 requested a review from richturner June 25, 2025 12:58
@richturner
Copy link
Member

I ran the current commit locally and with OR_ENABLE_VACUUM_FULL=true I get the following:

Starting cron service for scheduled database maintenance (OR_ENABLE_VACUUM_FULL=true)...
 * Starting periodic command scheduler cron
cron: can't open or create /var/run/crond.pid: Permission denied
   ...fail!

Please confirm functionality locally both with existing storage volume and without.

Copy link
Member

@richturner richturner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to deal with the crond file permission issue I mentioned in the comments

Comment on lines 3 to 4
# Log file for vacuum operations
LOG_FILE="/var/lib/postgresql/vacuum_full.log"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log to standard out

Comment on lines 6 to 7
# Check if VACUUM FULL schedule is set
if [ -n "${OR_VACUUM_FULL_CRON_SCHEDULE}" ]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep this outer if in the entrypoint for ease of reading

@richturner
Copy link
Member

Additional tasks:

  • Update README
  • Update docker compose files and deploy.yml in main repo
  • Enable this option on deployments where desired

@richturner richturner assigned richturner and Miggets7 and unassigned richturner and Miggets7 Jun 30, 2025
Removed alpine dockerfile as it became obsolete because of timescaledb arm64 support
@Miggets7 Miggets7 changed the title Added weekly VACUUM FULL maintenance with cron scheduling for database optimization Added ENV for autovacuum_vacuum_scale_factor and autovacuum_analyze_scale_factor Jul 10, 2025
@Miggets7 Miggets7 requested a review from richturner July 10, 2025 09:48
Comment on lines +1 to +19
#!/bin/bash
set -e

echo "-------------------------------------------------------------------------------------"
echo "Setting autovacuum parameters during initialization..."
echo "-------------------------------------------------------------------------------------"

# Set vacuum parameters
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
ALTER SYSTEM SET autovacuum_vacuum_scale_factor = $OR_AUTOVACUUM_VACUUM_SCALE_FACTOR;
ALTER SYSTEM SET autovacuum_analyze_scale_factor = $OR_AUTOVACUUM_ANALYZE_SCALE_FACTOR;
SELECT pg_reload_conf();
EOSQL

echo "-----------------------------------------------------------------------------------"
echo "Autovacuum parameters set: "
echo " - autovacuum_vacuum_scale_factor = $OR_AUTOVACUUM_VACUUM_SCALE_FACTOR"
echo " - autovacuum_analyze_scale_factor = $OR_AUTOVACUUM_ANALYZE_SCALE_FACTOR"
echo "-----------------------------------------------------------------------------------"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this now I don't see value in having this init script and the logic in the entrypoint, the entrypoint logic should be sufficient I think

# Extract current setting if it exists (commented or uncommented)
CURRENT_AUTOVAC_SETTING=$(grep -E "^[#]*autovacuum_vacuum_scale_factor" "$PGDATA/postgresql.conf" | grep -oE "[0-9]\.[0-9]+" || echo "")

if [ -z "$CURRENT_AUTOVAC_SETTING" ] || [ "$CURRENT_AUTOVAC_SETTING" != "$OR_AUTOVACUUM_VACUUM_SCALE_FACTOR" ]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check OR_AUTOVACUUM_VACUUM_SCALE_FACTOR is set if not then leave this setting alone (just in case DBA has configured this manually)

# Extract current setting if it exists (commented or uncommented)
CURRENT_AUTOVAC_ANALYZE_SETTING=$(grep -E "^[#]*autovacuum_analyze_scale_factor" "$PGDATA/postgresql.conf" | grep -oE "[0-9]\.[0-9]+" || echo "")

if [ -z "$CURRENT_AUTOVAC_ANALYZE_SETTING" ] || [ "$CURRENT_AUTOVAC_ANALYZE_SETTING" != "$OR_AUTOVACUUM_ANALYZE_SCALE_FACTOR" ]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check OR_AUTOVACUUM_VACUUM_SCALE_FACTOR is set if not then leave this setting alone (just in case DBA has configured this manually)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve Postgresql performance
2 participants