zoukankan      html  css  js  c++  java
  • Linux shell 操作 postgresql,并设置crontab任务

    Linux shell 操作 postgresql:删除间隔日期的数据
    -删除指定日期的数据
    -vacuumdb 清理数据库

    -清理日志

    -定期执行脚本


    *修改pg_hba.conf 设置本地连接无密码,trust

    # "local" is for Unix domain socket connections only
    local   all             all                                     trust
    # IPv4 local connections:
    host    all             all             127.0.0.1/32            trust
    

    crontab 定期执行
    *添加执行任务

    crontab -e
    
    */1 * * * * /home/sample/delDataAndVacuumdb.sh >> /var/log/pg_maintenance.log
    
    */5 * * * * /home/sample/cleanLog.sh
    

    *查看执行任务

    crontab -l
    

    *查看执行情况

    vi /var/spool/mail/root
    cat /var/log/cron
    

    delDataAndVacuumdb.sh

    #!/bin/bash
    # this script is aimed to delete the expired data;
    # and use the vacummdb command to clean up databases.
    # Copyright(c) 2016--2016 yuxiangli All Copyright reserved.
    echo "-----------------------------------------------------"
    echo `date +%Y%m%d%H%M%S`
    echo "delete the expired data..."
    psql -h 127.0.0.1 -p 5432 -U postgres << EOF
    delete from company where join_date < (select now()::timestamp - interval'1 month'); \q EOF echo "-----------------------------------------------------" echo `date +%Y%m%d%H%M%S` echo "clean the databases..." vacuumdb --host=127.0.0.1 --port=5432 --all --username=postgres --analyze --verbose echo `date +%Y%m%d%H%M%S` echo "-----------------------------------------------------"

    cleanLog.sh

    #!/bin/bash
    rm -rf /var/log/pg_maintenance.log
    exit 0
    
  • 相关阅读:
    oracle数据字典(笔记)
    oracle管理表空间和数据文件(笔记)
    oracle权限管理(笔记)
    hibernate获取session的两个方法(笔记)
    hibernate一级缓存(笔记)
    hibernate主要接口和类(笔记)
    hibernate本地事务、全局事务
    hibernate:get和load方法的区别
    位权
    学习使用CGI和HTML
  • 原文地址:https://www.cnblogs.com/Tiago/p/5379188.html
Copyright © 2011-2022 走看看