zoukankan      html  css  js  c++  java
  • 如何获取 Greenplum 中用户最后登录时间和登录频率

    这几天搞系统迁移,老板突然想知道给客户开的那么多用户当中,哪些还在用,哪些已经不用了。我们的数据库是 Greenplum,而且还是一直没有升级的老版本,Google 了一下没有发现特别好的查看用户登录情况的方法。咨询了 Greenplum 的售后同事后,对方建议我们使用 gp_toolkit.gp_log_database 通过遍历日志来获取用户登录信息。

    gp_log_database 的详细信息可以在官方指南里找到。

    https://gpdb.docs.pivotal.io/43130/ref_guide/gp_toolkit.html#topic16

    官方关于它的描述是“This view uses an external table to read the server log files of the entire Greenplum system (master, segments, and mirrors) and lists log entries associated with the current database. Associated log entries can be identified by the session id (logsession) and command id (logcmdcount). The use of this view requires superuser permissions.”

    注意这里的 entire Greenplum system (master, segments, and mirrors) ,意味着这个 view 将会尝试去加载海量的所有日志文件。一开始我还抱有幻想觉得可能有什么高大上的方式来获取日志数据,直到我看到报错信息里的 cat 才知道它就是一次性把所有日志读进 Greenplum。

    所以为了让查询能进行下去,我不得不把所有 segment 和 mirror 的日志都先藏起来,然后把 master 上除了今年的日志之外的日志也都藏起来,只留下了 master 上今年至今不到5个月的日志。

    之后,psql 进入数据库,直接查询 gp_toolkit.gp_log_database,例如查查各个用户今年以来最后一次登录时间:

    select loguser, max(logtime)

    from gp_toolkit.gp_log_database

    where logdatabase='xxxxx'

    group by loguser

    order by max(logtime) desc;

    然后再查查到目前为止每个用户都有多少天有登录过:

    select loguser, count(distinct cast(logtime as date))

    from gp_toolkit.gp_log_database

    where logdatabase='xxxxx'

    group by loguser

    order by count(distinct cast(logtime as date)) desc;

  • 相关阅读:
    dirname,basename的用法与用途
    终极解决方案——sbt配置阿里镜像源,解决sbt下载慢,dump project structure from sbt耗时问题
    linux-manjaro下添加Yahei Hybrid Consola字体
    Idea无法调出搜狗等中文输入法
    Spring 源码学习系列
    BF算法
    Mybatis Mapper接口是如何找到实现类的-源码分析
    Lua脚本在redis分布式锁场景的运用
    GO语言一行代码实现反向代理
    SpringMVC源码分析-400异常处理流程及解决方法
  • 原文地址:https://www.cnblogs.com/rabbitpei/p/6843460.html
Copyright © 2011-2022 走看看