Skip to content

Instantly share code, notes, and snippets.

View victorpendleton's full-sized avatar

victorpendleton

View GitHub Profile
@victorpendleton
victorpendleton / skip_gtid.sql
Last active October 4, 2017 15:14
How to skip MySQL replication errors using GTIDs
SHOW SLAVE STATUS\G
-- Grab Primary Host from `Retrieved_Gtid_Set`
-- Retrieved_Gtid_Set: PRIMARY_GUID:1234567
-- Find what value has been executed from primary from Executed_Gtid_Set
-- Executed_Gtid_Set: PRIMARY_GUID:123455
STOP SLAVE;
-- Set the gtid to next value
SET GTID_NEXT ='PRIMARY_GUID:123456';
begin; commit;
set gtid_next = 'AUTOMATIC';
@victorpendleton
victorpendleton / view_host_port.sql
Created April 7, 2017 15:50
View running mysql processes by host/port
SELECT p.ID
, p.User
, SUBSTRING(p.Host, 1, LOCATE(':', p.Host) -1) AS Host
, SUBSTRING(p.Host, LOCATE(':', p.Host) + 1) AS Port
, ROUND(p.Time/60, 2) Mins
, p.command
, p.State
, p.rows_sent
, p.rows_examined
, SUBSTRING(p.INFO, 0, 50) Query
@victorpendleton
victorpendleton / active_transactions.sql
Last active January 27, 2018 13:13
View active transactions
-- View processes with transaction information
SELECT p.id
, p.user
, substring(p.host, 1, IF( (locate(':', p.host)-1)<0, LENGTH(p.host), locate(':', p.host)-1 ) ) as host
, SUBSTRING(p.Host, LOCATE(':', p.Host) + 1) AS Port
, p.command
, t.trx_started AS transaction_start_time
, p.time
, p.time/60 as minutes
, p.state
@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"
@victorpendleton
victorpendleton / full_innobackupex
Last active March 20, 2017 17:26
Perform full backup using Pecona 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}"
socket="${instancedirectory}/mysql.sock"
config="${instancedirectory}/mysql.cnf"
targetdirectory="${backupdirectory}/${DATE}/"
@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
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
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