Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
infra
ansible-shared
zabbix
Commits
af165749
Commit
af165749
authored
May 03, 2017
by
Lars Beckers
Browse files
zabbix-server: add comment counts function
parent
7f936a04
Changes
2
Hide whitespace changes
Inline
Side-by-side
zabbix-server/files/commentcounts.sql
0 → 100644
View file @
af165749
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
;
zabbix-server/tasks/main.yml
View file @
af165749
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment