zoukankan      html  css  js  c++  java
  • 041.PGSQL-pgsql时间日期错误问题,原来是系统时间问题,使用远程的NTP时间服务器来提供时间的话,需要使用timedatectl设置将NTP时间同步开启。

    pgsql时间错误问题

    mydb@[local]:5432=#select now();
    now
    -------------------------------
    2021-07-05 08:07:22.981157+08


    mydb@[local]:5432=# show time zone;
    TimeZone
    ---------------
    Asia/Shanghai
    (1 row)

    查看可供选择的时区

    mydb@[local]:5432=#select * from pg_timezone_names;
                      name                  | abbrev | utc_offset | is_dst
    ----------------------------------------+--------+------------+--------
     Africa/Accra                           | GMT    | 00:00:00   | f
     Africa/Algiers                         | CET    | 01:00:00   | f
     Africa/Bissau                          | GMT    | 00:00:00   | f
     Africa/Casablanca                      | WEST   | 01:00:00   | t
     Africa/Ceuta                           | CEST   | 02:00:00   | t
     Africa/El_Aaiun                        | WEST   | 01:00:00   | t
     Africa/Monrovia                        | GMT    | 00:00:00   | f
     Africa/Ndjamena                        | WAT    | 01:00:00   | f
     Africa/Tunis                           | CET    | 01:00:00   | f
     Africa/Windhoek                        | WAT    | 01:00:00   | f
     Africa/Abidjan                         | GMT    | 00:00:00   | f
     Africa/Bamako                          | GMT    | 00:00:00   | f
     Africa/Banjul                          | GMT    | 00:00:00   | f
     Africa/Conakry                         | GMT    | 00:00:00   | f
    

    中国公用时间  (PRC指:People's Republic of China)

    mydb@[local]:5432=#select * from pg_timezone_names where name = 'PRC';
    name | abbrev | utc_offset | is_dst
    ------+--------+------------+--------
    PRC | CST | 08:00:00 | f
    (1 row)

    修改配置文件

    [root@s101 /var/lib/pgsql/13/data]#nano postgresql.conf
    log_timezone = 'PRC'

    timezone = 'PRC'

    重启数据库

    [root@s101 /var/lib/pgsql/13/data]#sudo systemctl restart postgresql-13

    再次查看还是没变

    原来是系统时间错误

     设置系统时间

    https://blog.csdn.net/weixin_43545225/article/details/106118354

    https://www.cnblogs.com/actively/p/14078643.html

    再次查看

    ----------------- 续篇

    最近发现时间又不对,硬件时间是对的

    date

    hwclock --show

    timedatectl

    [root@s101 /var/lib/pgsql/13/data]#date

    [root@s101 /var/lib/pgsql/13/data]#hwclock --show

    [root@s101 /var/lib/pgsql/13/data]#timedatectl

    使用远程的NTP时间服务器来提供时间的话,需要使用timedatectl设置将NTP时间同步开启。 

     开启ntp

    [root@s101 /usr/share/zoneinfo/Asia]#timedatectl set-ntp yes

    重启时间模块系统

    [root@s101 /usr/share/zoneinfo/Asia]#systemctl restart systemd-timedated.service

    同步硬件时间等于系统时间

    [root@s101 /usr/share/zoneinfo/Asia]#/sbin/hwclock --systohc

    最终版

     ntpdate time.nist.gov

    修改crontab 定时调度   每小时同步一次时间

    同步时间成功后调整硬件时间

    #hwclock -w

        1.编写调度文件
            [/etc/crontab]
            SHELL=/bin/bash
            PATH=/sbin:/bin:/usr/sbin:/usr/bin
            MAILTO=root
    
            # For details see man 4 crontabs
    
            # Example of job definition:
            # .---------------- minute (0 - 59),分钟
            # |  .------------- hour (0 - 23)
            # |  |  .---------- day of month (1 - 31)
            # |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
            # |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
            # |  |  |  |  |
            # *  *  *  *  * user-name  command to be executed
            * */01 * * * root ntpdate time.nist.gov;hwclock -w2.启动调度服务
            $>su root
            $>service crond status        //查看服务状态
            $>service crond start        //启动服务器
    
        3.设置crond服务开机自启
            $>chkconfig crond on        //启用开机自启

    crontab设置参考

    https://www.cnblogs.com/intval/p/5763929.html

    linux系统时间设置更新同步

    https://www.cnblogs.com/whymoney1000/p/11059803.html

    参考文档

    https://blog.csdn.net/solaraceboy/article/details/78831319

     https://www.cnblogs.com/abclife/p/6171323.html

  • 相关阅读:
    权限管理(java+struts2(自定义标签)实现)--------->全代码演示
    颜色的几个术语和属性
    颜色的不同表达方式
    bootstrap作为mixin库的应用模式
    -webkit-min-device-pixel-ratio: 2是什么意思?
    如何在前端项目中引用bootstrap less?
    js闭包??
    win 运行
    win 2016 添加系统组件注册表,
    C# window服务操作
  • 原文地址:https://www.cnblogs.com/star521/p/15072192.html
Copyright © 2011-2022 走看看