Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View aaronbbrown's full-sized avatar

Aaron Brown aaronbbrown

View GitHub Profile
@aaronbbrown
aaronbbrown / restartslaveonlag
Created December 4, 2011 00:28
Restart slave when it lags too much
#!/bin/bash
U=user
P=pass
MYSQLCMD="mysql -u $U -p$P -BN -e"
while : ; do
LAG=$($MYSQLCMD "select now()-ts as behind_by from maatkit.heartbeat limit 1;" | awk -F. '{print $1}')
echo "$(date) $LAG"
if [[ $LAG -gt 120 ]]; then
@aaronbbrown
aaronbbrown / restart_slave_binlog_pos.sh
Created December 4, 2011 00:36
Restart slave if the binary log position doesn't change
#!/bin/bash
U=user
P=pass
MYSQLCMD="mysql -u $U -p$P -e"
SECS=60
OLDLOGPOS=1
while : ; do
LOGPOS=$($MYSQLCMD "SHOW SLAVE STATUS\G" | grep Exec_Master_Log_Pos | awk '{print $2}')
echo "$(date) pos: $LOGPOS old pos: $OLDLOGPOS"
@aaronbbrown
aaronbbrown / gist:1732430
Created February 3, 2012 20:49
mtr time warner packet loss
My traceroute [v0.80]anders.borg.lan (0.0.0.0) Fri Feb 3 10:51:27 2012
Keys: Help Display mode Restart statistics Order of fields quit
Packets Pings
Host Loss% Snt Last Avg Best Wrst StDev
1. router.borg.lan 0.0% 7 1.1 1.1 0.7 1.4 0.2
2. 10.117.128.1 83.3% 7 9.1 9.1 9.1 9.1 0.0
3. vlan109.que7600-pv-1.twalb.com
@aaronbbrown
aaronbbrown / gist:1733942
Created February 4, 2012 00:11
packet loss
My traceroute [v0.80]gaeta-wifi.borg.lan (0.0.0.0) Fri Feb 3 19:08:50 2012
Resolver: Received error response 2. (server failure)er of fields quit
Packets Pings
Host Loss% Snt Last Avg Best Wrst StDev
1. router.borg.lan 0.0% 95 1.3 1.6 1.0 10.1 1.2
2. 10.117.128.1 44.2% 95 7.5 12.9 6.6 49.0 7.2
3. vlan109.que7600-pv-1.twalb.com 38.9% 95 9.9 17.1 7.0 94.2 15.0
@aaronbbrown
aaronbbrown / gist:1740562
Created February 4, 2012 22:08
analyze table blog processlist
mysql> SELECT * FROM INFORMATION_SCHEMA.PROCESSLIST WHERE INFO <> 'NULL' ORDER BY TIME;
*************************** 1. row ***************************
ID: 19210373
USER: me
HOST: localhost
DB: production
COMMAND: Query
TIME: 0
STATE: executing
INFO: SELECT * FROM INFORMATION_SCHEMA.PROCESSLIST WHERE INFO <> 'NULL' ORDER BY TIME
@aaronbbrown
aaronbbrown / gist:1740568
Created February 4, 2012 22:09
analyze table blog mysql.err
83109 production.table Locked - write High priority write lock
83109 production.table Locked - read Low priority read lock
@aaronbbrown
aaronbbrown / gist:1740615
Created February 4, 2012 22:16
analyze table blog reproduce 2
session1> SELECT RUN_LONG_TIME FROM table;
session2> ANALYZE TABLE table;
session3> SELECT * FROM table WHERE id=123;
@aaronbbrown
aaronbbrown / gist:1740580
Created February 4, 2012 22:11
analyze table blog reproduce 1
session1> SELECT RUN_LONG_TIME FROM table;
session2> SELECT * FROM table WHERE id = 123
------- TRX HAS BEEN WAITING 42 SEC FOR THIS LOCK TO BE GRANTED:
TABLE LOCK table `db`.`table` trx id 4617 lock mode AUTO-INC waiting
------------------
TABLE LOCK table `db`.`table` trx id 4617 lock mode AUTO-INC waiting
@aaronbbrown
aaronbbrown / gist:2245742
Created March 30, 2012 01:58
Exclusion Query Notes (employees)
$ (for x in {1..100}; do echo 'select * from departments d where (select count(*) from dept_emp de where d.dept_no = de.dept_no) = 0;'; echo; done ) | ./mk-query-profiler -u root --database=employees
+----------------------------------------------------------+
| 100 (0.1104 sec) |
+----------------------------------------------------------+
__ Overall stats _______________________ Value _____________
Total elapsed time 11.596
Questions 100
COMMIT 0