Commit af165749 authored by Lars Beckers's avatar Lars Beckers
Browse files

zabbix-server: add comment counts function

parent 7f936a04
CREATE OR REPLACE FUNCTION zbx_update_partition_table_comments(schema_arg TEXT DEFAULT 'partitions') RETURNS INT AS $$
DECLARE
r RECORD;
c BIGINT;
t TEXT;
BEGIN
RAISE NOTICE 'Updating table comments in schema %', schema_arg;
FOR r IN SELECT tablename FROM pg_tables WHERE schemaname = schema_arg -- AND tablename like 'history_str%'
LOOP
RAISE NOTICE '. updating comment for %.%', schema_arg, r.tablename;
EXECUTE 'SELECT count(1) FROM ' || quote_ident(schema_arg) || '.' || quote_ident(r.tablename) || '' INTO c;
t := quote_literal(date_trunc('second',CURRENT_TIMESTAMP)::TEXT || ' => ' || to_char(c, '999G999G999G999') || ' Rows');
RAISE NOTICE '.. got count % for %.%', t, schema_arg, r.tablename;
EXECUTE 'COMMENT ON TABLE ' || quote_ident(schema_arg) || '.' || quote_ident(r.tablename) ||' IS ' || t || '';
END LOOP;
RETURN 1;
END
$$ LANGUAGE plpgsql;
......@@ -36,6 +36,12 @@
- database
- zabbix
- name: ensure there is the commentcounts sql file
copy: src=commentcounts.sql dest=/usr/share/doc/zabbix-server-pgsql/commentcounts.sql
tags:
- database
- zabbix
- name: ensure we have a user on the database server
postgresql_user: name="{{ zabbix_db_user }}" password="{{ zabbix_db_password }}" state=present role_attr_flags=NOSUPERUSER,NOCREATEDB
become: yes
......@@ -107,6 +113,18 @@
- database
- zabbix
- name: apply database commentcounts function
shell: psql -h {{ zabbix_db_host }} -U {{ zabbix_db_user }} -w -d {{ zabbix_db_name }} -f /usr/share/doc/zabbix-server-pgsql/commentcounts.sql && touch /var/lib/zabbix/.db_schema_countfunc
args:
creates: /var/lib/zabbix/.db_schema_countfunc
become: yes
become_user: zabbix
notify:
- restart zabbix server
tags:
- database
- zabbix
- name: include snmp-features
include: snmp.yml
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment