• Home
  • Services
    • DBA Support
    • DBA Consultancy Services
    • PostgreSQL Support
    • Website Maintenance
  • Courses

    About Courses

    • List Of Courses
    • Become an Instructor
    Greenplum Database

    Greenplum Database

    $2,000.00 $1,500.00
    Read More
  • Company
    • FAQs
    • About Us
    • Contact
  • Events
  • Portfolio
  • Blogs
    • Blog – RayaFeeL
    • Blog – PostgreSQL Support
    • Blog – PostgreSQL Migration
    • Blog – All DB’s
    • Blog – Linux
    • Blog – Medical Coding
      • Cart

        0

    Have any question?
    (+91)8838953252
    ITsupport@rayafeel.com
    RegisterLogin
    RayaFeeL
    • Home
    • Services
      • DBA Support
      • DBA Consultancy Services
      • PostgreSQL Support
      • Website Maintenance
    • Courses

      About Courses

      • List Of Courses
      • Become an Instructor
      Greenplum Database

      Greenplum Database

      $2,000.00 $1,500.00
      Read More
    • Company
      • FAQs
      • About Us
      • Contact
    • Events
    • Portfolio
    • Blogs
      • Blog – RayaFeeL
      • Blog – PostgreSQL Support
      • Blog – PostgreSQL Migration
      • Blog – All DB’s
      • Blog – Linux
      • Blog – Medical Coding
        • Cart

          0

      Blog

      • Home
      • Blog
      • Blog
      • script for VACUUM and ANALYZE for postgres database

      script for VACUUM and ANALYZE for postgres database

      • Posted by 2ndnijam
      • Categories Blog
      • Date February 9, 2019
      • Comments 0 comment

      vacuum_and_analyze.sh script vacuums and analyzes all the database of an instance. Script pick the instance on the basis of details provided in cronjobs_conf_5432.sh. If you have multiple instances, and you want to run vacuum_and_analyze.sh for those instances too, by tweaking the instance details in cronjobs_conf_5432.sh.

      bash-4.1$ cat  /post/open_source/scripts/vacuum_and_analyze.sh
      #!/bin/bash
      
      usage()
      {
         echo -e "\n\tUsage:  `basename $0` -c /home/postgres/edbscripts/cronjobs_conf_5432.sh\n"
         echo -e "\tNote :  Absolute path required for cronjobs configuration file\n"
         exit 1
      }
      
      while getopts ":c:" opt; do
          case "${opt}" in
               c)
                  CONF=${OPTARG}
                  ;;
               *) echo "Unknown option: -$OPTARG" >&2; usage ;break;;
           esac
      done
      if [ -z "${CONF}" ]; then
         usage
      fi
      if [ ! -f "${CONF}" ]; then
         echo -e "\t\nNot a valid conf file...$CONF"
         exit 1
      fi
      
      ### Main script process
      
      source ${CONF}
      
      process()
      {
         echo -e "\n::::::::::::  VACUUM ANALYZE Details  :::::::::::::::\n"
         echo    "VACUUM ANALYZE LOG.: $CRONLOG_LOCATION/vacuum_analyze_$FILE_TIMESTAMP.log"
         START=$(date +%s)
         $PGBIN/vacuumdb -a -z -v -h $PGHOST -U $PGUSER -p $PGPORT >>$CRONLOG_LOCATION/vacuum_analyze_$FILE_TIMESTAMP.log 2>>$CRONLOG_LOCATION/vacuum_analyze_$FILE_TIMESTAMP.log
         result=${?}
         if [ ${result} -ne 0 ]
         then
            echo "Please connect to the server ASAP"| mailx -s "::ALERT::`hostname` - VACUUM Failed" $CUSTOMER_EMAIL
            echo "`date`|$CUSTOMER_NAME|`basename $0`|false|vacuum failed" >>$CRONLOG_LOCATION/cronjobs.csv
            exit 1
         else
            echo "vacuum analyze completed successfully">>$CRONLOG_LOCATION/vacuum_analyze_$FILE_TIMESTAMP.log
            END=$(date +%s)
            DIFF=$(($END-$START))
            VDB=`awk '/vacuuming database/ {print $4}' $CRONLOG_LOCATION/vacuum_analyze_$FILE_TIMESTAMP.log|wc -l`
            ISSUES=`grep -i "error:" $CRONLOG_LOCATION/vacuum_analyze_$FILE_TIMESTAMP.log|wc -l`
            echo "VACUUMED INFO.....: vacuumed $PGPORT port of $VDB databases."
            echo "TIME..............: started at $(date -d @"$START" +%d-%m-%y' '%T) with total time $((diff/60))M $((diff%60))s"
            echo "VACUUM ISSUES.....: In logs $(if [ $ISSUES -ge 1 ]; then echo "$ISSUES found. Please check logs"; else echo "nothing found"; fi)"
            echo "`date`|$CUSTOMER_NAME|`basename $0`|true|vacuum completed" >>$CRONLOG_LOCATION/cronjobs.csv
         fi
      }
      process >>$CRONLOG_LOCATION/crons_summary.log
      exit 0
      
      

      • Share:
      2ndnijam

      Previous post

      Script to move and compress the postgres logs
      February 9, 2019

      Next post

      How to schedule VACUUM and ANALYZE script for for postgres database ?
      February 9, 2019

      Leave A Reply Cancel reply

      You must be logged in to post a comment.

      Login with:

      Login with Google Login with Twitter Login with LinkedIn Login with Microsoft


      Search

      ADVERTISEMENT

      Latest Posts

      PostgreSQL Patching version 9, 10,11
      10Oct2019
      Tools for PostgreSQL
      16Sep2019
      Postgres user creation and restrict DDL & database access
      13Sep2019
      PostgreSQL SSL Setup
      07Sep2019
      How to DELETE current XLOG / WAL LOG in postgresql database ?
      19Aug2019

      Latest Courses

      PostgreSQL Database

      PostgreSQL Database

      $600.00 $500.00
      Greenplum Database

      Greenplum Database

      $2,000.00 $1,500.00

      Preview Course

      Free

      Recent Forum Topics

      • thought behind whiteboard activity
      • Are you going to take your first ste
      • How to start working on an application?
      • please let me know pre requirements to increase work_mem
      • how to copy some data in one table to another table in postgres

      2ndquadrant.in

      (+91) 8838953252

      ITsupport@rayafeel.com

      Company

      • About Us
      • Contact
      • Our Team
      • Blog

      COURSES

      • List Of Course
      • Become An Instructor
      • Events
      • Postgres Support Blog

      Support

      • DBA Support
      • Consultancy Services
      • Postgres Migration Blogs
      • Forum

      Recommend

      • Groups
      • Login
      • FAQs
      • SignUp

      IT Services by rayafeel.com. Powered by Rayafeel Technologies Pvt Ltd.

      • Privacy
      • Terms

      Become An Instructor?

      Join thousand of instructors and earn money hassle free!

      Get Started Now

      Login with:

      Login with Google Login with Twitter Login with LinkedIn Login with Microsoft

      Login with your site account

      Lost your password?

      Not a member yet? Register now

      Register a new account

      Are you a member? Login now