Skip to content

Instantly share code, notes, and snippets.

View victorpendleton's full-sized avatar

victorpendleton

View GitHub Profile
@victorpendleton
victorpendleton / Calculate innodb log activity
Last active August 29, 2015 14:06
SQL used to calculate MySQL log size based on current usage and compare to actual size
SELECT variable_value into @start
from information_schema.global_status
where variable_name = 'innodb_lsn_current';
SELECT sleep(60);
SELECT variable_value into @end
from information_schema.global_status
where variable_name = 'innodb_lsn_current';
@victorpendleton
victorpendleton / Retrieve checkbox elements
Last active August 29, 2015 14:08
Display value of checked radio button
var rbtn = document.getElementsByName("objname");
var nbtns = rbtn.length;
for (i=0; i<nbtns; i++) {
if (rbtn[i].checked) {
window.alert(rbtn[i].value);
}
}
@victorpendleton
victorpendleton / Track MySQL table stats
Last active January 7, 2016 15:02
Table and event code to track and record mysql table statistics
DROP TABLE IF EXISTS stats_history;
-- Create table
CREATE TABLE `stats_history` (`id` bigint(20) NOT NULL AUTO_INCREMENT,
`runTime` datetime DEFAULT NULL,
`TABLE_SCHEMA` varchar(192) NOT NULL DEFAULT '',
`TABLE_NAME` varchar(192) NOT NULL DEFAULT '',
`ROWS_READ` bigint(21) unsigned NOT NULL DEFAULT '0',
`ROWS_CHANGED` bigint(21) unsigned NOT NULL DEFAULT '0',
`ROWS_CHANGED_X_INDEXES` bigint(21) unsigned NOT NULL DEFAULT '0',
SELECT user
, group_concat(time)
, count(*)
FROM information_schema.processlist
WHERE user NOT IN ('some_user') -- Filter out users
AND time > ## -- Filter by time
AND command NOT IN ('sleep') -- Filter by command
GROUP BY 1
ORDER BY 3;
STOP SLAVE;
SET GTID_NEXT="";
BEGIN; COMMIT;
SET GTID_NEXT="AUTOMATIC";
START SLAVE;
SHOW SLAVE STATUS\G
@victorpendleton
victorpendleton / gist:baf9913895546de012aad8dbe10e9c4a
Last active September 30, 2016 19:44
Get information about active transactions
SELECT t.trx_id
, t.trx_mysql_thread_id
, p.User
, SUBSTRING(p.Host, 1, LOCATE(':', p.Host) -1) AS Host
, SUBSTRING(p.Host, LOCATE(':', p.Host) + 1) AS Port
, t.trx_state
, t.trx_started
, ROUND(p.Time/60, 2) Mins
, p.command
, p.State
SELECT user
, total_connections
, concurrent_connections
, select_commands
, rows_fetched
, table_rows_read
, IF (table_rows_read >= rows_fetched
,ROUND((rows_fetched/table_rows_read), 5) * 100
, 100) as efficiency
FROM information_schema.user_statistics
@victorpendleton
victorpendleton / partition_info.sql
Last active February 16, 2017 21:32
Get MySQL partition information
-- Get the unique PARTITION_EXPRESSION values
SELECT DISTINCT PARTITION_EXPRESSION
FROM information_schema.partitions;
-- Mappings
-- TO_DAYS() => FROM_DAYS()
-- UNIX_TIMESTAMP() => FROM_UNIXTIME()
SELECT TABLE_SCHEMA
, TABLE_NAME
@victorpendleton
victorpendleton / View Postgres Replica Status
Last active March 17, 2017 14:07
Postgres lag and wal file
SELECT '00000001' || LPAD(SUBSTRING(trim(' ' || pg_last_xlog_replay_location() || ' ') FROM 1 FOR position('/' in trim(' ' || pg_last_xlog_replay_location() || ' '))-1), 8, '0') || LPAD(SUBSTRING(trim(' ' || pg_last_xlog_replay_location() || ' ') FROM position('/' in trim(' ' || pg_last_xlog_replay_location() || ' '))+1 FOR 2), 8, '0') as last_wal
, SUBSTRING(trim(' ' || pg_last_xlog_replay_location() || ' ') FROM position('/' in trim(' ' || pg_last_xlog_replay_location() || ' '))+3 ) as last_lsn
, '00000001' || LPAD(SUBSTRING(trim(' ' || pg_last_xlog_receive_location() || ' ') FROM 1 FOR position('/' in trim(' ' || pg_last_xlog_receive_location() || ' '))-1), 8, '0') || LPAD(SUBSTRING(trim(' ' || pg_last_xlog_receive_location() || ' ') FROM position('/' in trim(' ' || pg_last_xlog_receive_location() || ' '))+1 FOR 2), 8, '0') as last_wal_rev
, SUBSTRING(trim(' ' || pg_last_xlog_receive_location() || ' ') FROM position('/' in trim(' ' || pg_last_xlog_receive_location() || ' '))+3 ) as last_lsn_recv
, CASE WHE
@victorpendleton
victorpendleton / partial_innodbbackupex
Last active March 20, 2017 17:15
Perform a surgical pull of MySQL data using Percona innobackupex
#!/bin/bash
# This file contains the user/password combination to connect to the database
source creds.sh
DATE=`date +%Y%m%d`
instancedirectory="/var/lib/"
retval=-1
backupdirectory="${1}"
exportconfig="${2}"
socket="${instancedirectory}/mysql.sock"
config="${instancedirectory}/mysql.cnf"