[ZBX-10076] IBM DB2 error "Value is too long" for message field in alerts table Created: 2015 Nov 13 Updated: 2017 May 30 Resolved: 2016 Feb 24 |
|
Status: | Closed |
Project: | ZABBIX BUGS AND ISSUES |
Component/s: | Frontend (F), Server (S) |
Affects Version/s: | 2.2.11 |
Fix Version/s: | 3.2.0alpha1 |
Type: | Incident report | Priority: | Blocker |
Reporter: | Ingus Vilnis | Assignee: | Unassigned |
Resolution: | Fixed | Votes: | 0 |
Labels: | database, db2 | ||
Remaining Estimate: | Not Specified | ||
Time Spent: | Not Specified | ||
Original Estimate: | Not Specified |
Issue Links: |
|
Description |
IBM DB2 error when trying to insert long text in message field in alerts table. 993:20151112:183728.751 [Z3005] query failed: [-433] 22001 [IBM][CLI Driver][DB2/LINUXX8664] SQL0433N Value "2015.11.12 09:33:02 New message in file /var/log/websphere/i" is too long. SQLSTATE=22001 [insert into alerts (alertid,actionid,eventid,userid,clock,mediatypeid,sendto,subject,message,status,error,esc_step,alerttype) values (8862248,103,3907367,64,1447346248,1,'[email protected]','Websphere iApi: PROBLEM (New message in file /var/log/websphere/iapi_clsrv2.log.2015-11-12)','...Long log message with some text data here...',0,'',1,0);] In such case entries are not stored in alerts table thus no messages are sent to recipients when corresponding trigger is fired. |
Comments |
Comment by Glebs Ivanovskis (Inactive) [ 2015 Dec 03 ] |
Issue lies somewhere in between Zabbix server and IBM DB2 database and is encoding related. It is possible to reproduce the error message "Value ... is too long" for any text field. IBM DB2 look into LANG environment variable of the client (Zabbix server or proxy in our case) to find out what encoding it should expect from client. Zabbix server always works in UTF-8 and does not care about LANG variable. Let's assume LANG is set to POSIX for Zabbix server/proxy and the latter wants to insert a text containing non-ASCII characters. Zabbix server/proxy prepares a valid and properly truncated to fit into field width UTF-8 string. IBM DB2 gets this string, assumes that it is some kind of one-byte-per-character encoding and starts to convert it to UTF-8. ASCII characters are fine, they stay as they are. But non-ASCII characters take up more than one byte in UTF-8 and every one of them starts with binary '1', therefore corresponds to a non-ASCII character in one-byte-per-character encoding (character code > 127) and therefore grows to 2 to 4 bytes in UTF-8. This way every non-ASCII character can expand from 2-4 bytes in Zabbix server string to 4-16 |
Comment by Glebs Ivanovskis (Inactive) [ 2015 Dec 03 ] |
So this becomes a documentation issue. There is a set of locale environment variables, and they influence and override each other in a very interesting manner:
The most important for us is LC_CTYPE which
If LC_CTYPE is not set explicitly, its value is borrowed from LANG variable. However, regardless of whether LC_CTYPE is set explicitly or not its value is overridden by LC_ALL. $ locale | grep -E "LC_CTYPE=|LANG=|LC_ALL=" LANG=en_US.UTF-8 LC_CTYPE="en_US.UTF-8" LC_ALL= $ LC_CTYPE=POSIX locale | grep -E "LC_CTYPE=|LANG=|LC_ALL=" LANG=en_US.UTF-8 LC_CTYPE=POSIX LC_ALL= $ LANG=POSIX locale | grep -E "LC_CTYPE=|LANG=|LC_ALL=" LANG=POSIX LC_CTYPE="POSIX" LC_ALL= $ LANG=POSIX LC_CTYPE=en_US.UTF-8 locale | grep -E "LC_CTYPE=|LANG=|LC_ALL=" LANG=POSIX LC_CTYPE=en_US.UTF-8 LC_ALL= $ LC_ALL=POSIX LC_CTYPE=en_US.UTF-8 locale | grep -E "LC_CTYPE=|LANG=|LC_ALL=" LANG=en_US.UTF-8 LC_CTYPE="POSIX" LC_ALL=POSIX Documentation must say that Zabbix users should provide that locale environment variables are properly set for Zabbix server/proxy:
This can be achieved by editing system configuration files for "zabbix" user or by simply setting necessary environment variables in commands to run Zabbix daemons: $ LC_ALL=en_US.UTF-8 zabbix_server ... As we see, it is very critical for IBM DB2 where we have the strictest limit of 2048 bytes for text fields, but can play a role for other DB engines as well resulting in more space taken by non-ASCII characters than essentially required (this has to be investigated in more detail though). |
Comment by Glebs Ivanovskis (Inactive) [ 2015 Dec 04 ] |
Zabbix server/proxy environment variables does not seem to affect how non-IBM DB2 database server interprets text Zabbix server/proxy sends to it. For example, PostreSQL documentation says that
Related reading on this topic: For Oracle we set NLS_LANG=.UTF8. zalex_ua As for Oracle, see also |
Comment by Glebs Ivanovskis (Inactive) [ 2015 Dec 08 ] |
If my words did not convince you, see Chapter 5 (p. 49) of IBM DB2 10.5 for Linux, UNIX, and Windows - Globalization Guide |
Comment by Glebs Ivanovskis (Inactive) [ 2015 Dec 09 ] |
Fixed for version 2.2 in development branch svn://svn.zabbix.com/branches/dev/ZBX-10076-22 revisions 57098 (server) and 57116 (frontend). Server will now set SQL_ATTR_CLIENT_CODEPAGE connection attribute to 1208 (IBM notation of UTF-8). Unfortunately, it is not possible to set client codepage attributes on the connection level in PHP. That's why we utilize web server environment variables for this purpose. We try to setlocale() to one of the most common UTF-8 locales and issue an error if we fail. |
Comment by Glebs Ivanovskis (Inactive) [ 2015 Dec 09 ] |
(1) If environment variables were not set for Zabbix server and web server properly, non-ASCII text information is stored in the database incorrectly. This may cause problems after the fix and therefore has to be documented in Upgrade notes. |
Comment by Oleksii Zagorskyi [ 2015 Dec 21 ] |
I'd suggest to fix this for 3.0 only as it involves upgrade notes documentation, db creation scripts documentation. |
Comment by Andris Zeila [ 2016 Jan 19 ] |
(2) According to the documentation (not examples) it seems to be more correct using SQL_IS_UINTEGER rather than SQL_IS_POINTER when setting codepage attribute. Please review, r57840, r57841. glebs.ivanovskis Following documentation rigorously will definitely not hurt. Thanks, accepted. |
Comment by Andris Zeila [ 2016 Jan 19 ] |
Server side tested |
Comment by Oleg Egorov (Inactive) [ 2016 Feb 04 ] |
(3) [F] Minor coding style improvements in r58270 and r58271 iivs CLOSED |
Comment by Ivo Kurzemnieks [ 2016 Feb 04 ] |
(4) Success message "Application added", but there is an error in details: And error in footer: And items... oleg.egorov MOVED to iivs CLOSED |
Comment by Oleg Egorov (Inactive) [ 2016 Feb 04 ] |
Frontend side tested |
Comment by Glebs Ivanovskis (Inactive) [ 2016 Feb 18 ] |
(5) Since it was decided to fix the issue for trunk only, I've ported patch to new development branch svn://svn.zabbix.com/branches/dev/ZBX-10076 revision 58556. There was a conflict on frontend side. oleg.egorov, please review. oleg.egorov CLOSED |
Comment by Glebs Ivanovskis (Inactive) [ 2016 Feb 19 ] |
Fixed in pre-3.1.0 (trunk) revision 58585. |
Comment by Glebs Ivanovskis (Inactive) [ 2016 Feb 22 ] |
Documented in:
sasha CLOSED |