myNMS> echo "select count(*) from IP_MAC" | mysql -t NMS +----------+ | count(*) | +----------+ | 16145 | +----------+ myNMS> echo "select count(*) from IP_MAC where time2<`DB_maint --showtime NOW - QUARTER`" | mysql NMS +----------+ | count(*) | +----------+ | 8824 | +----------+
In the case of the IP_MAC_user table however the table itself is relatively large, and historical records form a greater proportion of the whole:
For this table old records should be deleted periodically, e.g.:myNMS> echo "select count(*) from IP_MAC_user" | mysql NMS +----------+ | count(*) | +----------+ | 398065 | +----------+ myNMS> echo "select count(*) from IP_MAC_user where mtime<`DB_maint --showtime NOW - QUARTER`" | mysql NMS +----------+ | count(*) | +----------+ | 270258 | +----------+ myNMS> echo "select count(*) from IP_MAC_user where mtime<`DB_maint --showtime NOW - QUARTER - QUARTER`" | mysql -t NMS +----------+ | count(*) | +----------+ | 208687 | +----------+
myNMS> echo "delete from IP_MAC_user where mtime < `DB_maint --showtime NOW - QUARTER - QUARTER`" | mysql NMS
This can be fixed using
Whilst working DB_maint will report duplicates and consecutive time records it finds e.g.:myNMS> DB_maint --undup NMS IP_MAC_user
If this has to be done repeatedly it could be performed by a cron job daily, weekly or monthly.Duplicate records for IP/MAC/user/time: 192.171.166.6 0800208694df sgshoges 20010215170500 Duplicate records for IP/MAC/user/time: 192.171.166.6 0800208694df sgshoges 20010215170500 Duplicate records for IP/MAC/user/time: 192.171.166.6 0800208694df sgshoges 20010215170500 Duplicate records for IP/MAC/user/time: 192.171.166.6 0800208694df sgshoges 20010215170500 Duplicate records for IP/MAC/user/time: 192.171.166.6 0800208694df sgshoges 20010215170500 Duplicate records for IP/MAC/user/time: 192.171.166.6 0800208694df sgshoges 20010215170500 Duplicate records for IP/MAC/user/time: 192.171.166.6 0800208694df sgshoges 20010215170500 Duplicate records for IP/MAC/user/time: 192.171.166.6 0800208694df sgshoges 20010215170500 Duplicate records for IP/MAC/user/time: 192.171.166.6 0800208694df sgshoges 20010215170500 Duplicate records for IP/MAC/user/time: 192.171.166.6 0800208694df sgshoges 20010215170500 Duplicate records for IP/MAC/user/time: 192.171.166.6 0800208694df sgshoges 20010215170500 Consecutive records for IP, MAC, user : 192.171.166.6 0800208694df sgshoges mtime(1): 20010215170500 mtime(2): 20010216180820 Consecutive records for IP, MAC, user : 192.171.166.6 0800208694df sgshoges mtime(1): 20010216180820 mtime(2): 20010219180500 Consecutive records for IP, MAC, user : 192.171.166.6 0800208694df sgshoges mtime(1): 20010219180500 mtime(2): 20010220121320 Consecutive records for IP, MAC, user : 192.171.166.6 0800208694df sgshoges mtime(1): 20010220121320 mtime(2): 20010221181820 Consecutive records for IP, MAC, user : 192.171.166.6 0800208694df sgshoges mtime(1): 20010221181820 mtime(2): 20010222134820
The result will be that the query should produce the correct result:
Another indication is messages in log files like:
When these occur the tool isamchk can be used to check for and repair errors. To use the tool specify (or change into) the directory containing the files mySQL uses to store the affected table, and specify the table name (file name without any extension) e.g.:DBD::mysql::db do failed: Duplicate entry '947188840-20' for key 2 at ./SNMP_info line 762. DBD::mysql::db do failed: Incorrect key file for table: 'SNMP_ipAddrTable'. Try to repair it at /usr/local/myNMS/bin/SNMP_info line 788.
myNMS> isamchk NMS/SNMP_ipAddrTable Checking ISAM file: NMS/SNMP_ipAddrTable Data records: 1356 Deleted blocks: 3 - check file-size - check delete-chain - check index reference - check data record references index: 1 isamchk: error: Found 1350 keys of 1356 ISAM-table 'NMS/SNMP_ipAddrTable' is corrupted Fix it using switch "-r" or "-o" myNMS> isamchk -r NMS/SNMP_ipAddrTable - recovering ISAM-table 'NMS/SNMP_ipAddrTable.ISM' Data records: 1356 - Fixing index 1 - Fixing index 2 - Fixing index 3 myNMS> isamchk NMS/SNMP_ipAddrTable Checking ISAM file: NMS/SNMP_ipAddrTable Data records: 1356 Deleted blocks: 0 - check file-size - check delete-chain - check index reference - check data record references index: 1 - check data record references index: 2 - check data record references index: 3
Another example:
Examining the code of the Query script (symlinked as Query.cgi) shows that one of the tables being accessed is SNMP_idAddrTable, so isamchk is run to check this table.DBD::mysql::st execute failed: Got error 127 from table handler at /export/www/noc/Query.cgi line 1637.
myNMS> isamchk NMS/SNMP_ipAddrTable Checking ISAM file: NMS/SNMP_ipAddrTable Data records: 1859 Deleted blocks: 30 - check file-size isamchk: error: Size of datafile is: 83028 Should be: 83116 - check delete-chain isamchk: error: delete-link-chain corrupted - check index reference - check data record references index: 1 isamchk: error: Found key at page 57344 that points to record outside datafile ISAM-table 'NMS/SNMP_ipAddrTable' is corrupted Fix it using switch "-r" or "-o"
Alternatively isamchk can been run against all tables, using the -s or --silent flag to report only errors found :
myNMS> isamchk -s NMS/*.ISM isamchk: ISAM file /DATA/mySQLdata/NMS/SNMP_ipAddrTable.ISM isamchk: error: Size of datafile is: 58300 Should be: 112992 isamchk: error: Found key at page 1024 that points to record outside datafile ISAM-table '/DATA/mySQLdata/NMS/SNMP_ipAddrTable.ISM' is corrupted Fix it using switch "-r" or "-o"
Sometimes even the -r (--recover) option will not fix the problem (as shown by continuation of the symptoms, and by isamchk continuing to report errors in the table) and the -o or --safe-recover old recovery method ("slower than '-r' but can handle a couple of cases that '-r' cannot handle") is required:
In extreme cases it may be necessary to shut down and restart mysql:myNMS> isamchk -o /DATA/mySQLdata/NMS/SNMP_ipAddrTable - recovering ISAM-table '/DATA/mySQLdata/NMS/SNMP_ipAddrTable.ISM' Data records: 1350 Data records: 1325 scinfo@sunm2> isamchk /DATA/mySQLdata/NMS/SNMP_ipAddrTable Checking ISAM file: /DATA/mySQLdata/NMS/SNMP_ipAddrTable Data records: 1325 Deleted blocks: 0 - check file-size - check delete-chain - check index reference - check data record references index: 1 - check data record references index: 2 - check data record references index: 3
then as unix root:mysqladmin --user=root shutdown
/etc/init.d/mysql.server start
There have been instances where data in a switch's SNMP_system and SNMP_ipAddrTable does not correspond with
its SNMP_ifTable and dot1d table, as seen by comparing IP addresses in the SNMP_ipAddrTable and those in the dot1d table
e.g.
This is probably caused by bugs in the SNMP_info functions updating devices' SNMP and dot1d table info when some aspect of the device's configuration (e.g. IP address) changed. To remedy this delete the device in the mysql tool:
Then re-discover the device manually:myNMS> DB_maint --delete-device NMS 947197967 Deleting device 947197967 from database NMS tables: SNMP_system SNMP_ifTable SNMP_ipAddrTable dot1d MAC_connections - DONE
SNMP_info --snmp {IP address of switch} SNMP_info --dot1d {IP address of switch}