{
  "annotations":{"list":[{"builtIn":1,"datasource":{"type":"datasource","uid":"grafana"},"enable":true,"hide":true,"iconColor":"rgba(0, 211, 255, 1)","name":"Annotations & Alerts","target":{"limit":100,"matchAny":false,"tags":[],"type":"dashboard"},"type":"dashboard"}]},
  "author":"Ruohang Feng (rh@vonng.com)",
  "description":"PostgreSQL Catalog : Activity & Locks",
  "editable":true,
  "fiscalYearStartMonth":0,
  "graphTooltip":0,
  "id":null,
  "license":"https://pigsty.io/docs/about/license/",
  "links":[
    { "asDropdown":true,"icon":"external link","includeVars":true,"keepTime":true,"tags":["Pigsty","PGSQL","Overview"],"targetBlank":false,"title":"Overview","tooltip":"","type":"dashboards","url":"" },{ "asDropdown":true,"icon":"external link","includeVars":true,"keepTime":true,"tags":["Pigsty","PGSQL","Cluster"] ,"targetBlank":false,"title":"Cluster" ,"tooltip":"","type":"dashboards","url":"" },
    { "asDropdown":true,"icon":"external link","includeVars":true,"keepTime":true,"tags":["Pigsty","PGSQL","Instance"],"targetBlank":false,"title":"Instance","tooltip":"","type":"dashboards","url":"" },{ "asDropdown":true,"icon":"external link","includeVars":true,"keepTime":true,"tags":["Pigsty","PGSQL","Database"],"targetBlank":false,"title":"Database","tooltip":"","type":"dashboards","url":"" }
  ],
  "panels":[
    {"collapsed":false,"gridPos":{"h":1,"w":24,"x":0,"y":0},"id":201,"panels":[],"title":"Overview","type":"row"},
    {
      "datasource":{"type":"marcusolsson-static-datasource","uid":"ds-static"},
      "description":"",
      "fieldConfig":{
        "defaults":{"color":{"mode":"thresholds"},"mappings":[],"max":2.5,"min":0,"thresholds":{"mode":"absolute","steps":[{"color":"#3e668f"}]}},
        "overrides":[
          { "matcher":{"id":"byFrameRefID","options":"A"},"properties":[{"id":"links","value":[{"title":"PGCAT Instance : ${dsn:text}","url":"/d/pgcat-instance?var-dsn=${dsn:text}&${__url_time_range}"}]}]             },
          { "matcher":{"id":"byFrameRefID","options":"B"},"properties":[{"id":"links","value":[{"title":"PGSQL Cluster : ${cls}","url":"/d/pgsql-cluster?var-cls=${cls}&${__url_time_range}"}]}]                         },
          { "matcher":{"id":"byFrameRefID","options":"C"},"properties":[{"id":"links","value":[{"title":"PGCAT Database : ${ins}.${datname}","url":"/d/pgcat-database?var-dsn=${ins}.${datname}&${__url_time_range}"}]}] }
        ]
      },
      "gridPos":{"h":6,"w":6,"x":0,"y":1},
      "id":230,
      "options":{"colorMode":"background","graphMode":"area","justifyMode":"auto","orientation":"horizontal","percentChangeColorMode":"standard","reduceOptions":{"calcs":["lastNotNull"],"fields":"/.*/","values":true},"showPercentChange":false,"text":{"titleSize":16,"valueSize":16},"textMode":"value_and_name","wideLayout":true},
      "pluginVersion":"12.0.0",
      "targets":[
        { "datasource":{"type":"marcusolsson-static-datasource","uid":"ds-static"},"frame":{"fields":[{"config":{},"name":"Database","type":"string","values":["${datname}"]}],"meta":{},"name":""},"hide":false,"refId":"C" },
        { "datasource":{"type":"marcusolsson-static-datasource","uid":"ds-static"},"frame":{"fields":[{"config":{},"name":"Instance","type":"string","values":["$ins"]}],"meta":{},"name":""}      ,"hide":false,"refId":"A" },
        { "datasource":{"type":"marcusolsson-static-datasource","uid":"ds-static"},"frame":{"fields":[{"config":{},"name":"Cluster","type":"string","values":["${cls}"]}],"meta":{},"name":""}     ,"hide":false,"refId":"B" }
      ],
      "title":"",
      "type":"stat"
    },
    {
      "datasource":{"type":"prometheus","uid":"ds-prometheus"},
      "description":"",
      "fieldConfig":{
        "defaults":{"color":{"mode":"thresholds"},"custom":{"align":"center","cellOptions":{"type":"auto"},"inspect":false},"mappings":[],"max":1.2,"min":0,"thresholds":{"mode":"absolute","steps":[{"color":"#e3e3e3e0"}]}},
        "overrides":[
          {"matcher":{"id":"byName","options":"Instance"},"properties":[{"id":"links","value":[{"title":"PGCAT Database : ${__data.fields.Instance}.${datname}","url":"/d/pgcat-database?var-dsn=${__data.fields.Instance}.${datname}&${__url_time_range}"}]},{"id":"custom.width"}]},
          {"matcher":{"id":"byName","options":"IP"},"properties":[{"id":"custom.width","value":110},{"id":"links","value":[{"title":"Node Instance : ${__data.fields.IP}","url":"/d/node-instance?var-id=${__data.fields.IP}&${__url_time_range}"}]}]},
          {
            "matcher":{"id":"byName","options":"Role"},
            "properties":[
              { "id":"custom.width"      ,"value":80                                                                                                                                             },{ "id":"mappings"          ,"value":[{"options":{"0":{"color":"#3e668f","index":0,"text":"primary"},"1":{"color":"#346f36cc","index":1,"text":"replica"}},"type":"value"}]         },
              { "id":"custom.cellOptions","value":{"mode":"gradient","type":"color-background"}                                                                                                  },{ "id":"links"             ,"value":[{"title":"PGSQL Service for ${cls}-${__data.fields.Role}","url":"/d/pgsql-service?var-svc=${cls}-${__data.fields.Role}&${__url_time_range}"}] }
            ]
          },{
            "matcher":{"id":"byName","options":"Load"},
            "properties":[
              { "id":"custom.cellOptions","value":{"mode":"gradient","type":"gauge"}                                                                                                                                                                                                         },
              { "id":"color"             ,"value":{"mode":"thresholds"}                                                                                                                                                                                                                      },
              { "id":"unit"              ,"value":"percentunit"                                                                                                                                                                                                                              },
              { "id":"custom.width"      ,"value":120                                                                                                                                                                                                                                        },
              { "id":"thresholds"        ,"value":{"mode":"absolute","steps":[{"color":"#3e668f"},{"color":"#346f36cc","value":0.1},{"color":"#fcdb72","value":0.3},{"color":"#f79f64","value":0.5},{"color":"red","value":0.7},{"color":"#b783af","value":0.9},{"color":"text","value":1}]} },
              { "id":"decimals"          ,"value":1                                                                                                                                                                                                                                          },
              { "id":"mappings"          ,"value":[{"options":{"-1":{"color":"transparent","index":0,"text":"N/A"}},"type":"value"}]                                                                                                                                                         }
            ]
          },
          {"matcher":{"id":"byName","options":"Cluster"},"properties":[{"id":"links","value":[{"title":"PGSQL Cluster for ${__data.fields.Cluster}","url":"/d/pgsql-cluster?var-cls=${__data.fields.Cluster}&${__url_time_range}"}]}]},
          {"matcher":{"id":"byName","options":"TPS"},"properties":[{"id":"custom.width","value":80},{"id":"thresholds","value":{"mode":"absolute","steps":[{"color":"#3e668f"},{"color":"#3e668f","value":32},{"color":"#f79f64","value":32000}]}},{"id":"custom.cellOptions","value":{"type":"color-text"}}]},
          {"matcher":{"id":"byName","options":"QPS"},"properties":[{"id":"custom.width","value":80},{"id":"thresholds","value":{"mode":"absolute","steps":[{"color":"#3e668f"},{"color":"#3e668f","value":32},{"color":"#f79f64","value":32000}]}},{"id":"custom.cellOptions","value":{"type":"color-text"}}]},
          {
            "matcher":{"id":"byName","options":"Conn"},
            "properties":[{"id":"custom.width","value":80},{"id":"thresholds","value":{"mode":"absolute","steps":[{"color":"#3e668f"},{"color":"#346f36cc","value":4},{"color":"#EAB839","value":20},{"color":"#EF843C","value":40},{"color":"#E24D42","value":80},{"color":"#b783af","value":100},{"color":"text","value":400}]}},{"id":"custom.cellOptions","value":{"type":"color-text"}}]
          },{
            "matcher":{"id":"byName","options":"RT"},
            "properties":[
              { "id":"custom.width"      ,"value":80                                                                                                                                                                                                  },
              { "id":"unit"              ,"value":"s"                                                                                                                                                                                                 },
              { "id":"mappings"          ,"value":[{"options":{"match":"nan","result":{"index":1,"text":"-"}},"type":"special"}]                                                                                                                      },
              { "id":"thresholds"        ,"value":{"mode":"absolute","steps":[{"color":"#346f36cc"},{"color":"#fcdb72","value":1},{"color":"#f79f64","value":2},{"color":"red","value":4},{"color":"#b783af","value":8},{"color":"text","value":16}]} },
              { "id":"custom.cellOptions","value":{"type":"color-text"}                                                                                                                                                                               }
            ]
          },
          {"matcher":{"id":"byName","options":"Queue"},"properties":[{"id":"custom.width","value":60},{"id":"thresholds","value":{"mode":"absolute","steps":[{"color":"#346f36cc"},{"color":"red","value":1}]}},{"id":"custom.cellOptions","value":{"type":"color-text"}}]},
          {"matcher":{"id":"byName","options":"HAProxy"},"properties":[{"id":"links","value":[{"targetBlank":true,"title":"HAProxy Admin Page : ${__data.fields.Instance}","url":"/haproxy/${__data.fields.Instance}"}]}]},
          {"matcher":{"id":"byName","options":"Up"},"properties":[{"id":"custom.width","value":80},{"id":"mappings","value":[{"options":{"0":{"color":"#cc4637d9","index":0,"text":"Dead"},"1":{"color":"#346f36cc","index":1,"text":"Alive"}},"type":"value"}]},{"id":"custom.cellOptions","value":{"type":"color-background"}}]}
        ]
      },
      "gridPos":{"h":6,"w":8,"x":6,"y":1},
      "id":199,
      "links":[{"title":"PGSQL Instance : ${primary}","url":"/d/pgsql-instance?var-ins=${primary}&${__url_time_range}"}],
      "options":{"cellHeight":"sm","footer":{"countRows":false,"fields":"","reducer":["sum"],"show":false},"showHeader":true,"sortBy":[{"desc":false,"displayName":"Instance"}]},
      "pluginVersion":"12.0.0",
      "targets":[
        { "datasource":{"type":"prometheus","uid":"ds-prometheus"},"editorMode":"code","exemplar":false,"expr":"min by (ins,ip) (up{job=\"pgsql\", cls=\"$cls\"})"                                       ,"format":"table","hide":false,"instant":true,"interval":"","legendFormat":"","refId":"A" },
        { "datasource":{"type":"prometheus","uid":"ds-prometheus"},"editorMode":"code","exemplar":false,"expr":"max by (ins) (pg:ins:load1{cls=\"$cls\"})"                                               ,"format":"table","hide":false,"instant":true,"interval":"","legendFormat":"","refId":"B" },
        { "datasource":{"type":"prometheus","uid":"ds-prometheus"},                    "exemplar":false,"expr":"sum by (ins) (pg:ins:xact_total_rate1m{cls=\"$cls\"})"                                   ,"format":"table","hide":false,"instant":true,"interval":"","legendFormat":"","refId":"C" },
        { "datasource":{"type":"prometheus","uid":"ds-prometheus"},"editorMode":"code","exemplar":false,"expr":"min by (ins,ip) (pg_in_recovery{cls=\"$cls\"})"                                          ,"format":"table","hide":false,"instant":true,"interval":"","legendFormat":"","refId":"D" },
        { "datasource":{"type":"prometheus","uid":"ds-prometheus"},                    "exemplar":false,"expr":"max by (ins) (pg:ins:num_backends{cls=\"$cls\"})"                                        ,"format":"table","hide":false,"instant":true,"interval":"","legendFormat":"","refId":"E" },
        { "datasource":{"type":"prometheus","uid":"ds-prometheus"},                    "exemplar":false,"expr":"max by (ins) (pgbouncer:ins:xact_rt_1m{cls=\"$cls\"})"                                   ,"format":"table","hide":false,"instant":true,"interval":"","legendFormat":"","refId":"F" },
        { "datasource":{"type":"prometheus","uid":"ds-prometheus"},                    "exemplar":false,"expr":"sum by (ins,instance) (haproxy_backend_current_sessions{cls=\"$cls\", proxy!=\"stats\"})","format":"table","hide":false,"instant":true,"interval":"","legendFormat":"","refId":"G" }
      ],
      "title":"",
      "transformations":[
        {"id":"seriesToColumns","options":{"byField":"ins"}},
        {
          "id":"organize",
          "options":{
            "excludeByName":{
              "Time":true,
              "Time 1":true,
              "Time 10":true,
              "Time 2":true,
              "Time 3":true,
              "Time 4":true,
              "Time 6":true,
              "Time 8":true,
              "Time 9":true,
              "Value #A":false,
              "Value #B":false,
              "Value #C":false,
              "Value #E":false,
              "Value #F":true,
              "Value #G":true,
              "Value #H":false,
              "__name__":true,
              "__name__ 1":true,
              "__name__ 2":true,
              "__name__ 3":true,
              "__name__ 5":true,
              "__name__ 7":true,
              "cls":true,
              "cls 1":true,
              "cls 2":true,
              "cls 3":true,
              "cls 4":true,
              "cls 5":true,
              "cls 6":true,
              "cls 7":true,
              "instance":true,
              "instance 1":true,
              "instance 2":false,
              "instance 3":true,
              "instance 4":true,
              "instance 5":true,
              "instance 6":true,
              "ip 2":true,
              "ip 3":true,
              "ip 4":true,
              "ip 5":true,
              "ip 6":true,
              "ip 7":true,
              "job":true,
              "job 1":true,
              "job 2":true,
              "job 3":true,
              "job 4":true,
              "job 5":true,
              "job 6":true,
              "job 7":true
            },
            "indexByName":{"Time 1":8,"Time 2":9,"Time 3":10,"Time 4":11,"Time 5":12,"Time 6":14,"Value #A":0,"Value #B":4,"Value #C":5,"Value #D":1,"Value #E":6,"Value #F":7,"ins":2,"ip 1":3,"ip 2":13},
            "renameByName":{"Time 4":"","Value #A":"Up","Value #B":"Load","Value #C":"TPS","Value #D":"Role","Value #E":"Conn","Value #F":"RT","Value #G":"LB Conn","Value #H":"LB","Value #I":"QPS","Value #J":"LB Clients","Value #K":"Lag","cls 1":"","cls 2":"","ins":"Instance","instance":"HAProxy","instance 2":"","ip":"IP","ip 1":"IP"}
          }
        }
      ],
      "type":"table"
    },
    {
      "datasource":{"type":"postgres","uid":"${dsn}"},
      "description":"Databases of this instance\nTmpl: is this database a template?\nConn: is this database connectable?",
      "fieldConfig":{
        "defaults":{"color":{"mode":"fixed"},"custom":{"align":"center","cellOptions":{"type":"auto"},"inspect":false},"mappings":[],"thresholds":{"mode":"absolute","steps":[{"color":"#346f36cc"}]}},
        "overrides":[
          {
            "matcher":{"id":"byName","options":"Database"},
            "properties":[
              { "id":"links"             ,"value":[]                                                                                                                                                              },{ "id":"mappings"          ,"value":[{"options":{"postgres":{"color":"#808080","index":2},"template0":{"color":"#c0c0c0e0","index":0},"template1":{"color":"#a8a8a8e0","index":1}},"type":"value"}] },
              { "id":"custom.cellOptions","value":{"type":"auto"}                                                                                                                                                 },{ "id":"color"             ,"value":{"fixedColor":"#3e668f","mode":"fixed"}                                                                                                                         },
              { "id":"links"             ,"value":[{"title":"PGSQL Database for ${ins}.${__data.fields.Database}","url":"/d/pgsql-database?var-ins=${ins}&var-datname=${__data.fields.Database}"}]                },{ "id":"custom.cellOptions","value":{"type":"color-text"}                                                                                                                                           }
            ]
          },{
            "matcher":{"id":"byName","options":"Size"},
            "properties":[
              { "id":"custom.width"      ,"value":75                                                                                                                                                                                                        },
              { "id":"unit"              ,"value":"decbytes"                                                                                                                                                                                                },
              { "id":"thresholds"        ,"value":{"mode":"absolute","steps":[{"color":"red"},{"color":"#3e668f","value":0},{"color":"#346f36cc","value":1000000000},{"color":"#fcdb72","value":1000000000000},{"color":"#f79f64","value":10000000000000}]} },
              { "id":"custom.cellOptions","value":{"mode":"basic","type":"color-background"}                                                                                                                                                                },
              { "id":"color"             ,"value":{"mode":"thresholds"}                                                                                                                                                                                     }
            ]
          },{
            "matcher":{"id":"byName","options":"Age"},
            "properties":[
              { "id":"thresholds"        ,"value":{"mode":"absolute","steps":[{"color":"#3e668f"},{"color":"#346f36cc","value":60000000},{"color":"#EAB839","value":200000000},{"color":"#f79f64","value":600000000},{"color":"red","value":1000000000},{"color":"#b783af","value":2000000000},{"color":"text","value":2137483647}]} },
              { "id":"custom.cellOptions","value":{"mode":"basic","type":"color-background"}                                                                                                                                                                                                                                         },
              { "id":"unit"              ,"value":"short"                                                                                                                                                                                                                                                                            },
              { "id":"custom.width"      ,"value":80                                                                                                                                                                                                                                                                                 },
              { "id":"color"             ,"value":{"mode":"thresholds"}                                                                                                                                                                                                                                                              },
              { "id":"decimals"          ,"value":2                                                                                                                                                                                                                                                                                  }
            ]
          },{
            "matcher":{"id":"byName","options":"Status"},
            "properties":[
              { "id":"custom.width"      ,"value":100                                                                                                                                                                                                                                                                                                                                              },
              { "id":"mappings"          ,"value":[{"options":{"0":{"color":"#f79f64","index":1,"text":"Template0"},"1":{"color":"red","index":2,"text":"RejectConn"},"2":{"color":"#3e668f","index":3,"text":"Template"},"3":{"color":"#346f36cc","index":4,"text":"Normal"}},"type":"value"},{"options":{"match":"null+nan","result":{"color":"gray","index":0,"text":"N/A"}},"type":"special"}] },
              { "id":"custom.cellOptions","value":{"mode":"basic","type":"color-background"}                                                                                                                                                                                                                                                                                                       }
            ]
          },{
            "matcher":{"id":"byName","options":"ConnLimit"},
            "properties":[
              { "id":"custom.width"      ,"value":85                                                                                                                                                                                                                                                                                },
              { "id":"custom.cellOptions","value":{"mode":"gradient","type":"color-background"}                                                                                                                                                                                                                                     },
              { "id":"color"                                                                                                                                                                                                                                                                                                        },
              { "id":"mappings"          ,"value":[{"options":{"-1":{"color":"#3e668f","index":1,"text":"NO LIMIT"}},"type":"value"},{"options":{"match":"null+nan","result":{"color":"gray","index":0,"text":"N/A"}},"type":"special"},{"options":{"from":0,"result":{"color":"#f79f64","index":2},"to":99999999},"type":"range"}] }
            ]
          },
          {"matcher":{"id":"byName","options":"Collate"},"properties":[{"id":"custom.width","value":65}]},{"matcher":{"id":"byName","options":"Encoding"},"properties":[{"id":"custom.width","value":75}]},
          {
            "matcher":{"id":"byName","options":"Owner"},
            "properties":[
              { "id":"custom.align"      ,"value":"center"                                                                                                                                                                                                                                                              },
              { "id":"custom.cellOptions","value":{"type":"color-text"}                                                                                                                                                                                                                                                 },
              { "id":"color"             ,"value":{"fixedColor":"#999999","mode":"fixed"}                                                                                                                                                                                                                               },
              { "id":"mappings"          ,"value":[{"options":{"dbuser_dba":{"color":"light-blue","index":1,"text":"dbuser_dba"},"postgres":{"color":"#3e668f","index":0,"text":"postgres"}},"type":"value"},{"options":{"pattern":"(dbuser_.*)","result":{"color":"#346f36cc","index":2,"text":"$1"}},"type":"regex"}] }
            ]
          },
          {"matcher":{"id":"byName","options":"Tablespace"},"properties":[{"id":"custom.width","value":90}]},{"matcher":{"id":"byName","options":"Privileges"},"properties":[{"id":"custom.cellOptions","value":{"type":"json-view"}}]},
          {"matcher":{"id":"byName","options":"AllowConn"},"properties":[{"id":"custom.cellOptions","value":{"mode":"basic","type":"color-background"}},{"id":"mappings","value":[{"options":{"false":{"color":"#f79f64","index":1,"text":"N"},"true":{"color":"#346f36cc","index":0,"text":"Y"}},"type":"value"}]},{"id":"custom.width","value":90}]},
          {
            "matcher":{"id":"byName","options":"OID"},
            "properties":[
              { "id":"custom.width"      ,"value":80                                                                                                                                 },{ "id":"custom.cellOptions","value":{"type":"color-text"}                                                                                                              },
              { "id":"color"             ,"value":{"fixedColor":"#3e668f","mode":"fixed"}                                                                                            },{ "id":"links"             ,"value":[{"title":"PGCAT Database : ${ins}.${__data.fields.Database}","url":"/d/pgcat-database?var-dsn=${ins}.${__data.fields.Database}"}] },
              { "id":"mappings"          ,"value":[{"options":{"from":0,"result":{"color":"#bfbfbf33","index":0},"to":10},"type":"range"}]                                           }
            ]
          },
          {"matcher":{"id":"byName","options":"IsTemplate"},"properties":[{"id":"custom.width","value":90},{"id":"custom.cellOptions","value":{"mode":"gradient","type":"color-background"}},{"id":"mappings","value":[{"options":{"false":{"color":"#3e668f","index":0,"text":"F"},"true":{"color":"#f79f64","index":1,"text":"T"}},"type":"value"}]}]}
        ]
      },
      "gridPos":{"h":6,"w":10,"x":14,"y":1},
      "id":164,
      "options":{"cellHeight":"sm","footer":{"countRows":false,"fields":"","reducer":["sum"],"show":false},"showHeader":true,"sortBy":[{"desc":true,"displayName":"OID"}]},
      "pluginVersion":"12.0.0",
      "targets":[
        {
          "datasource":{"type":"postgres","uid":"cc8a3615-9c82-44d7-be42-07d8aa1cac68"},
          "editorMode":"code",
          "format":"table",
          "group":[],
          "metricColumn":"none",
          "rawQuery":true,
          "rawSql":"SELECT d.datname, d.oid::INTEGER, d.datconnlimit, d.datfrozenxid, age(d.datfrozenxid) AS age, datistemplate,datallowconn,  1 - (datistemplate)::INTEGER + 2 * d.datallowconn::INTEGER AS status, psd.numbackends AS sessions,\n       pg_catalog.pg_get_userbyid(d.datdba) as owner, pg_catalog.pg_encoding_to_char(d.encoding) as encoding,\n       d.datcollate, d.datctype,  pg_catalog.array_to_string(d.datacl, E'\\n') AS acl,\n       CASE WHEN pg_catalog.has_database_privilege(d.datname, 'CONNECT') THEN pg_catalog.pg_database_size(d.datname) ELSE -1 END AS size,\n       t.spcname as tablespace,\n       pg_catalog.shobj_description(d.oid, 'pg_database') as description\nFROM pg_catalog.pg_database d JOIN pg_catalog.pg_tablespace t on d.dattablespace = t.oid JOIN pg_stat_database psd on d.oid = psd.datid\nORDER BY 1;",
          "refId":"A",
          "select":[[{"params":["value"],"type":"column"}]],
          "sql":{"columns":[{"parameters":[],"type":"function"}],"groupBy":[{"property":{"type":"string"},"type":"groupBy"}],"limit":50},
          "timeColumn":"time",
          "where":[{"name":"$__timeFilter","params":[],"type":"macro"}]
        }
      ],
      "title":"",
      "transformations":[
        {"id":"seriesToColumns","options":{"byField":"datname"}},
        {
          "id":"organize",
          "options":{
            "excludeByName":{"Time 1":true,"Time 10":true,"Time 2":true,"Time 3":true,"Time 4":true,"Time 5":true,"Time 6":true,"Time 7":true,"Time 8":true,"Time 9":true,"acl":true,"age":true,"datallowconn":false,"datcollate":true,"datconnlimit":true,"datctype":true,"datfrozenxid":true,"description":true,"encoding":true,"sessions":true,"size":true,"status":true,"tablespace":true},
            "indexByName":{"acl":14,"age":5,"datallowconn":4,"datcollate":10,"datconnlimit":8,"datctype":11,"datfrozenxid":12,"datistemplate":3,"datname":0,"description":15,"encoding":9,"oid":1,"owner":2,"sessions":7,"size":6,"status":16,"tablespace":13},
            "renameByName":{
              "Time 1":"",
              "Time 7":"",
              "Value #A":"Size",
              "Value #B":"Age",
              "Value #C":"Status",
              "Value #D":"Session",
              "Value #E":"TPS",
              "Value #F":"ConnLimit",
              "Value #G":"Reserve",
              "Value #H":"Current",
              "Value #I":"Disable",
              "Value #J":"Pause",
              "acl":"Privileges",
              "age":"Age",
              "datallowconn":"AllowConn",
              "datcollate":"Collate",
              "datconnlimit":"ConnLimit",
              "datctype":"Ctype",
              "datfrozenxid":"FronzenXID",
              "datistemplate":"IsTemplate",
              "datname":"Database",
              "description":"Description",
              "encoding":"Encoding",
              "host":"Target",
              "oid":"OID",
              "owner":"Owner",
              "real_datname":"Datname",
              "sessions":"Session",
              "size":"Size",
              "status":"Status",
              "tablespace":"Tablespace"
            }
          }
        }
      ],
      "type":"table"
    },
    {"collapsed":false,"gridPos":{"h":1,"w":24,"x":0,"y":7},"id":217,"panels":[],"title":"Locks","type":"row"},
    {
      "datasource":{"type":"postgres","uid":"${dsn}"},
      "description":"Block by : Which pid are blocked by this PID ?\n\nBlock N: how many process are blocked by this process?",
      "fieldConfig":{
        "defaults":{
          "custom":{"align":"center","cellOptions":{"type":"auto"},"filterable":false,"inspect":false},
          "mappings":[],
          "thresholds":{
            "mode":"absolute",
            "steps":[{"color":"#346f36cc"},{"color":"super-light-green","value":0.0001},{"color":"#346f36cc","value":0.01},{"color":"light-yellow","value":0.1},{"color":"#fcdb72","value":1},{"color":"super-light-orange","value":10},{"color":"#f79f64","value":60},{"color":"super-light-red","value":600},{"color":"red","value":1800},{"color":"super-light-purple","value":3600},{"color":"#b783af","value":7200}]
          }
        },
        "overrides":[
          {
            "matcher":{"id":"byName","options":"Database"},
            "properties":[
              { "id":"custom.width"      ,"value":130                                                                                                                                                                                                                                                      },
              { "id":"mappings"          ,"value":[{"options":{"postgres":{"color":"#f79f64","index":0},"template0":{"color":"#808080e0","index":1},"template1":{"color":"#787878e0","index":2}},"type":"value"},{"options":{"match":"null","result":{"color":"transparent","index":3}},"type":"special"}] },
              { "id":"custom.cellOptions","value":{"mode":"gradient","type":"color-background"}                                                                                                                                                                                                            },
              { "id":"links"             ,"value":[{"title":"PGCAT Database : ${dsn:text}","url":"/d/pgcat-database?var-dsn=${dsn:text}"}]                                                                                                                                                                 },
              { "id":"color"             ,"value":{"fixedColor":"#3e668f","mode":"fixed"}                                                                                                                                                                                                                  },
              { "id":"custom.filterable" ,"value":true                                                                                                                                                                                                                                                     }
            ]
          },{
            "matcher":{"id":"byName","options":"User"},
            "properties":[
              {"id":"custom.width","value":120},
              {
                "id":"mappings",
                "value":[
                  { "options":{"dbuser_dba":{"color":"#cc4637d9","index":1},"dbuser_monitor":{"color":"#f79f64","index":3},"postgres":{"color":"#b783af","index":0},"replicator":{"color":"#fcdb72","index":2}},"type":"value"   },
                  { "options":{"pattern":"dbrole.*","result":{"color":"#3e668f","index":4}}                                                                                                                    ,"type":"regex"   },
                  { "options":{"pattern":"dbuser.*","result":{"color":"#346f36cc","index":5}}                                                                                                                  ,"type":"regex"   },
                  { "options":{"match":"null","result":{"color":"transparent","index":6}}                                                                                                                      ,"type":"special" }
                ]
              },
              {"id":"custom.cellOptions","value":{"mode":"gradient","type":"color-background"}},{"id":"color","value":{"fixedColor":"#3e668f","mode":"fixed"}},{"id":"custom.filterable","value":true}
            ]
          },{
            "matcher":{"id":"byName","options":"App"},
            "properties":[
              {"id":"custom.width","value":220},
              {
                "id":"mappings",
                "value":[
                  { "options":{"Patroni":{"color":"#fcdb72","index":0},"Postgres JDBC Driver":{"color":"#b783af","index":2},"pg_exporter":{"color":"#f79f64","index":3},"psql":{"color":"#cc4637d9","index":1}},"type":"value"   },
                  { "options":{"pattern":"pgbench.*","result":{"color":"#5b9cd5","index":4}}                                                                                                                   ,"type":"regex"   },
                  { "options":{"pattern":"(citus|Timescale|Citus).*","result":{"color":"#7771a4","index":5}}                                                                                                   ,"type":"regex"   },
                  { "options":{"match":"null","result":{"color":"transparent","index":6}}                                                                                                                      ,"type":"special" },
                  { "options":{"match":"empty","result":{"color":"transparent","index":7}}                                                                                                                     ,"type":"special" }
                ]
              },
              {"id":"custom.cellOptions","value":{"type":"color-background"}},{"id":"color","value":{"fixedColor":"#3e668f","mode":"fixed"}},{"id":"custom.filterable","value":true}
            ]
          },{
            "matcher":{"id":"byName","options":"IP"},
            "properties":[
              { "id":"custom.width"      ,"value":120                                                                                                                                                               },{ "id":"mappings"          ,"value":[{"options":{"127.0.0.1":{"color":"#8b8b8b","index":1}},"type":"value"},{"options":{"match":"null","result":{"color":"transparent","index":0}},"type":"special"}] },
              { "id":"custom.cellOptions","value":{"type":"auto"}                                                                                                                                                   },{ "id":"color"             ,"value":{"fixedColor":"#3e668f","mode":"fixed"}                                                                                                                           },
              { "id":"links"             ,"value":[{"title":"Node Instance : ${__data.fields.IP}","url":"/d/node-instance?var-ip=${__data.fields.IP}&${__url_time_range}"}]                                         },{ "id":"custom.filterable" ,"value":true                                                                                                                                                              }
            ]
          },{
            "matcher":{"id":"byName","options":"Port"},
            "properties":[{"id":"custom.width","value":66},{"id":"mappings","value":[{"options":{"-1":{"color":"#808080e0","index":1,"text":"Socket"}},"type":"value"},{"options":{"match":"null","result":{"color":"transparent","index":0}},"type":"special"}]},{"id":"custom.cellOptions","value":{"type":"color-text"}},{"id":"color","value":{"fixedColor":"#3e668f","mode":"fixed"}}]
          },{
            "matcher":{"id":"byName","options":"Type"},
            "properties":[
              {"id":"custom.width","value":160},
              {
                "id":"mappings",
                "value":[
                  {
                    "options":{
                      " autovacuum worker"          :{ "color":"#346f36cc","index":12,"text":"Vacuum Worker"    },
                      "archiver"                    :{ "color":"#cc4637d9","index": 5,"text":"Archiver"         },
                      "autovacuum launcher"         :{ "color":"#346f36cc","index":11,"text":"Vacuum Main"      },
                      "background writer"           :{ "color":"#cc4637d9","index": 4,"text":"BGWriter"         },
                      "checkpointer"                :{ "color":"#cc4637d9","index": 3,"text":"Checkpointer"     },
                      "client backend"              :{ "color":"#3e668f"  ,"index": 0,"text":"Client"           },
                      "logical replication launcher":{ "color":"#f79f64"  ,"index": 9,"text":"Logical Launcher" },
                      "logical replication worker"  :{ "color":"#f79f64"  ,"index":10,"text":"Logical Worker"   },
                      "parallel worker"             :{ "color":"#5b9cd5"  ,"index": 1,"text":"Worker"           },
                      "startup"                     :{ "color":"#fcdb72"  ,"index": 8,"text":"Startup"          },
                      "walreceiver"                 :{ "color":"#fcdb72"  ,"index": 7,"text":"WAL Receiver"     },
                      "walsender"                   :{ "color":"#fcdb72"  ,"index": 6,"text":"WAL Sender"       },
                      "walwriter"                   :{ "color":"#cc4637d9","index": 2,"text":"WAL Writer"       }
                    },
                    "type":"value"
                  },
                  {"options":{"pattern":"(Citus|TimescaleDB).*","result":{"color":"#7771a4","index":13}},"type":"regex"}
                ]
              },
              {"id":"thresholds","value":{"mode":"absolute","steps":[{"color":"#80808080"}]}},{"id":"custom.cellOptions","value":{"mode":"gradient","type":"color-background"}},{"id":"custom.filterable","value":true}
            ]
          },{
            "matcher":{"id":"byName","options":"State"},
            "properties":[
              {"id":"custom.width","value":150},
              {
                "id":"mappings",
                "value":[
                  { "options":{"active":{"color":"#346f36cc","index":0},"disabled":{"color":"#7f7f7fe0","index":6},"fastpath function call":{"color":"#fcdb72","index":5},"idle":{"color":"#3d668f33","index":1},"idle in transaction":{"color":"#cc4637d9","index":3},"idle in transaction (aborted)":{"color":"#b783af","index":4},"waiting":{"color":"#f79f64","index":2}},"type":"value"   },
                  { "options":{"match":"null","result":{"color":"transparent","index":7}}                                                                                                                                                                                                                                                                                    ,"type":"special" }
                ]
              },
              {"id":"custom.cellOptions","value":{"mode":"gradient","type":"color-background"}},{"id":"custom.filterable","value":true}
            ]
          },{
            "matcher":{"id":"byName","options":"Wait"},
            "properties":[
              {"id":"custom.width","value":80},
              {
                "id":"mappings",
                "value":[
                  { "options":{"Activity":{"color":"#346f36cc","index":0},"BufferPin":{"color":"#f79f64","index":4},"Client":{"color":"#3e668f","index":1},"Extension":{"color":"#7771a4","index":8},"IO":{"color":"#f7cb67","index":3},"IPC":{"color":"#5b9cd5","index":2},"LWLock":{"color":"#cc4637d9","index":6},"Lock":{"color":"red","index":5},"Timeout":{"color":"#7f7f7f9e","index":7}},"type":"value"   },
                  { "options":{"match":"null","result":{"color":"super-light-green","index":9,"text":"Running"}}                                                                                                                                                                                                                                                                                ,"type":"special" }
                ]
              },
              {"id":"custom.cellOptions","value":{"mode":"gradient","type":"color-background"}}
            ]
          },
          {"matcher":{"id":"byName","options":"Event"},"properties":[{"id":"custom.width","value":180},{"id":"custom.cellOptions","value":{"type":"auto"}},{"id":"thresholds","value":{"mode":"absolute","steps":[{"color":"#e3e3e3e0"}]}}]},
          {"matcher":{"id":"byName","options":"PID"},"properties":[{"id":"custom.width","value":70},{"id":"color","value":{"fixedColor":"#3e668f","mode":"fixed"}},{"id":"custom.cellOptions","value":{"type":"color-background"}}]},
          {
            "matcher":{"id":"byName","options":"ConnTime"},
            "properties":[
              { "id":"custom.width"      ,"value":100                                                                                                                                                                                           },
              { "id":"unit"              ,"value":"s"                                                                                                                                                                                           },
              { "id":"custom.cellOptions","value":{"type":"color-background"}                                                                                                                                                                   },
              { "id":"mappings"          ,"value":[{"options":{"match":"null","result":{"color":"transparent","index":0}},"type":"special"}]                                                                                                    },
              { "id":"thresholds"        ,"value":{"mode":"absolute","steps":[{"color":"#3e668f"},{"color":"#346f36cc","value":60},{"color":"#fcdb72","value":3600},{"color":"#cc4637d9","value":86400},{"color":"#f79f64","value":183131175}]} }
            ]
          },{
            "matcher":{"id":"byName","options":"Xact Wait"},
            "properties":[
              { "id":"custom.width"      ,"value":100                                                                                                                                                                                                                                               },
              { "id":"unit"              ,"value":"s"                                                                                                                                                                                                                                               },
              { "id":"custom.cellOptions","value":{"mode":"gradient","type":"color-background"}                                                                                                                                                                                                     },
              { "id":"mappings"          ,"value":[{"options":{"match":"null","result":{"color":"transparent","index":0}},"type":"special"}]                                                                                                                                                        },
              { "id":"thresholds"        ,"value":{"mode":"absolute","steps":[{"color":"#3e668f"},{"color":"#346f36cc","value":0.001},{"color":"#fcdb72","value":0.01},{"color":"#f79f64","value":0.1},{"color":"#cc4637d9","value":1},{"color":"#b783af","value":10},{"color":"text","value":60}]} },
              { "id":"color"                                                                                                                                                                                                                                                                        }
            ]
          },{
            "matcher":{"id":"byName","options":"Lock Wait"},
            "properties":[
              { "id":"custom.width"      ,"value":100                                                                                                                                                                                                                                               },
              { "id":"unit"              ,"value":"s"                                                                                                                                                                                                                                               },
              { "id":"custom.cellOptions","value":{"type":"color-text"}                                                                                                                                                                                                                             },
              { "id":"mappings"          ,"value":[{"options":{"match":"null","result":{"color":"transparent","index":0}},"type":"special"}]                                                                                                                                                        },
              { "id":"thresholds"        ,"value":{"mode":"absolute","steps":[{"color":"#3e668f"},{"color":"#346f36cc","value":0.001},{"color":"#fcdb72","value":0.01},{"color":"#f79f64","value":0.1},{"color":"#cc4637d9","value":1},{"color":"#b783af","value":10},{"color":"text","value":60}]} },
              { "id":"custom.cellOptions","value":{"type":"color-background"}                                                                                                                                                                                                                       }
            ]
          },{
            "matcher":{"id":"byName","options":"StateTime"},
            "properties":[
              { "id":"custom.width"      ,"value":100                                                                                                                                                                                                                 },
              { "id":"unit"              ,"value":"s"                                                                                                                                                                                                                 },
              { "id":"custom.cellOptions","value":{"type":"color-text"}                                                                                                                                                                                               },
              { "id":"mappings"          ,"value":[{"options":{"match":"null","result":{"color":"transparent","index":0}},"type":"special"}]                                                                                                                          },
              { "id":"thresholds"        ,"value":{"mode":"absolute","steps":[{"color":"#3e668f"},{"color":"#346f36cc","value":1},{"color":"#fcdb72","value":10},{"color":"#f79f64","value":60},{"color":"#cc4637d9","value":600},{"color":"#b783af","value":86400}]} }
            ]
          },
          {"matcher":{"id":"byName","options":"Query"},"properties":[{"id":"custom.width","value":200},{"id":"custom.cellOptions","value":{"type":"auto"}},{"id":"links","value":[{"title":"${__data.fields.SQL}","url":"/d/pgcat-query?var-dsn=${dsn:text}&var-query=${__data.fields.Query}"}]},{"id":"unit","value":"string"}]},
          {"matcher":{"id":"byName","options":"SQL"},"properties":[{"id":"custom.inspect","value":true},{"id":"custom.minWidth","value":500},{"id":"custom.align","value":"left"}]},{"matcher":{"id":"byName","options":"Start"},"properties":[{"id":"custom.width","value":200},{"id":"color","value":{"fixedColor":"#3e668f","mode":"fixed"}},{"id":"custom.cellOptions","value":{"type":"color-text"}}]},
          {"matcher":{"id":"byRegexp","options":"/XID|XMIN|LeaderPID|UID|DBID/"},"properties":[{"id":"custom.width","value":80},{"id":"color","value":{"fixedColor":"#3e668f","mode":"fixed"}},{"id":"custom.cellOptions","value":{"type":"color-text"}}]},{"matcher":{"id":"byRegexp","options":"/^(Type|State|Database|User|App|IP|Wait|Event)$/"},"properties":[{"id":"custom.filterable","value":true}]},
          {"matcher":{"id":"byName","options":"Block By"},"properties":[{"id":"mappings","value":[{"options":{"{}":{"color":"#346f36cc","index":0}},"type":"value"}]},{"id":"custom.cellOptions","value":{"type":"color-background"}},{"id":"thresholds","value":{"mode":"absolute","steps":[{"color":"#f79f64"}]}},{"id":"custom.width","value":110}]},
          {"matcher":{"id":"byName","options":"Level"},"properties":[{"id":"custom.width","value":60},{"id":"thresholds","value":{"mode":"absolute","steps":[{"color":"#346f36cc"},{"color":"#f79f64","value":1},{"color":"#cc4637d9","value":2},{"color":"#b783af","value":3},{"color":"#7771a4","value":4},{"color":"text","value":5}]}},{"id":"custom.cellOptions","value":{"type":"color-background"}}]},
          {"matcher":{"id":"byName","options":"Block N"},"properties":[{"id":"custom.width","value":70},{"id":"thresholds","value":{"mode":"absolute","steps":[{"color":"#346f36cc"},{"color":"#f79f64","value":1},{"color":"#cc4637d9","value":2}]}},{"id":"custom.cellOptions","value":{"type":"color-background"}}]},{"matcher":{"id":"byName","options":"XMin"},"properties":[{"id":"custom.width","value":110}]},
          {
            "matcher":{"id":"byName","options":"XID Age"},
            "properties":[{"id":"custom.width","value":80},{"id":"thresholds","value":{"mode":"absolute","steps":[{"color":"#3e668f"},{"color":"#346f36cc","value":8},{"color":"#f79f64","value":32},{"color":"#EAB839","value":32},{"color":"#cc4637d9","value":128},{"color":"#7771a4","value":1000000000},{"color":"text","value":2000000000}]}},{"id":"custom.cellOptions","value":{"type":"color-background"}},{"id":"color"}]
          }
        ]
      },
      "gridPos":{"h":10,"w":24,"x":0,"y":8},
      "id":218,
      "links":[{"title":"PGCAT Instance : ${dsn:text}","url":"/d/pgcat-instance?var-dsn=${dsn:text}&viewPanel=179"}],
      "options":{"cellHeight":"sm","footer":{"countRows":false,"fields":"","reducer":["sum"],"show":false},"showHeader":true,"sortBy":[]},
      "pluginVersion":"12.0.0",
      "targets":[
        {
          "datasource":{"type":"postgres","uid":"${dsn}"},
          "editorMode":"code",
          "format":"table",
          "group":[],
          "metricColumn":"none",
          "rawQuery":true,
          "rawSql":"with recursive\n    activity as (select pg_blocking_pids(pid) blocked_by, *,\n                        extract(seconds FROM age(clock_timestamp(), xact_start)) as xact_wait,\n                        extract(seconds FROM age(clock_timestamp(),\n                            -- (select max(l.waitstart) from pg_locks l where a.pid = l.pid)    -- PG 14 and newer\n                             state_change       -- PG 13 and below\n                            )) as lock_wait\n                 from pg_stat_activity a\n                 where state is distinct from 'idle'),\n    blockers as (select array_agg(distinct c order by c) as pids\n                 from (select unnest(blocked_by)\n                       from activity) as dt(c)),\n    tree as (select activity.*,\n                    1                           as level,\n                    activity.pid                as top_blocker_pid,\n                    array [activity.pid]        as path,\n                    array [activity.pid]::int[] as all_blockers_above\n             from activity, blockers\n             where array [pid] <@ blockers.pids and blocked_by = '{}'::int[]\n             union all\n             select activity.*,\n                    tree.level + 1 as level,\n                    tree.top_blocker_pid,\n                    path || array [activity.pid] as path,\n                    tree.all_blockers_above || array_agg(activity.pid) over () as all_blockers_above\n             from activity,\n                  tree\n             where not array [activity.pid] <@ tree.all_blockers_above\n               and activity.blocked_by <> '{}'::int[]\n               and activity.blocked_by <@ tree.all_blockers_above)\nselect pid,\n       blocked_by,\n       case when wait_event_type = 'Lock' then 'waiting' else state end                                      as state,\n       wait_event_type,\n       wait_event,\n       xact_wait,\n       lock_wait,\n       age(backend_xid) AS xid_age,\n       -- 2147483647 - age(backend_xmin) as xmin_ttf,\n       datname, usename, level - 1 AS level,\n       (select count(distinct t1.pid) from tree t1 where array [tree.pid] <@ t1.path and t1.pid <> tree.pid) as blkd,\n       format('%s %s%s', lpad('[' || pid::text || ']', 9, ' '), repeat('.', level - 1) || case when level > 1 then ' ' end, left(query, 1000) ) as query\nfrom tree\nWHERE datname = CURRENT_DATABASE()\norder by top_blocker_pid, level, pid;",
          "refId":"A",
          "select":[[{"params":["value"],"type":"column"}]],
          "sql":{"columns":[{"parameters":[],"type":"function"}],"groupBy":[{"property":{"type":"string"},"type":"groupBy"}],"limit":50},
          "timeColumn":"time",
          "where":[{"name":"$__timeFilter","params":[],"type":"macro"}]
        }
      ],
      "title":"Locks for ${datname}",
      "transformations":[
        {
          "id":"organize",
          "options":{
            "excludeByName":{"backend_start":false,"backend_xid":false,"backend_xmin":false,"client_hostname":true,"datid":false,"leader_pid":false,"query_id":true,"query_start":true,"state_change":true,"usesysid":false,"xact_start":true},
            "indexByName":{"blkd":5,"blocked_by":4,"datname":0,"level":8,"lock_wait":9,"pid":3,"query":10,"state":2,"usename":1,"wait_event":7,"wait_event_type":6,"xact_wait":11,"xid_age":12,"xmin_ttf":13},
            "renameByName":{
              "application_name":"App",
              "backend_start":"Start",
              "backend_type":"Type",
              "backend_xid":"XID",
              "backend_xmin":"XMIN",
              "blkd":"Block N",
              "blocked_by":"Block By",
              "blocking_pids":"Blocking PIDs",
              "client_addr":"IP",
              "client_hostname":"ClientHostname",
              "client_port":"Port",
              "conn_time":"ConnTime",
              "datid":"DBID",
              "datname":"Database",
              "leader_pid":"LeaderPID",
              "level":"Level",
              "lock_wait":"Lock Wait",
              "pid":"PID",
              "qid":"Query",
              "query":"SQL",
              "query_id":"QueryID",
              "query_start":"Query Start",
              "query_time":"QueryTime",
              "state":"State",
              "state_change":"Stage Change",
              "state_time":"StateTime",
              "usename":"User",
              "usesysid":"UID",
              "wait_event":"Event",
              "wait_event_type":"Wait",
              "xact_start":"Xact Start",
              "xact_time":"XactTime",
              "xact_wait":"Xact Wait",
              "xid_age":"XID Age",
              "xmin_ttf":"XMin"
            }
          }
        }
      ],
      "type":"table"
    },
    {"collapsed":false,"gridPos":{"h":1,"w":24,"x":0,"y":18},"id":196,"panels":[],"title":"Activity","type":"row"},
    {
      "datasource":{"type":"grafana-postgresql-datasource","uid":"${dsn}"},
      "fieldConfig":{
        "defaults":{
          "custom":{"align":"center","cellOptions":{"type":"auto"},"filterable":false,"inspect":false},
          "mappings":[],
          "thresholds":{
            "mode":"absolute",
            "steps":[{"color":"#346f36cc"},{"color":"super-light-green","value":0.0001},{"color":"#346f36cc","value":0.01},{"color":"light-yellow","value":0.1},{"color":"#fcdb72","value":1},{"color":"super-light-orange","value":10},{"color":"#f79f64","value":60},{"color":"super-light-red","value":600},{"color":"red","value":1800},{"color":"super-light-purple","value":3600},{"color":"#b783af","value":7200}]
          }
        },
        "overrides":[
          {
            "matcher":{"id":"byName","options":"Database"},
            "properties":[
              { "id":"custom.width"      ,"value":130                                                                                                                                                                                                                                                      },
              { "id":"mappings"          ,"value":[{"options":{"postgres":{"color":"#f79f64","index":0},"template0":{"color":"#808080e0","index":1},"template1":{"color":"#787878e0","index":2}},"type":"value"},{"options":{"match":"null","result":{"color":"transparent","index":3}},"type":"special"}] },
              { "id":"custom.cellOptions","value":{"mode":"gradient","type":"color-background"}                                                                                                                                                                                                            },
              { "id":"links"             ,"value":[{"title":"PGCAT Database : ${dsn:text}","url":"/d/pgcat-database?var-dsn=${dsn:text}"}]                                                                                                                                                                 },
              { "id":"color"             ,"value":{"fixedColor":"#3e668f","mode":"fixed"}                                                                                                                                                                                                                  },
              { "id":"custom.filterable" ,"value":true                                                                                                                                                                                                                                                     }
            ]
          },{
            "matcher":{"id":"byName","options":"User"},
            "properties":[
              {"id":"custom.width","value":120},
              {
                "id":"mappings",
                "value":[
                  { "options":{"dbuser_dba":{"color":"#cc4637d9","index":1},"dbuser_monitor":{"color":"#f79f64","index":3},"postgres":{"color":"#b783af","index":0},"replicator":{"color":"#fcdb72","index":2}},"type":"value"   },
                  { "options":{"pattern":"dbrole.*","result":{"color":"#3e668f","index":4}}                                                                                                                    ,"type":"regex"   },
                  { "options":{"pattern":"dbuser.*","result":{"color":"#346f36cc","index":5}}                                                                                                                  ,"type":"regex"   },
                  { "options":{"match":"null","result":{"color":"transparent","index":6}}                                                                                                                      ,"type":"special" }
                ]
              },
              {"id":"custom.cellOptions","value":{"mode":"gradient","type":"color-background"}},{"id":"color","value":{"fixedColor":"#3e668f","mode":"fixed"}},{"id":"custom.filterable","value":true}
            ]
          },{
            "matcher":{"id":"byName","options":"App"},
            "properties":[
              {"id":"custom.width","value":220},
              {
                "id":"mappings",
                "value":[
                  { "options":{"Patroni":{"color":"#fcdb72","index":0},"Postgres JDBC Driver":{"color":"#b783af","index":2},"pg_exporter":{"color":"#f79f64","index":3},"psql":{"color":"#cc4637d9","index":1}},"type":"value"   },
                  { "options":{"pattern":"pgbench.*","result":{"color":"#5b9cd5","index":4}}                                                                                                                   ,"type":"regex"   },
                  { "options":{"pattern":"(citus|Timescale|Citus).*","result":{"color":"#7771a4","index":5}}                                                                                                   ,"type":"regex"   },
                  { "options":{"match":"null","result":{"color":"transparent","index":6}}                                                                                                                      ,"type":"special" },
                  { "options":{"match":"empty","result":{"color":"transparent","index":7}}                                                                                                                     ,"type":"special" }
                ]
              },
              {"id":"custom.cellOptions","value":{"type":"color-background"}},{"id":"color","value":{"fixedColor":"#3e668f","mode":"fixed"}},{"id":"custom.filterable","value":true}
            ]
          },{
            "matcher":{"id":"byName","options":"IP"},
            "properties":[
              { "id":"custom.width"      ,"value":120                                                                                                                                                               },{ "id":"mappings"          ,"value":[{"options":{"127.0.0.1":{"color":"#8b8b8b","index":1}},"type":"value"},{"options":{"match":"null","result":{"color":"transparent","index":0}},"type":"special"}] },
              { "id":"custom.cellOptions","value":{"type":"auto"}                                                                                                                                                   },{ "id":"color"             ,"value":{"fixedColor":"#3e668f","mode":"fixed"}                                                                                                                           },
              { "id":"links"             ,"value":[{"title":"Node Instance : ${__data.fields.IP}","url":"/d/node-instance?var-ip=${__data.fields.IP}&${__url_time_range}"}]                                         },{ "id":"custom.filterable" ,"value":true                                                                                                                                                              }
            ]
          },{
            "matcher":{"id":"byName","options":"Port"},
            "properties":[{"id":"custom.width","value":66},{"id":"mappings","value":[{"options":{"-1":{"color":"#808080e0","index":1,"text":"Socket"}},"type":"value"},{"options":{"match":"null","result":{"color":"transparent","index":0}},"type":"special"}]},{"id":"custom.cellOptions","value":{"type":"color-text"}},{"id":"color","value":{"fixedColor":"#3e668f","mode":"fixed"}}]
          },{
            "matcher":{"id":"byName","options":"Type"},
            "properties":[
              {"id":"custom.width","value":160},
              {
                "id":"mappings",
                "value":[
                  {
                    "options":{
                      " autovacuum worker"          :{ "color":"#346f36cc","index":12,"text":"Vacuum Worker"    },
                      "archiver"                    :{ "color":"#cc4637d9","index": 5,"text":"Archiver"         },
                      "autovacuum launcher"         :{ "color":"#346f36cc","index":11,"text":"Vacuum Main"      },
                      "background writer"           :{ "color":"#cc4637d9","index": 4,"text":"BGWriter"         },
                      "checkpointer"                :{ "color":"#cc4637d9","index": 3,"text":"Checkpointer"     },
                      "client backend"              :{ "color":"#3e668f"  ,"index": 0,"text":"Client"           },
                      "logical replication launcher":{ "color":"#f79f64"  ,"index": 9,"text":"Logical Launcher" },
                      "logical replication worker"  :{ "color":"#f79f64"  ,"index":10,"text":"Logical Worker"   },
                      "parallel worker"             :{ "color":"#5b9cd5"  ,"index": 1,"text":"Worker"           },
                      "startup"                     :{ "color":"#fcdb72"  ,"index": 8,"text":"Startup"          },
                      "walreceiver"                 :{ "color":"#fcdb72"  ,"index": 7,"text":"WAL Receiver"     },
                      "walsender"                   :{ "color":"#fcdb72"  ,"index": 6,"text":"WAL Sender"       },
                      "walwriter"                   :{ "color":"#cc4637d9","index": 2,"text":"WAL Writer"       }
                    },
                    "type":"value"
                  },
                  {"options":{"pattern":"(Citus|TimescaleDB).*","result":{"color":"#7771a4","index":13}},"type":"regex"}
                ]
              },
              {"id":"thresholds","value":{"mode":"absolute","steps":[{"color":"#80808080"}]}},{"id":"custom.cellOptions","value":{"mode":"gradient","type":"color-background"}},{"id":"custom.filterable","value":true}
            ]
          },{
            "matcher":{"id":"byName","options":"State"},
            "properties":[
              {"id":"custom.width","value":150},
              {
                "id":"mappings",
                "value":[
                  { "options":{"active":{"color":"#346f36cc","index":0},"disabled":{"color":"#7f7f7fe0","index":5},"fastpath function call":{"color":"#fcdb72","index":4},"idle":{"color":"#3d668f33","index":1},"idle in transaction":{"color":"#cc4637d9","index":2},"idle in transaction (aborted)":{"color":"#b783af","index":3}},"type":"value"   },
                  { "options":{"match":"null","result":{"color":"transparent","index":6}}                                                                                                                                                                                                                                            ,"type":"special" }
                ]
              },
              {"id":"custom.cellOptions","value":{"mode":"gradient","type":"color-background"}},{"id":"custom.filterable","value":true}
            ]
          },{
            "matcher":{"id":"byName","options":"Wait"},
            "properties":[
              {"id":"custom.width","value":80},
              {
                "id":"mappings",
                "value":[
                  { "options":{"BufferPin":{"color":"#f79f64","index":4},"Client":{"color":"#3e668f","index":1},"Extension":{"color":"#7771a4","index":8},"IO":{"color":"#f7cb67","index":3},"IPC":{"color":"#5b9cd5","index":2},"LWLock":{"color":"#cc4637d9","index":6},"Lock":{"color":"red","index":5},"Running":{"color":"#346f36cc","index":0},"Timeout":{"color":"#7f7f7f9e","index":7}},"type":"value"   },
                  { "options":{"match":"null","result":{"color":"super-light-green","index":9,"text":"Running"}}                                                                                                                                                                                                                                                                               ,"type":"special" }
                ]
              },
              {"id":"custom.cellOptions","value":{"mode":"gradient","type":"color-background"}}
            ]
          },
          {"matcher":{"id":"byName","options":"Event"},"properties":[{"id":"custom.width","value":180},{"id":"custom.cellOptions","value":{"type":"auto"}},{"id":"thresholds","value":{"mode":"absolute","steps":[{"color":"#e3e3e3e0"}]}}]},
          {"matcher":{"id":"byName","options":"PID"},"properties":[{"id":"custom.width","value":70},{"id":"color","value":{"fixedColor":"#3e668f","mode":"fixed"}},{"id":"custom.cellOptions","value":{"type":"color-background"}}]},
          {
            "matcher":{"id":"byName","options":"ConnTime"},
            "properties":[
              { "id":"custom.width"      ,"value":100                                                                                                                                                                                           },
              { "id":"unit"              ,"value":"s"                                                                                                                                                                                           },
              { "id":"custom.cellOptions","value":{"type":"color-background"}                                                                                                                                                                   },
              { "id":"mappings"          ,"value":[{"options":{"match":"null","result":{"color":"transparent","index":0}},"type":"special"}]                                                                                                    },
              { "id":"thresholds"        ,"value":{"mode":"absolute","steps":[{"color":"#3e668f"},{"color":"#346f36cc","value":60},{"color":"#fcdb72","value":3600},{"color":"#cc4637d9","value":86400},{"color":"#f79f64","value":183131175}]} }
            ]
          },{
            "matcher":{"id":"byName","options":"XactTime"},
            "properties":[
              { "id":"custom.width"      ,"value":100                                                                                                                                                                                                                 },
              { "id":"unit"              ,"value":"s"                                                                                                                                                                                                                 },
              { "id":"custom.cellOptions","value":{"mode":"gradient","type":"color-background"}                                                                                                                                                                       },
              { "id":"mappings"          ,"value":[{"options":{"match":"null","result":{"color":"transparent","index":0}},"type":"special"}]                                                                                                                          },
              { "id":"thresholds"        ,"value":{"mode":"absolute","steps":[{"color":"#3e668f"},{"color":"#346f36cc","value":1},{"color":"#fcdb72","value":10},{"color":"#f79f64","value":60},{"color":"#cc4637d9","value":600},{"color":"#b783af","value":86400}]} }
            ]
          },{
            "matcher":{"id":"byName","options":"QueryTime"},
            "properties":[
              { "id":"custom.width"      ,"value":100                                                                                                                                                                                                                 },
              { "id":"unit"              ,"value":"s"                                                                                                                                                                                                                 },
              { "id":"custom.cellOptions","value":{"type":"color-text"}                                                                                                                                                                                               },
              { "id":"mappings"          ,"value":[{"options":{"match":"null","result":{"color":"transparent","index":0}},"type":"special"}]                                                                                                                          },
              { "id":"thresholds"        ,"value":{"mode":"absolute","steps":[{"color":"#3e668f"},{"color":"#346f36cc","value":1},{"color":"#fcdb72","value":10},{"color":"#f79f64","value":60},{"color":"#cc4637d9","value":600},{"color":"#b783af","value":86400}]} }
            ]
          },{
            "matcher":{"id":"byName","options":"StateTime"},
            "properties":[
              { "id":"custom.width"      ,"value":100                                                                                                                                                                                                                 },
              { "id":"unit"              ,"value":"s"                                                                                                                                                                                                                 },
              { "id":"custom.cellOptions","value":{"type":"color-text"}                                                                                                                                                                                               },
              { "id":"mappings"          ,"value":[{"options":{"match":"null","result":{"color":"transparent","index":0}},"type":"special"}]                                                                                                                          },
              { "id":"thresholds"        ,"value":{"mode":"absolute","steps":[{"color":"#3e668f"},{"color":"#346f36cc","value":1},{"color":"#fcdb72","value":10},{"color":"#f79f64","value":60},{"color":"#cc4637d9","value":600},{"color":"#b783af","value":86400}]} }
            ]
          },
          {"matcher":{"id":"byName","options":"Query"},"properties":[{"id":"custom.width","value":200},{"id":"custom.cellOptions","value":{"type":"auto"}},{"id":"links","value":[{"title":"${__data.fields.SQL}","url":"/d/pgcat-query?var-dsn=${dsn:text}&var-query=${__data.fields.Query}"}]},{"id":"unit","value":"string"}]},
          {"matcher":{"id":"byName","options":"SQL"},"properties":[{"id":"custom.inspect","value":true},{"id":"custom.minWidth","value":240},{"id":"custom.align","value":"left"}]},{"matcher":{"id":"byName","options":"Start"},"properties":[{"id":"custom.width","value":200},{"id":"color","value":{"fixedColor":"#3e668f","mode":"fixed"}},{"id":"custom.cellOptions","value":{"type":"color-text"}}]},
          {"matcher":{"id":"byRegexp","options":"/XID|XMIN|LeaderPID|UID|DBID/"},"properties":[{"id":"custom.width","value":80},{"id":"color","value":{"fixedColor":"#3e668f","mode":"fixed"}},{"id":"custom.cellOptions","value":{"type":"color-text"}}]},{"matcher":{"id":"byRegexp","options":"/^(Type|State|Database|User|App|IP|Wait|Event)$/"},"properties":[{"id":"custom.filterable","value":true}]},
          {"matcher":{"id":"byName","options":"Blocking PIDs"},"properties":[{"id":"mappings","value":[{"options":{"{}":{"color":"transparent","index":0}},"type":"value"}]},{"id":"custom.cellOptions","value":{"type":"color-background"}},{"id":"thresholds","value":{"mode":"absolute","steps":[{"color":"#f79f64"}]}},{"id":"custom.width","value":110}]}
        ]
      },
      "gridPos":{"h":16,"w":24,"x":0,"y":19},
      "id":216,
      "links":[{"title":"PGCAT Instance : ${ins}","url":"/d/pgcat-instance?var-dsn=${dsn:text}&viewPanel=59"}],
      "options":{"cellHeight":"sm","footer":{"countRows":false,"fields":"","reducer":["sum"],"show":false},"showHeader":true,"sortBy":[{"desc":false,"displayName":"PID"}]},
      "pluginVersion":"12.0.0",
      "targets":[
        {
          "datasource":{"type":"postgres","uid":"${dsn}"},
          "editorMode":"code",
          "format":"table",
          "group":[],
          "metricColumn":"none",
          "rawQuery":true,
          "rawSql":"SELECT pg_blocking_pids(pid) AS blocking_pids,\n       datid,\n       datname,\n       pid,\n       leader_pid,\n       usesysid,\n       usename,\n       application_name,\n       client_addr,\n       client_hostname,\n       client_port,\n       extract(epoch from now() - backend_start) AS conn_time,\n       extract(epoch from now() - xact_start)    AS xact_time,\n       extract(epoch from now() - query_start)   AS query_time,\n       extract(epoch from now() - state_change)  AS state_time,\n       wait_event_type, wait_event,\n       state,\n       backend_xid,\n       backend_xmin,\n       query_id,\n       query,\n       backend_type,\n       query_id::TEXT AS qid -- 14 has query_id, comment this for PG 13 and below \nFROM pg_stat_activity\nWHERE datname = current_database()\nORDER BY state,wait_event_type;",
          "refId":"A",
          "select":[[{"params":["value"],"type":"column"}]],
          "sql":{"columns":[{"parameters":[],"type":"function"}],"groupBy":[{"property":{"type":"string"},"type":"groupBy"}],"limit":50},
          "timeColumn":"time",
          "where":[{"name":"$__timeFilter","params":[],"type":"macro"}]
        }
      ],
      "title":"Activity",
      "transformations":[
        {
          "id":"organize",
          "options":{
            "excludeByName":{"backend_start":false,"backend_xid":false,"backend_xmin":false,"client_hostname":true,"datid":false,"leader_pid":false,"query_id":true,"query_start":true,"state_change":true,"usesysid":false,"xact_start":true},
            "includeByName":{},
            "indexByName":{
              "application_name":6,
              "backend_start":14,
              "backend_type":1,
              "backend_xid":22,
              "backend_xmin":23,
              "blocking_pids":3,
              "client_addr":7,
              "client_hostname":27,
              "client_port":8,
              "conn_time":15,
              "datid":26,
              "datname":4,
              "leader_pid":24,
              "pid":0,
              "qid":9,
              "query":11,
              "query_id":10,
              "query_start":20,
              "query_time":17,
              "state":2,
              "state_change":21,
              "state_time":16,
              "usename":5,
              "usesysid":25,
              "wait_event":13,
              "wait_event_type":12,
              "xact_start":19,
              "xact_time":18
            },
            "renameByName":{
              "application_name":"App",
              "backend_start":"Start",
              "backend_type":"Type",
              "backend_xid":"XID",
              "backend_xmin":"XMIN",
              "blocking_pids":"Blocking PIDs",
              "client_addr":"IP",
              "client_hostname":"ClientHostname",
              "client_port":"Port",
              "conn_time":"ConnTime",
              "datid":"DBID",
              "datname":"Database",
              "leader_pid":"LeaderPID",
              "pid":"PID",
              "qid":"Query",
              "query":"SQL",
              "query_id":"QueryID",
              "query_start":"Query Start",
              "query_time":"QueryTime",
              "state":"State",
              "state_change":"Stage Change",
              "state_time":"StateTime",
              "usename":"User",
              "usesysid":"UID",
              "wait_event":"Event",
              "wait_event_type":"Wait",
              "xact_start":"Xact Start",
              "xact_time":"XactTime"
            }
          }
        }
      ],
      "type":"table"
    },
    {
      "collapsed":true,
      "gridPos":{"h":1,"w":24,"x":0,"y":35},
      "id":220,
      "panels":[
        {
          "datasource":{"type":"grafana-postgresql-datasource","uid":"${dsn}"},
          "description":"Get the latest 100 record from monitor.pg_wait_sampling_history.",
          "fieldConfig":{
            "defaults":{
              "custom":{"align":"center","cellOptions":{"type":"auto"},"filterable":false,"inspect":false},
              "mappings":[],
              "thresholds":{
                "mode":"absolute",
                "steps":[{"color":"#346f36cc"},{"color":"super-light-green","value":0.0001},{"color":"#346f36cc","value":0.01},{"color":"light-yellow","value":0.1},{"color":"#fcdb72","value":1},{"color":"super-light-orange","value":10},{"color":"#f79f64","value":60},{"color":"super-light-red","value":600},{"color":"red","value":1800},{"color":"super-light-purple","value":3600},{"color":"#b783af","value":7200}]
              }
            },
            "overrides":[
              {
                "matcher":{"id":"byName","options":"Wait"},
                "properties":[
                  {"id":"custom.width","value":80},
                  {
                    "id":"mappings",
                    "value":[
                      { "options":{"Activity":{"color":"#346f36cc","index":0},"BufferPin":{"color":"#f79f64","index":4},"Client":{"color":"#3e668f","index":1},"Extension":{"color":"#7771a4","index":8},"IO":{"color":"#f7cb67","index":3},"IPC":{"color":"#5b9cd5","index":2},"LWLock":{"color":"#cc4637d9","index":6},"Lock":{"color":"red","index":5},"Timeout":{"color":"#7f7f7f9e","index":7}},"type":"value"   },
                      { "options":{"match":"null","result":{"color":"super-light-green","index":9,"text":"Running"}}                                                                                                                                                                                                                                                                                ,"type":"special" }
                    ]
                  },
                  {"id":"custom.cellOptions","value":{"mode":"gradient","type":"color-background"}}
                ]
              },
              {"matcher":{"id":"byName","options":"Event"},"properties":[{"id":"custom.width","value":180},{"id":"custom.cellOptions","value":{"type":"auto"}},{"id":"thresholds","value":{"mode":"absolute","steps":[{"color":"#e3e3e3e0"}]}}]},
              {"matcher":{"id":"byName","options":"PID"},"properties":[{"id":"custom.width","value":70},{"id":"color","value":{"fixedColor":"#3e668f","mode":"fixed"}},{"id":"custom.cellOptions","value":{"type":"color-background"}}]},
              {
                "matcher":{"id":"byName","options":"Query"},
                "properties":[{"id":"custom.cellOptions","value":{"type":"auto"}},{"id":"links","value":[{"title":"${__data.fields.SQL}","url":"/d/pgcat-query?var-dsn=${dsn:text}&var-query=${__data.fields.Query}"}]},{"id":"unit","value":"string"},{"id":"mappings","value":[{"options":{"0":{"color":"text","index":0,"text":"_"}},"type":"value"}]},{"id":"custom.minWidth","value":150}]
              }
            ]
          },
          "gridPos":{"h":18,"w":9,"x":0,"y":36},
          "id":223,
          "options":{"cellHeight":"sm","footer":{"countRows":false,"fields":"","reducer":["sum"],"show":false},"showHeader":true,"sortBy":[{"desc":true,"displayName":"Query"}]},
          "pluginVersion":"11.6.0",
          "targets":[
            {
              "datasource":{"type":"postgres","uid":"${dsn}"},
              "editorMode":"code",
              "format":"table",
              "group":[],
              "metricColumn":"none",
              "rawQuery":true,
              "rawSql":"SELECT * FROM monitor.pg_wait_sampling_history ORDER BY ts DESC LIMIT 100;",
              "refId":"A",
              "select":[[{"params":["value"],"type":"column"}]],
              "sql":{"columns":[{"parameters":[],"type":"function"}],"groupBy":[{"property":{"type":"string"},"type":"groupBy"}],"limit":50},
              "timeColumn":"time",
              "where":[{"name":"$__timeFilter","params":[],"type":"macro"}]
            }
          ],
          "title":"Latest Wait Event History (latest 100)",
          "transformations":[
            {
              "id":"organize",
              "options":{
                "excludeByName":{"backend_start":false,"backend_xid":false,"backend_xmin":false,"client_hostname":true,"datid":false,"leader_pid":false,"query_id":true,"query_start":true,"state_change":true,"usesysid":false,"xact_start":true},
                "includeByName":{},
                "indexByName":{
                  "application_name":6,
                  "backend_start":14,
                  "backend_type":1,
                  "backend_xid":22,
                  "backend_xmin":23,
                  "blocking_pids":3,
                  "client_addr":7,
                  "client_hostname":27,
                  "client_port":8,
                  "conn_time":15,
                  "datid":26,
                  "datname":4,
                  "leader_pid":24,
                  "pid":0,
                  "qid":9,
                  "query":11,
                  "query_id":10,
                  "query_start":20,
                  "query_time":17,
                  "state":2,
                  "state_change":21,
                  "state_time":16,
                  "usename":5,
                  "usesysid":25,
                  "wait_event":13,
                  "wait_event_type":12,
                  "xact_start":19,
                  "xact_time":18
                },
                "renameByName":{
                  "application_name":"App",
                  "backend_start":"Start",
                  "backend_type":"Type",
                  "backend_xid":"XID",
                  "backend_xmin":"XMIN",
                  "blocking_pids":"Blocking PIDs",
                  "client_addr":"IP",
                  "client_hostname":"ClientHostname",
                  "client_port":"Port",
                  "conn_time":"ConnTime",
                  "datid":"DBID",
                  "datname":"Database",
                  "event":"Event",
                  "event_type":"Wait",
                  "leader_pid":"LeaderPID",
                  "pid":"PID",
                  "qid":"Query",
                  "query":"SQL",
                  "query_id":"QueryID",
                  "query_start":"Query Start",
                  "query_time":"QueryTime",
                  "queryid":"Query",
                  "state":"State",
                  "state_change":"Stage Change",
                  "state_time":"StateTime",
                  "ts":"Time",
                  "usename":"User",
                  "usesysid":"UID",
                  "wait_event":"Event",
                  "wait_event_type":"Wait",
                  "xact_start":"Xact Start",
                  "xact_time":"XactTime"
                }
              }
            }
          ],
          "type":"table"
        },
        {
          "datasource":{"type":"grafana-postgresql-datasource","uid":"${dsn}"},
          "description":"agg from monitor.pg_wait_sampling_profile by event_type, event",
          "fieldConfig":{
            "defaults":{
              "custom":{"align":"center","cellOptions":{"type":"auto"},"filterable":false,"inspect":false},
              "mappings":[],
              "thresholds":{
                "mode":"absolute",
                "steps":[{"color":"#346f36cc"},{"color":"super-light-green","value":0.0001},{"color":"#346f36cc","value":0.01},{"color":"light-yellow","value":0.1},{"color":"#fcdb72","value":1},{"color":"super-light-orange","value":10},{"color":"#f79f64","value":60},{"color":"super-light-red","value":600},{"color":"red","value":1800},{"color":"super-light-purple","value":3600},{"color":"#b783af","value":7200}]
              }
            },
            "overrides":[
              {
                "matcher":{"id":"byName","options":"Wait"},
                "properties":[
                  {"id":"custom.width","value":80},
                  {
                    "id":"mappings",
                    "value":[
                      { "options":{"Activity":{"color":"#346f36cc","index":0},"BufferPin":{"color":"#f79f64","index":4},"Client":{"color":"#3e668f","index":1},"Extension":{"color":"#7771a4","index":8},"IO":{"color":"#f7cb67","index":3},"IPC":{"color":"#5b9cd5","index":2},"LWLock":{"color":"#cc4637d9","index":6},"Lock":{"color":"red","index":5},"Timeout":{"color":"#7f7f7f9e","index":7}},"type":"value"   },
                      { "options":{"match":"null","result":{"color":"super-light-green","index":9,"text":"Running"}}                                                                                                                                                                                                                                                                                ,"type":"special" }
                    ]
                  },
                  {"id":"custom.cellOptions","value":{"mode":"gradient","type":"color-background"}}
                ]
              },
              {"matcher":{"id":"byName","options":"Event"},"properties":[{"id":"custom.width","value":180},{"id":"custom.cellOptions","value":{"type":"auto"}},{"id":"thresholds","value":{"mode":"absolute","steps":[{"color":"#e3e3e3e0"}]}}]},
              {"matcher":{"id":"byName","options":"PID"},"properties":[{"id":"custom.width","value":70},{"id":"color","value":{"fixedColor":"#3e668f","mode":"fixed"}},{"id":"custom.cellOptions","value":{"type":"color-background"}}]},{"matcher":{"id":"byName","options":"Count"},"properties":[{"id":"custom.minWidth","value":150}]}
            ]
          },
          "gridPos":{"h":18,"w":5,"x":9,"y":36},
          "id":222,
          "options":{"cellHeight":"sm","footer":{"countRows":false,"fields":"","reducer":["sum"],"show":false},"showHeader":true,"sortBy":[{"desc":true,"displayName":"Query"}]},
          "pluginVersion":"11.6.0",
          "targets":[
            {
              "datasource":{"type":"postgres","uid":"${dsn}"},
              "editorMode":"code",
              "format":"table",
              "group":[],
              "metricColumn":"none",
              "rawQuery":true,
              "rawSql":"select event_type AS event_type, event, sum(count) AS count  from monitor.pg_wait_sampling_profile GROUP BY event_type, event ORDER BY 3 DESC;",
              "refId":"A",
              "select":[[{"params":["value"],"type":"column"}]],
              "sql":{"columns":[{"parameters":[],"type":"function"}],"groupBy":[{"property":{"type":"string"},"type":"groupBy"}],"limit":50},
              "timeColumn":"time",
              "where":[{"name":"$__timeFilter","params":[],"type":"macro"}]
            }
          ],
          "title":"Wait Event Counter",
          "transformations":[
            {
              "id":"organize",
              "options":{
                "excludeByName":{"backend_start":false,"backend_xid":false,"backend_xmin":false,"client_hostname":true,"datid":false,"leader_pid":false,"query_id":true,"query_start":true,"state_change":true,"usesysid":false,"xact_start":true},
                "includeByName":{},
                "indexByName":{
                  "application_name":6,
                  "backend_start":14,
                  "backend_type":1,
                  "backend_xid":22,
                  "backend_xmin":23,
                  "blocking_pids":3,
                  "client_addr":7,
                  "client_hostname":27,
                  "client_port":8,
                  "conn_time":15,
                  "datid":26,
                  "datname":4,
                  "leader_pid":24,
                  "pid":0,
                  "qid":9,
                  "query":11,
                  "query_id":10,
                  "query_start":20,
                  "query_time":17,
                  "state":2,
                  "state_change":21,
                  "state_time":16,
                  "usename":5,
                  "usesysid":25,
                  "wait_event":13,
                  "wait_event_type":12,
                  "xact_start":19,
                  "xact_time":18
                },
                "renameByName":{
                  "application_name":"App",
                  "backend_start":"Start",
                  "backend_type":"Type",
                  "backend_xid":"XID",
                  "backend_xmin":"XMIN",
                  "blocking_pids":"Blocking PIDs",
                  "client_addr":"IP",
                  "client_hostname":"ClientHostname",
                  "client_port":"Port",
                  "conn_time":"ConnTime",
                  "count":"Count",
                  "datid":"DBID",
                  "datname":"Database",
                  "event":"Event",
                  "event_type":"Wait",
                  "leader_pid":"LeaderPID",
                  "pid":"PID",
                  "qid":"Query",
                  "query":"SQL",
                  "query_id":"QueryID",
                  "query_start":"Query Start",
                  "query_time":"QueryTime",
                  "queryid":"Query",
                  "state":"State",
                  "state_change":"Stage Change",
                  "state_time":"StateTime",
                  "usename":"User",
                  "usesysid":"UID",
                  "wait_event":"Event",
                  "wait_event_type":"Wait",
                  "xact_start":"Xact Start",
                  "xact_time":"XactTime"
                }
              }
            }
          ],
          "type":"table"
        },
        {
          "datasource":{"type":"grafana-postgresql-datasource","uid":"${dsn}"},
          "description":"agg from monitor.pg_wait_sampling_profile by event_type, event in last one second",
          "fieldConfig":{
            "defaults":{
              "custom":{"align":"center","cellOptions":{"type":"auto"},"filterable":false,"inspect":false},
              "mappings":[],
              "thresholds":{
                "mode":"absolute",
                "steps":[{"color":"#346f36cc"},{"color":"super-light-green","value":0.0001},{"color":"#346f36cc","value":0.01},{"color":"light-yellow","value":0.1},{"color":"#fcdb72","value":1},{"color":"super-light-orange","value":10},{"color":"#f79f64","value":60},{"color":"super-light-red","value":600},{"color":"red","value":1800},{"color":"super-light-purple","value":3600},{"color":"#b783af","value":7200}]
              }
            },
            "overrides":[
              {
                "matcher":{"id":"byName","options":"Wait"},
                "properties":[
                  {"id":"custom.width","value":80},
                  {
                    "id":"mappings",
                    "value":[
                      { "options":{"Activity":{"color":"#346f36cc","index":0},"BufferPin":{"color":"#f79f64","index":4},"Client":{"color":"#3e668f","index":1},"Extension":{"color":"#7771a4","index":8},"IO":{"color":"#f7cb67","index":3},"IPC":{"color":"#5b9cd5","index":2},"LWLock":{"color":"#cc4637d9","index":6},"Lock":{"color":"red","index":5},"Timeout":{"color":"#7f7f7f9e","index":7}},"type":"value"   },
                      { "options":{"match":"null","result":{"color":"super-light-green","index":9,"text":"Running"}}                                                                                                                                                                                                                                                                                ,"type":"special" }
                    ]
                  },
                  {"id":"custom.cellOptions","value":{"mode":"gradient","type":"color-background"}}
                ]
              },
              {"matcher":{"id":"byName","options":"Event"},"properties":[{"id":"custom.width","value":180},{"id":"custom.cellOptions","value":{"type":"auto"}},{"id":"thresholds","value":{"mode":"absolute","steps":[{"color":"#e3e3e3e0"}]}}]},
              {"matcher":{"id":"byName","options":"PID"},"properties":[{"id":"custom.width","value":70},{"id":"color","value":{"fixedColor":"#3e668f","mode":"fixed"}},{"id":"custom.cellOptions","value":{"type":"color-background"}}]},
              {
                "matcher":{"id":"byName","options":"Query"},
                "properties":[{"id":"custom.width","value":200},{"id":"custom.cellOptions","value":{"type":"auto"}},{"id":"links","value":[{"title":"${__data.fields.SQL}","url":"/d/pgcat-query?var-dsn=${dsn:text}&var-query=${__data.fields.Query}"}]},{"id":"unit","value":"string"},{"id":"mappings","value":[{"options":{"0":{"color":"text","index":0,"text":"_"}},"type":"value"}]}]
              },
              {"matcher":{"id":"byName","options":"Count"},"properties":[{"id":"custom.minWidth","value":100}]}
            ]
          },
          "gridPos":{"h":18,"w":5,"x":14,"y":36},
          "id":224,
          "options":{"cellHeight":"sm","footer":{"countRows":false,"fields":"","reducer":["sum"],"show":false},"showHeader":true,"sortBy":[{"desc":true,"displayName":"Count"}]},
          "pluginVersion":"11.6.0",
          "targets":[
            {
              "datasource":{"type":"postgres","uid":"${dsn}"},
              "editorMode":"code",
              "format":"table",
              "group":[],
              "metricColumn":"none",
              "rawQuery":true,
              "rawSql":"  SELECT event_type, event, count(*) FROM monitor.pg_wait_sampling_history \n  WHERE ts BETWEEN now() - '1s'::INTERVAL AND now()\n  GROUP BY 1,2;",
              "refId":"A",
              "select":[[{"params":["value"],"type":"column"}]],
              "sql":{"columns":[{"parameters":[],"type":"function"}],"groupBy":[{"property":{"type":"string"},"type":"groupBy"}],"limit":50},
              "timeColumn":"time",
              "where":[{"name":"$__timeFilter","params":[],"type":"macro"}]
            }
          ],
          "title":"Wait Event Count in Last 1 second",
          "transformations":[
            {
              "id":"organize",
              "options":{
                "excludeByName":{"backend_start":false,"backend_xid":false,"backend_xmin":false,"client_hostname":true,"datid":false,"leader_pid":false,"query_id":true,"query_start":true,"state_change":true,"usesysid":false,"xact_start":true},
                "includeByName":{},
                "indexByName":{
                  "application_name":6,
                  "backend_start":14,
                  "backend_type":1,
                  "backend_xid":22,
                  "backend_xmin":23,
                  "blocking_pids":3,
                  "client_addr":7,
                  "client_hostname":27,
                  "client_port":8,
                  "conn_time":15,
                  "datid":26,
                  "datname":4,
                  "leader_pid":24,
                  "pid":0,
                  "qid":9,
                  "query":11,
                  "query_id":10,
                  "query_start":20,
                  "query_time":17,
                  "state":2,
                  "state_change":21,
                  "state_time":16,
                  "usename":5,
                  "usesysid":25,
                  "wait_event":13,
                  "wait_event_type":12,
                  "xact_start":19,
                  "xact_time":18
                },
                "renameByName":{
                  "application_name":"App",
                  "backend_start":"Start",
                  "backend_type":"Type",
                  "backend_xid":"XID",
                  "backend_xmin":"XMIN",
                  "blocking_pids":"Blocking PIDs",
                  "client_addr":"IP",
                  "client_hostname":"ClientHostname",
                  "client_port":"Port",
                  "conn_time":"ConnTime",
                  "count":"Count",
                  "datid":"DBID",
                  "datname":"Database",
                  "event":"Event",
                  "event_type":"Wait",
                  "leader_pid":"LeaderPID",
                  "pid":"PID",
                  "qid":"Query",
                  "query":"SQL",
                  "query_id":"QueryID",
                  "query_start":"Query Start",
                  "query_time":"QueryTime",
                  "queryid":"Query",
                  "state":"State",
                  "state_change":"Stage Change",
                  "state_time":"StateTime",
                  "usename":"User",
                  "usesysid":"UID",
                  "wait_event":"Event",
                  "wait_event_type":"Wait",
                  "xact_start":"Xact Start",
                  "xact_time":"XactTime"
                }
              }
            }
          ],
          "type":"table"
        },
        {
          "datasource":{"type":"grafana-postgresql-datasource","uid":"${dsn}"},
          "fieldConfig":{
            "defaults":{"color":{"mode":"palette-classic"},"custom":{"hideFrom":{"legend":false,"tooltip":false,"viz":false}},"mappings":[]},
            "overrides":[
              { "matcher":{"id":"byName","options":"idle"}                                  ,"properties":[{"id":"color","value":{"fixedColor":"#f79f64","mode":"fixed"}}]           },{ "matcher":{"id":"byName","options":"null"}                                  ,"properties":[{"id":"color","value":{"fixedColor":"#80808080","mode":"fixed"}}]         },
              { "matcher":{"id":"byName","options":"active"}                                ,"properties":[{"id":"color","value":{"fixedColor":"#346f36cc","mode":"fixed"}}]         },{ "matcher":{"id":"byName","options":"client backend"}                        ,"properties":[{"id":"color","value":{"fixedColor":"#3e668f","mode":"fixed"}}]           },
              { "matcher":{"id":"byName","options":"checkpointer"}                          ,"properties":[{"id":"color","value":{"fixedColor":"light-red","mode":"fixed"}}]         },{ "matcher":{"id":"byName","options":"background writer"}                     ,"properties":[{"id":"color","value":{"fixedColor":"super-light-green","mode":"fixed"}}] },
              { "matcher":{"id":"byName","options":"walsender"}                             ,"properties":[{"id":"color","value":{"fixedColor":"#f79f64","mode":"fixed"}}]           },{ "matcher":{"id":"byName","options":"TimescaleDB Background Worker Launcher"},"properties":[{"id":"color","value":{"fixedColor":"#808080","mode":"fixed"}}]           },
              { "matcher":{"id":"byName","options":"archiver"}                              ,"properties":[{"id":"color","value":{"fixedColor":"super-light-red","mode":"fixed"}}]   },{ "matcher":{"id":"byName","options":"autovacuum launcher"}                   ,"properties":[{"id":"color","value":{"fixedColor":"dark-yellow","mode":"fixed"}}]       },
              { "matcher":{"id":"byName","options":"walwriter"}                             ,"properties":[{"id":"color","value":{"fixedColor":"dark-red","mode":"fixed"}}]          },{ "matcher":{"id":"byName","options":"logical replication launcher"}          ,"properties":[{"id":"color","value":{"fixedColor":"#b783af","mode":"fixed"}}]           },
              { "matcher":{"id":"byName","options":"Client"}                                ,"properties":[{"id":"color","value":{"fixedColor":"blue","mode":"fixed"}}]              },{ "matcher":{"id":"byName","options":"Running"}                               ,"properties":[{"id":"color","value":{"fixedColor":"super-light-green","mode":"fixed"}}] },
              { "matcher":{"id":"byName","options":"Activity"}                              ,"properties":[{"id":"color","value":{"fixedColor":"green","mode":"fixed"}}]             }
            ]
          },
          "gridPos":{"h":18,"w":5,"x":19,"y":36},
          "id":228,
          "options":{"displayLabels":[],"legend":{"displayMode":"table","placement":"bottom","showLegend":true,"values":["value","percent"]},"pieType":"pie","reduceOptions":{"calcs":["lastNotNull"],"fields":"","values":false},"tooltip":{"hideZeros":false,"mode":"multi","sort":"none"}},
          "pluginVersion":"11.6.0",
          "targets":[
            {
              "datasource":{"type":"grafana-postgresql-datasource","uid":"pg-meta-1.meta"},
              "editorMode":"code",
              "format":"time_series",
              "group":[],
              "metricColumn":"none",
              "rawQuery":true,
              "rawSql":"  SELECT now() AS time, \n  coalesce(event_type, 'Running') AS metric, count(*) AS value\n  FROM monitor.pg_wait_sampling_history \n  WHERE ts BETWEEN now() - '1s'::INTERVAL AND now()\n  GROUP BY 2;",
              "refId":"A",
              "select":[[{"params":["value"],"type":"column"}]],
              "sql":{"columns":[{"parameters":[],"type":"function"}],"groupBy":[{"property":{"type":"string"},"type":"groupBy"}],"limit":50},
              "timeColumn":"time",
              "where":[{"name":"$__timeFilter","params":[],"type":"macro"}]
            }
          ],
          "title":"Wait Event Type",
          "type":"piechart"
        },
        {
          "datasource":{"type":"prometheus","uid":"ds-prometheus"},
          "description":"Group by pg_stat_activity.wait_event_type on instance level",
          "fieldConfig":{
            "defaults":{
              "color":{"mode":"palette-classic"},
              "custom":{
                "axisBorderShow":false,
                "axisCenteredZero":false,
                "axisColorMode":"text",
                "axisLabel":"",
                "axisPlacement":"auto",
                "barAlignment":0,
                "barWidthFactor":0.6,
                "drawStyle":"line",
                "fillOpacity":71,
                "gradientMode":"hue",
                "hideFrom":{"legend":false,"tooltip":false,"viz":false},
                "insertNulls":false,
                "lineInterpolation":"stepBefore",
                "lineWidth":0,
                "pointSize":5,
                "scaleDistribution":{"type":"linear"},
                "showPoints":"auto",
                "spanNulls":false,
                "stacking":{"group":"A","mode":"normal"},
                "thresholdsStyle":{"mode":"off"}
              },
              "mappings":[],
              "thresholds":{"mode":"absolute","steps":[{"color":"#346f36cc"}]}
            },
            "overrides":[
              { "matcher":{"id":"byName","options":"Client"}   ,"properties":[{"id":"color","value":{"fixedColor":"#3e668f","mode":"fixed"}}]           },{ "matcher":{"id":"byName","options":"NULL"}     ,"properties":[{"id":"color","value":{"fixedColor":"#808080","mode":"fixed"}}]           },
              { "matcher":{"id":"byName","options":"Extension"},"properties":[{"id":"color","value":{"fixedColor":"#7771a4","mode":"fixed"}}]           },{ "matcher":{"id":"byName","options":"IPC"}      ,"properties":[{"id":"color","value":{"fixedColor":"#5b9cd5","mode":"fixed"}}]           },
              { "matcher":{"id":"byName","options":"IO"}       ,"properties":[{"id":"color","value":{"fixedColor":"#f7cb67","mode":"fixed"}}]           },{ "matcher":{"id":"byName","options":"Lock"}     ,"properties":[{"id":"color","value":{"fixedColor":"#e02f44","mode":"fixed"}}]           },
              { "matcher":{"id":"byName","options":"LWLock"}   ,"properties":[{"id":"color","value":{"fixedColor":"#cc4637d9","mode":"fixed"}}]         },{ "matcher":{"id":"byName","options":"Timeout"}  ,"properties":[{"id":"color","value":{"fixedColor":"#7f7f7f9e","mode":"fixed"}}]         },
              { "matcher":{"id":"byName","options":"Running"}  ,"properties":[{"id":"color","value":{"fixedColor":"super-light-green","mode":"fixed"}}] }
            ]
          },
          "gridPos":{"h":8,"w":12,"x":0,"y":54},
          "id":229,
          "links":[{"title":"PGRDS Cluster: ${cls}","url":"/d/pgrds-cluster?var-cls=${cls}&viewPanel=165&${__url_time_range}"}],
          "options":{"legend":{"calcs":["last"],"displayMode":"table","placement":"right","showLegend":true,"sortBy":"Last","sortDesc":true},"tooltip":{"hideZeros":false,"mode":"multi","sort":"none"}},
          "pluginVersion":"11.6.0",
          "targets":[{"datasource":{"type":"prometheus","uid":"ds-prometheus"},"editorMode":"code","exemplar":false,"expr":"sum by (event) (pg_wait_count{ins=\"$ins\"})","interval":"","legendFormat":"{{ event }}","range":true,"refId":"A"}],
          "title":"Backends by Wait Event Type",
          "transformations":[{"id":"renameByRegex","options":{"regex":"(Value)","renamePattern":"NULL"}}],
          "type":"timeseries"
        },
        {
          "datasource":{"type":"prometheus","uid":"ds-prometheus"},
          "fieldConfig":{
            "defaults":{
              "color":{"mode":"palette-classic"},
              "custom":{
                "axisBorderShow":false,
                "axisCenteredZero":false,
                "axisColorMode":"text",
                "axisLabel":"",
                "axisPlacement":"auto",
                "barAlignment":0,
                "barWidthFactor":0.6,
                "drawStyle":"line",
                "fillOpacity":71,
                "gradientMode":"hue",
                "hideFrom":{"legend":false,"tooltip":false,"viz":false},
                "insertNulls":false,
                "lineInterpolation":"stepBefore",
                "lineWidth":0,
                "pointSize":5,
                "scaleDistribution":{"type":"linear"},
                "showPoints":"auto",
                "spanNulls":false,
                "stacking":{"group":"A","mode":"normal"},
                "thresholdsStyle":{"mode":"off"}
              },
              "mappings":[],
              "thresholds":{"mode":"absolute","steps":[{"color":"#346f36cc"}]}
            },
            "overrides":[
              { "matcher":{"id":"byName","options":"client backend"}               ,"properties":[{"id":"color","value":{"fixedColor":"#346f36cc","mode":"fixed"}}]                },{ "matcher":{"id":"byName","options":"autovacuum launcher"}          ,"properties":[{"id":"color","value":{"fixedColor":"#b783af","mode":"fixed"}}]                  },
              { "matcher":{"id":"byName","options":"background writer"}            ,"properties":[{"id":"color","value":{"fixedColor":"#f79f64","mode":"fixed"}}]                  },{ "matcher":{"id":"byName","options":"checkpointer"}                 ,"properties":[{"id":"color","value":{"fixedColor":"super-light-orange","mode":"fixed"}}]       },
              { "matcher":{"id":"byName","options":"logical replication launcher"} ,"properties":[{"id":"color","value":{"fixedColor":"#3e668f","mode":"fixed"}}]                  },{ "matcher":{"id":"byName","options":"walwriter"}                    ,"properties":[{"id":"color","value":{"fixedColor":"super-light-blue","mode":"fixed"}}]         },
              { "matcher":{"id":"byName","options":"idle"}                         ,"properties":[{"id":"color","value":{"fixedColor":"rgba(128, 128, 128, 0.5)","mode":"fixed"}}] },{ "matcher":{"id":"byName","options":"active"}                       ,"properties":[{"id":"color","value":{"fixedColor":"#346f36cc","mode":"fixed"}}]                },
              { "matcher":{"id":"byName","options":"disabled"}                     ,"properties":[{"id":"color","value":{"fixedColor":"#fcdb72","mode":"fixed"}}]                  },{ "matcher":{"id":"byName","options":"idle in transaction (aborted)"},"properties":[{"id":"color","value":{"fixedColor":"#b783af","mode":"fixed"}}]                  },
              { "matcher":{"id":"byName","options":"idle in transaction"}          ,"properties":[{"id":"color","value":{"fixedColor":"#cc4637d9","mode":"fixed"}}]                },{ "matcher":{"id":"byName","options":"Client"}                       ,"properties":[{"id":"color","value":{"fixedColor":"#346f36cc","mode":"fixed"}}]                },
              { "matcher":{"id":"byName","options":"Running"}                      ,"properties":[{"id":"color","value":{"fixedColor":"green","mode":"fixed"}}]                    },{ "matcher":{"id":"byName","options":"ClientRead"}                   ,"properties":[{"id":"color","value":{"fixedColor":"blue","mode":"fixed"}}]                     }
            ]
          },
          "gridPos":{"h":8,"w":12,"x":12,"y":54},
          "id":225,
          "options":{"legend":{"calcs":["last"],"displayMode":"table","placement":"right","showLegend":true,"sortBy":"Last","sortDesc":true},"tooltip":{"hideZeros":false,"mode":"multi","sort":"none"}},
          "pluginVersion":"11.6.0",
          "targets":[{"editorMode":"code","exemplar":false,"expr":"sum by (event) (rate(pg_wait_event_count{ins=\"$ins\"}[30s]))","interval":"","legendFormat":"{{ event }}","range":true,"refId":"A"}],
          "title":"Backends by Wait Event",
          "type":"timeseries"
        }
      ],
      "title":"WaitEvent (pg_wait_sampling required)",
      "type":"row"
    }
  ],
  "preload":false,
  "refresh":"1s",
  "schemaVersion":41,
  "tags":["Pigsty","PGSQL","PGCAT","Database"],
  "templating":{
    "list":[
      { "current":{},                                                                                     "description":"Database Instance"          ,         "includeAll":false,"label":"Data Source","name":"dsn"    ,"options":[],"query":"postgres"             ,"refresh":1,"regex":"/.*\\..*/"           ,"type":"datasource"          },
      { "current":{},"datasource":{"type":"postgres","uid":"${dsn}"},"definition":"SELECT '${dsn:text}';","description":"Instance"                   ,"hide":2,"includeAll":false,"label":"Instance"   ,"name":"ins"    ,"options":[],"query":"SELECT '${dsn:text}';","refresh":2,"regex":"/(\\S+)\\.\\S+/"     ,"type":"query"     ,"sort":1 },
      { "current":{},"datasource":{"type":"postgres","uid":"${dsn}"},"definition":"SELECT '${dsn:text}';","description":"Database name of this table","hide":2,"includeAll":false,"label":"Database"   ,"name":"datname","options":[],"query":"SELECT '${dsn:text}';","refresh":1,"regex":"/\\S+\\.(\\S+)/"     ,"type":"query"               },
      { "current":{},"datasource":{"type":"postgres","uid":"${dsn}"},"definition":"SELECT '${dsn:text}';","description":"Cluster"                    ,"hide":2,"includeAll":false,"label":"Cluster"    ,"name":"cls"    ,"options":[],"query":"SELECT '${dsn:text}';","refresh":2,"regex":"/(\\S+)-\\d+\\.\\S+/","type":"query"     ,"sort":1 }
    ]
  },
  "time":{"from":"now-1h","to":"now"},
  "timepicker":{"refresh_intervals":["100ms","200ms","300ms","500ms","1s","2s","5s","10s","30s","1m","5m","15m","30m"]},
  "timezone":"browser",
  "title":"PGCAT Locks",
  "uid":"pgcat-locks",
  "version":1
}