Monday, 26 October 2009

Version 1.1.3 of improved Cacti graphs for MySQL released

Version 1.1.3 of improved Cacti graphs for MySQL released: "

I’ve just released version 1.1.3 of the Cacti templates I wrote for MySQL. This is a bug-fix release only, and affects only ss_get_mysql_stats.php. To upgrade from the previous release, upgrade ss_get_mysql_stats.php. Don’t forget to save and restore your configuration options, if any. (Note that there is a feature to help with this: you can keep configuration options in ss_get_mysql_stats.php.cnf to avoid making them in ss_get_mysql_stats.php.)



Next up: actual template changes! More graphs!



The changelog follows.



2009-10-24: version 1.1.3

* This is a bug-fix release only, and contains no template changes.
* To upgrade from the previous release, upgrade ss_get_mysql_stats.php.
* MySQL 5.1 broke backwards compatibility with table_cache (issue 63).
* Added a version number to the script (partial fix for issue 79).
* Added a test suite (issue 76, issue 59).
* Math operations were done in MySQL instead of PHP (issue 25).
* SHOW STATUS values didn't override SHOW INNODB STATUS parsing (issue 24).
* Long error messages were not appearing in the Cacti log.
* SHOW INNODB STATUS parsing for unpurged_txns was broken.
* SHOW INNODB STATUS parsing for innodb_lock_structs was broken.
* SHOW INNODB STATUS parsing for pending_log_flushes was broken (issue 62).
* SHOW INNODB STATUS parsing for pending_buf_pool_flushes was broken.
* SHOW INNODB STATUS parsing for pending_ibuf_aio_reads was broken.
* SHOW INNODB STATUS parsing for pending_aio_log_ios was broken.
* SHOW INNODB STATUS parsing for pending_aio_sync_ios was broken.
* Made SHOW INNODB STATUS parsing less sensitive to false positive matches.


Related posts:

  1. Version 1.1.2 of improved Cacti templates released I’ve
  2. Maatkit version 4334 released Maatkit ve
  3. Maatkit version 3329 released Maatkit ve


Related posts brought to you by Yet Another Related Posts Plugin.


PlanetMySQL Voting:
Vote UP /
Vote DOWN"

Sunday, 25 October 2009

What is the difference among VIRT, RES, and SHR in top output

What is the difference among VIRT, RES, and SHR in top output: "VIRT stands for the virtual size of a process, which is the sum of memory it is actually using, memory it has mapped into itself (for instance the video card's RAM for the X server), files on disk that have been mapped into it (most notably shared libraries), and memory shared with other processes. VIRT represents how much memory the program is able to access at the present moment.

RES stands


"

How to Tune Swap Setting on Linux for Maximum Performance

How to Tune Swap Setting on Linux for Maximum Performance: "HANDLE WITH CARE

Since 2.6, there has been a way to tune how much Linux favors swapping out to disk compared to shrinking the caches when memory gets full.

ghoti adds: 'When an application needs memory and all the RAM is fully occupied, the kernel has two ways to free some memory at its disposal: it can either reduce the disk cache in the RAM by eliminating the oldest data or it may swap some


"

Use MySQL? You need Maatkit

Use MySQL? You need Maatkit: "

Maatkit is a pretty useful set of utilities for MySQL. From their site:


You can use Maatkit to prove replication is working correctly, fix corrupted data, automate repetitive tasks, speed up your servers, and much, much more.

One of the first things you can do after installing the toolkit (which may already be installed if you are running CentOS or Debian) is to run the mk-audit utility. It will give you a nice summary of your server, as well as point out potential problems in your configuration.


Here's a list of all the utilities included in Maatkit:




  • mk-archiver Archive rows from a MySQL table into another table or a file.

  • mk-audit Analyze, summarize and report on MySQL config, schema and operation

  • mk-checksum-filter Filter checksums from mk-table-checksum.


  • mk-deadlock-logger Extract and log MySQL deadlock information.

  • mk-duplicate-key-checker Find duplicate indexes and foreign keys on MySQL tables.

  • mk-fifo-split Split files and pipe lines to a fifo without really splitting.

  • mk-find Find MySQL tables and execute actions, like GNU find.

  • mk-heartbeat Monitor MySQL replication delay.


  • mk-kill Kill MySQL queries that match certain criteria.

  • mk-loadavg Watch MySQL load and take action when it gets too high.

  • mk-log-player Split and play MySQL slow logs.

  • mk-parallel-dump Dump sets of MySQL tables in parallel.

  • mk-parallel-restore Load files into MySQL in parallel.


  • mk-profile-compact Compact the output from mk-query-profiler.

  • mk-query-digest Parses logs and more. Analyze, transform, filter, review and
    report on queries.

  • mk-query-profiler Execute SQL statements and print statistics, or measure
    activity caused by other processes.

  • mk-show-grants Canonicalize and print MySQL grants so you can effectively
    replicate, compare and version-control them.

  • mk-slave-delay Make a MySQL slave server lag behind its master.


  • mk-slave-find Find and print replication hierarchy tree of MySQL slaves.

  • mk-slave-move Move a MySQL slave around in the replication hierarchy.

  • mk-slave-prefetch Pipeline relay logs on a MySQL slave to pre-warm caches.

  • mk-slave-restart Watch and restart MySQL replication after errors.

  • mk-table-checksum Perform an online replication consistency check, or
    checksum MySQL tables efficiently on one or many servers.


  • mk-table-sync Synchronize MySQL tables efficiently.

  • mk-upgrade Execute SQL statements against two MySQL servers and compare the results.

  • mk-visual-explain Format EXPLAIN output as a tree.



PlanetMySQL Voting:
Vote UP /
Vote DOWN"

Friday, 23 October 2009

Secure Your Server – Tips for DBAs

Secure Your Server – Tips for DBAs: "It has been the responsibility of the DBA to implement a security strategy, at least on the database level. All DBAs should take action, if not already, by taking a proactive approach to this crucial part of database administration. For this post I have compiled a list of general best practices below.



-- The List

1. Make sure that ALL root level accounts have strong passwords and apply them using hashes not plain text. Otherwise anyone can connect as root without a password and be granted all privileges.



2. For ALL other accounts use passwords and apply them using hashes not plain text.

A good practice is to use the following:



mysql> grant SELECT, INSERT……. ON `database`.* to ‘user’@’10.%’ IDENTIFIED BY ‘*9B9C8E678DB2D62877E829D633535CBEB2B7E6E0’;



NOTE: make sure you are using HASHS and not plain text!

If you run something like below…



mysql> update user set password = password(‘somepassword’) where user = ‘someuser’;

Make sure you remove it from the ~/.mysql_history file in your home dir and or roots home directory. Otherwise, if your server becomes compromised, the intruder can take full advantage of this file and do more damage.



3. Give permissions only as needed and use different logins for different purposes.



NOTE: given that column level permissions hurt performance you should try and stick to table, at the lowest, and database level permissions.



4. Avoid using FQDN or hostnames when granting access. Try to keep it to a subnet (Example: 10.0.2.%).



5. Avoid having the MySQL server open to the web by using ‘%’ for any user. Although remote exploits are few and far between, it is just better not to risk it.



6. Remove ALL blank user accounts. Even if they just have USAGE!



mysql> DELETE from user WHERE user = ‘’;



7. Remove the following from the mysql.db table



mysql> DELETE from mysql.db WHERE Db = ‘test’ OR Db = ‘test\_%’;



You might ask why for the above removal, well, here is an explanation…



Let’s say you have many different databases on a single MySQL instance where the users control the names of their databases. The traditional rules apply like database name have to be unique, but some of these users have the same idea; adding a test database to their MySQL instance. Given that test is already taken on the server one user would create a database named test_a and another would create test_b. With the grant in the mysql.db table, Db = ‘test\_%’, BOTH users would have read and write access to each others database. If the overall goal is keep users from seeing each others databases than the Db = ‘test\_%’ grant must be removed.



A long explanation but I have seen it happen!
PlanetMySQL Voting:
Vote UP /
Vote DOWN"

Thursday, 22 October 2009

Basics of MySQL failover (using replication)

Basics of MySQL failover (using replication): "

For easy MySQL failover, replication is a great solution. This post will cover the basics of performing a failover in case your master dies.


First, setup one-way replication (or two-way, but don't plan to use both servers for writes at the same time). Next, you'll want to direct all activity, or at least the writes, to the master. If the master dies, there are two major concerns:



  1. Redirecting the clients to the slave. There are several ways to handle this, such as Heartbeat or MySQL's JDBC driver.

  2. Checking if the slave is caught up. This is trickier. If the master's binary logs are still available, then you can do SHOW SLAVE STATUS on the slave and compare the READ_MASTER_LOG_POS to the master's binary log. For example, if SHOW SLAVE STATUS shows:
    Master_Log_File: localhost-bin.000051
    Read_Master_Log_Pos: 605


    Then look at the master's binary log files. A long listing will do the trick:



    ls -l *bin*

    -rw-rw---- 1 mysql mysql 698 2009-10-08 18:24 localhost-bin.000051





    Note that the binary log has a size of 698 bytes. Yet the slave only read up to byte position 605. So you can manually execute the activity that the slave missed:

    mysqlbinlog --start-position=605 localhost-bin.000051 | mysql -h slave-host-name






You may want to manually get the slave up-to-date before failing over. Or you can keep the slave read-only until you catch the slave up, then turn off read-only by doing SET GLOBAL read_only=0;


You may want to setup replication in both directions (sometimes called 'master-master' or two-way replication). This is a tricky setup if both servers are actively doing updates. But if you know that only one of the servers is updating at any one time, then it works quite well. Once you've failed-over to the slave, it is now acting as a master. Any updates done on this server can be replicated back to the other server when it comes back up.


This solution is not perfect and may not be suitable for all situations. There is potential data loss (possibly unknown data loss) if the binary logs are no longer available on the master. For some scenarios it is better to have additional means of failover such as MySQL Cluster or DRBD for localized failures.


PlanetMySQL Voting:
Vote UP /
Vote DOWN"

Wednesday, 21 October 2009

How to capture debugging information with mk-loadavg

How to capture debugging information with mk-loadavg: "

Maatkit’s mk-loadavg tool is a helpful way to gather information about infrequent conditions on your database server (or any other server, really). We wrote it at Percona to help with those repeated cases of things like “every two weeks, my database stops processing queries for 30 seconds, but it’s not locked up and during this time there is nothing happening.” That’s pretty much impossible to catch in action, and these conditions can take months to resolve without the aid of good tools.



In this blog post I’ll illustrate a very simple usage of mk-loadavg to help in solving a much smaller problem: find out what is happening on the database server during periods of CPU spikes that happen every so often.



First, set everything up.




  1. Start a screen session: screen -S loadmonitoring. If you don’t have screen, you can run mk-loadavg as a daemon, but it’s much better to use screen in my opinion.

  2. Get mk-loadavg. For purposes of this blog post, I’m going to get the latest trunk code, because I know a bug or two has been fixed since the last release. wget http://www.maatkit.org/trunk/mk-loadavg

  3. Create a directory to hold the collected information in files. mkdir collected



Next let’s set up a script that mk-loadavg can use to gather some information when it detects a high CPU condition. Save the contents of this script as “collect-stats.sh”. The script will gather about 30 seconds worth of statistics. It uses a simple sentinel file /tmp/gatherinfo to prevent multiple occurrences from gathering statistics at the same time. (This is intentionally simple for demo purposes.)




#!/bin/bash

if [ -f /tmp/gatherinfo ]; then exit 0; fi
touch /tmp/gatherinfo
d=`date +%F-%T`
echo "gathering info for $d"
ps -eaf >> collected/$d-ps 2>&1 &
top -bn1 > collected/$d-top 2>&1 &
mysql -e 'show innodb status\G show full processlist\G' >> collected/$d-innodbstatus 2>&1 &
vmstat 1 30 >collected/$d-vmstat 2>&1 &
iostat -dx 1 30 >collected/$d-iostat 2>&1 &
mysqladmin ext -i1 -c30 > collected/$d-mysqladmin 2>&1 &
sleep 30
ps -eaf >> collected/$d-ps 2>&1 &
mysql -e 'show innodb status\G show full processlist\G' >> collected/$d-innodbstatus 2>&1 &
rm /tmp/gatherinfo


Now make the script executable: chmod +x collect-stats.sh. At this point we’re ready to start working. Let’s fire the stats-collection script when the system’s user CPU goes above 40%.




perl mk-loadavg --watch "Server:vmstat:us:>:40" --interval 1 --execute collect-stats.sh


If the CPU goes over 40%, you'll get a bunch of files in the collected directory, with helpful information to diagnose the problem. This example usage is pretty similar to a real-life one I set up recently. It enabled me to take a methodical approach to the problem:


  1. From the top output I was able to identify that MySQL was causing the spike.

  2. I then looked at the SHOW STATUS output to see what the database server was doing, using mext as a helper.

  3. From Select_full_scan and Handler_read_rnd_next I isolated table scans as a problem.

  4. From the saved SHOW PROCESSLIST I found problem queries and optimized them.



You would be right if you said there are much better tools for finding problem queries -- but remember two things: 1) sometimes clients ask for the lightweight, short-term solution that can be set up in about 5 minutes and checked the next day; and 2) when it is unclear that queries are the problem, setting up only a query monitor is stabbing in the dark and will not get results.



In addition to watching vmstat to measure system CPU usage, mk-loadavg can watch many other things, such as the MySQL server's SHOW PROCESSLIST, parsing values from SHOW INNODB STATUS, and so on.



Related posts:

  1. A metric for MySQL load average If you wer
  2. Maatkit version 3119 released Your month
  3. An alternative to the MySQL Query Analyzer MySQL just


Related posts brought to you by Yet Another Related Posts Plugin.


PlanetMySQL Voting:
Vote UP /
Vote DOWN

"

Sike's shared items