Skip to content Skip to sidebar Skip to footer

Using Crontab to Cut Postgresql Connection

So here i have a problem between my odoo server and postgresql, as i described in my other post about error of odoo loading takes too long time to validate a document. And then i decide to cut and reconnect the session between them automatically everyday using crontab. Crontab is likely a scheduler program in windows which is run a script, command, or an app for particular time based on when you want it to run. It's as simply as that.

So here is how i use crontab :
  1. Login to your server as root;
  2. In this tutorial i would like to create a script that disconnect and reconnect postgresql so what i need is create a file script named stop.sh and start.sh;
  3. I create stop.sh by typing nano stop.sh and then type in the command to stop postgres, which is systemctl stop postgresql@11-main. Save it and exit;
  4. Later on, i make that file executable by running chmod +x stop.sh;
  5. I repeat the number 4 and 5 step to create start.sh (you can skip this);
  6. Type command crontab -e;
  7. Make a setting which you would like to run the previous script you create as following these image :
    crontab hour
    For exampe, i would like to run stop.sh at 4 AM so i need to make it like picture above. Also, at 4:05 AM i would like to start.sh to executed so i put the script above.

    Here is a basic instruction of crontab, thanks to tecadmin.net for providing the image

    crontab format - Source : tecadmin.net