<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Admon Home &#187; Databases</title>
	<atom:link href="http://www.admon.org/databases/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.admon.org</link>
	<description>Linux System Administration</description>
	<lastBuildDate>Wed, 08 Feb 2012 10:24:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>MySQL 5.5.15 GA Released</title>
		<link>http://www.admon.org/mysql-5-5-15-ga-released/</link>
		<comments>http://www.admon.org/mysql-5-5-15-ga-released/#comments</comments>
		<pubDate>Fri, 29 Jul 2011 04:01:02 +0000</pubDate>
		<dc:creator>joseph</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[release]]></category>

		<guid isPermaLink="false">http://www.admon.org/?p=910</guid>
		<description><![CDATA[MySQL 5.5.15 GA has been released in 28 July 2011. Functionality Added or Changed The undocumented &#8211;all option for perror is deprecated and will be removed in MySQL 5.6. Bugs Fixed InnoDB Storage Engine: A failed CREATE INDEX operation for an InnoDB table could result in some memory being allocated and not freed. This memory [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-758" title="mysql" src="http://www.admon.org/wp-content/uploads/2010/01/mysql.jpg" alt="MySQL database" width="150" height="150" />MySQL 5.5.15 GA has been released in 28 July 2011.</p>
<p><strong>Functionality Added or Changed</strong></p>
<div>
<ul>
<li>The undocumented <em>&#8211;all</em> option for <a title="4.8.1. perror — Explain Error Codes" href="http://dev.mysql.com/doc/refman/5.5/en/perror.html"><strong>perror</strong></a> is deprecated and will be removed in MySQL 5.6.</li>
</ul>
</div>
<p><strong>Bugs Fixed</strong></p>
<ul>
<li><strong>InnoDB Storage Engine</strong>: A failed <em>CREATE INDEX</em> operation for an <em>InnoDB</em> table could result in some memory being allocated and not freed. This memory leak could affect tables created with the <em>ROW_FORMAT=DYNAMIC</em> and <em>ROW_FORMAT=COMPRESSED</em> settings. (Bug #12699505)<span id="more-910"></span></li>
<li><strong>Partitioning</strong>: Auto-increment columns of partitioned tables were checked even when they were not being written to. In debug builds, this could lead to a crash of the server. (Bug #11765667, Bug #58655)</li>
<li><strong>Partitioning</strong>: The <a href="http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_unix-timestamp"><em>UNIX_TIMESTAMP()</em></a> function was not treated as a monotonic function for purposes of partition pruning. (Bug #11746819, Bug #28928)</li>
<li><strong>Replication</strong>: If a <a title="12.2.6. LOAD DATA INFILE       Syntax" href="http://dev.mysql.com/doc/refman/5.5/en/load-data.html"><em>LOAD DATA INFILE</em></a> statement—replicated using statement-based replication—featured a <a title="10.4.5. The SET Type" href="http://dev.mysql.com/doc/refman/5.5/en/set.html"><em>SET</em></a> clause, the name-value pairs were regenerated using a method (<em>Item::print()</em>) intended primarily for generating output for statements such as <a title="12.8.2. EXPLAIN Syntax" href="http://dev.mysql.com/doc/refman/5.5/en/explain.html"><em>EXPLAIN EXTENDED</em></a>, and which cannot be relied on to return valid SQL. This could in certain cases lead to a crash on the slave.To fix this problem, we now name each value in its original, user-supplied form, and use that to create <a title="12.2.6. LOAD DATA INFILE       Syntax" href="http://dev.mysql.com/doc/refman/5.5/en/load-data.html"><em>LOAD DATA INFILE</em></a>statements for statement-based replication. (Bug #11902767, Bug #60580)See also Bug #34283, Bug #11752526, Bug #43746.</li>
<li>Compiling the server with maintainer mode enabled failed for <strong>gcc</strong> 4.6 or higher. (Bug #12727287)</li>
<li>The option-parsing code for empty strings leaked memory. (Bug #12589928)</li>
<li>Previously, an inappropriate error message was produced if a multiple-table update for an <em>InnoDB</em> table with a clustered primary key would update a table through multiple aliases, and perform an update that may physically move the row in at least one of these aliases. Now the error message is: <em>Primary key/partition key update is not permitted since the table is updated both as &#8216;<em><em>tbl_name1</em></em>&#8216; and &#8216;<em><em>tbl_name2</em></em>&#8216;</em>(Bug #11882110)See also Bug #11764529.</li>
<li><a title="12.1.6. ALTER TABLE Syntax" href="http://dev.mysql.com/doc/refman/5.5/en/alter-table.html"><em>ALTER TABLE {MODIFY|CHANGE} &#8230; FIRST</em></a> did nothing except rename columns if the old and new versions of the table had exactly the same structure with respect to column data types. As a result, the mapping of column name to column data was incorrect. The same thing happened for <a title="12.1.6. ALTER TABLE Syntax" href="http://dev.mysql.com/doc/refman/5.5/en/alter-table.html"><em>ALTER TABLE DROP COLUMN, ADD COLUMN</em></a> statements intended to produce a new version of table with exactly the same structure as the old version. (Bug #61493, Bug #12652385)</li>
<li>Incorrect handling of metadata locking for <a title="12.4.6.3. FLUSH Syntax" href="http://dev.mysql.com/doc/refman/5.5/en/flush.html"><em>FLUSH TABLES WITH READ LOCK</em></a>for statements requiring prelocking caused two problems:
<div>
<ul>
<li>Execution of any data-changing statement that required prelocking (that is, involved a stored function or trigger) as part of transaction slowed down somewhat all subsequent statements in the transaction. Performance in a transaction that periodically involved such statements gradually degraded over time.</li>
<li>Execution of any data-changing statement that required prelocking as part of transaction prevented a concurrent <a title="12.4.6.3. FLUSH Syntax" href="http://dev.mysql.com/doc/refman/5.5/en/flush.html"><em>FLUSH TABLES WITH READ LOCK</em></a> from proceeding until the end of transaction rather than at the end of the particular statement.</li>
</ul>
</div>
<p>(Bug #61401, Bug #12641342)</li>
<li>The fractional part of the “Queries per second” value in MySQL status output could be displayed incorrectly. (Bug #61205, Bug #12565712)</li>
<li><a title="12.2.6. LOAD DATA INFILE       Syntax" href="http://dev.mysql.com/doc/refman/5.5/en/load-data.html"><em>LOAD DATA INFILE</em></a> incorrectly parsed relative data file path names that ascended more than three levels in the file system and as a consequence was unable to find the file. (Bug #60987, Bug #12403662)</li>
<li>For unknown users, the native password plugin reported incorrectly that no password had been specified even when it had. (Bug #59792, Bug #11766641)</li>
<li>For <a title="13.5. The MyISAM Storage Engine" href="http://dev.mysql.com/doc/refman/5.5/en/myisam-storage-engine.html"><em>MyISAM</em></a> tables, attempts to insert incorrect data into an indexed <em>GEOMETRY</em> column could result in table corruption. (Bug #57323, Bug #11764487)</li>
<li>In debug builds, <em>Field_new_decimal::store_value()</em> was subject to buffer overflows. (Bug #55436, Bug #11762799)</li>
<li>A race condition between loading a stored routine using the name qualified by the database name and dropping that database resulted in a spurious error message: <em>The table mysql.proc is missing, corrupt, or contains bad data</em> (Bug #47870, Bug #11756013)</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.admon.org/mysql-5-5-15-ga-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MongoDB init script on Ubuntu</title>
		<link>http://www.admon.org/mongodb-init-script-on-ubuntu-debian/</link>
		<comments>http://www.admon.org/mongodb-init-script-on-ubuntu-debian/#comments</comments>
		<pubDate>Fri, 21 Jan 2011 05:46:46 +0000</pubDate>
		<dc:creator>joseph</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[init scripts]]></category>
		<category><![CDATA[mongo]]></category>
		<category><![CDATA[update-rc.d]]></category>

		<guid isPermaLink="false">http://planet.admon.org/?p=816</guid>
		<description><![CDATA[By default, MongoDB does not supply any auto start/stop scripts for instance management. Here we&#8217;ll share a smart script to do so. It&#8217;s tested OK on ubuntu servers, and should work on Debian too. All you need to do are two steps: 1, Create a configuration file for MongDB, which is located at /etc/mongodb.conf, here&#8217;s an [...]]]></description>
			<content:encoded><![CDATA[<p>By default, MongoDB does not supply any auto start/stop scripts for instance management. Here we&#8217;ll share a smart script to do so. It&#8217;s tested OK on ubuntu servers, and should work on Debian too. All you need to do are two steps:</p>
<p>1, Create a configuration file for MongDB, which is located at <strong>/etc/mongodb.conf</strong><span id="more-816"></span>, here&#8217;s an example:</p>
<pre># This is an example config file for MongoDB.
dbpath = /var/lib/mongodb
logpath = /var/log/mongodb/mongod.log
bind_ip = 0.0.0.0
noauth = true # use 'true' for options that don't take an argument
verbose = false # to disable, comment out.
fork = true
nohttpinterface = true</pre>
<p>2, Copy and paste the following init.d scripit to <strong>/etc/init.d/mongo </strong>(make sure it&#8217;s executable), then<a title="init script management in Debian" href="http://planet.admon.org/manage-debian-auto-startup-scripts/" target="_blank"> enable the init script by update-rc.d</a>.</p>
<pre>#!/bin/sh
#
# init.d script with LSB support.
#
# Copyright (c) 2007 Javier Fernandez-Sanguino
#
# This is free software; you may redistribute it and/or modify
# it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2,
# or (at your option) any later version.
#
# This is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License with
# the Debian operating system, in /usr/share/common-licenses/GPL;  if
# not, write to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA 02111-1307 USA
#
### BEGIN INIT INFO
# Provides:          mongodb
# Required-Start:    $network $local_fs
# Required-Stop:
# Should-Start:      $named
# Should-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: An object/document-oriented database
# Description:       MongoDB is a high-performance, open source, schema-free
#                    document-oriented  data store that's easy to deploy, manage
#                    and use. It's network accessible, written in C++ and offers
#                    the following features:
#
#                       * Collection oriented storage - easy storage of object-
#                         style data
#                       * Full index support, including on inner objects
#                       * Query profiling
#                       * Replication and fail-over support
#                       * Efficient storage of binary data including large
#                         objects (e.g. videos)
#                       * Auto-sharding for cloud-level scalability (Q209)
#

#                    High performance, scalability, and reasonable depth of
#                    functionality are the goals for the project.
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/bin/mongod
DAEMON_OPTS='-f /etc/mongodb.conf run'
NAME=MongoDB
DESC=database

test -x $DAEMON || exit 0

. /lib/lsb/init-functions

LOGDIR=/var/log/mongodb
PIDFILE=/var/run/$NAME.pid
DIETIME=10                   # Time to wait for the server to die, in seconds
                            # If this value is set too low you might not
                            # let some servers to die gracefully and
                            # 'restart' will not work

LOGFILE=$LOGDIR/$NAME.log  # Server logfile

# Include mongodb defaults if available
if [ -f /etc/default/$NAME ] ; then
        . /etc/default/$NAME
fi

DAEMONUSER=mongodb
# Check that the user exists (if we set a user)
# Does the user exist?
if [ -n "$DAEMONUSER" ] ; then
    if getent passwd | grep -q "^$DAEMONUSER:"; then
        # Obtain the uid and gid
        DAEMONUID=`getent passwd |grep "^$DAEMONUSER:" | awk -F : '{print $3}'`
        DAEMONGID=`getent passwd |grep "^$DAEMONUSER:" | awk -F : '{print $4}'`
    else
        log_failure_msg "The user $DAEMONUSER, required to run $NAME does not exist."
        exit 1
    fi

fi

set -e

running_pid() {
# Check if a given process pid's cmdline matches a given name
    pid=$1
    name=$2
    [ -z "$pid" ] &amp;&amp; return 1
    [ ! -d /proc/$pid ] &amp;&amp;  return 1
    cmd=`cat /proc/$pid/cmdline | tr "\000" "\n"|head -n 1 |cut -d : -f 1`
    # Is this the expected server
    [ "$cmd" != "$name" ] &amp;&amp;  return 1
    return 0
}

running() {
# Check if the process is running looking at /proc
# (works for all users)

    # No pidfile, probably no daemon present
    [ ! -f "$PIDFILE" ] &amp;&amp; return 1
    pid=`cat $PIDFILE`
    running_pid $pid $DAEMON || return 1
    return 0
}

start_server() {
# Start the process using the wrapper
        if [ -z "$DAEMONUSER" ] ; then
            start-stop-daemon --background --start --quiet --pidfile $PIDFILE \
                        --make-pidfile --exec $DAEMON -- $DAEMON_OPTS
            errcode=$?
        else
echo $DAEMONUSER

# if we are using a daemonuser then change the user id
            start-stop-daemon --background --start --quiet --pidfile $PIDFILE \
                        --make-pidfile --chuid $DAEMONUSER \
                        --exec $DAEMON -- $DAEMON_OPTS
            errcode=$?

        fi
        return $errcode
}

stop_server() {
# Stop the process using the wrapper
        if [ -z "$DAEMONUSER" ] ; then
            start-stop-daemon --stop --quiet --pidfile $PIDFILE
            rm $PIDFILE
            errcode=$?
        else
# if we are using a daemonuser then look for process that match
            start-stop-daemon --stop --quiet --pidfile $PIDFILE \
                        --user $DAEMONUSER \
                        --exec $DAEMON
            errcode=$?
        fi

        return $errcode
}
reload_server() {
    [ ! -f "$PIDFILE" ] &amp;&amp; return 1
    pid=pidofproc $PIDFILE # This is the daemon's pid
    # Send a SIGHUP
    kill -1 $pid
    return $?
}

force_stop() {
# Force the process to die killing it manually
        [ ! -e "$PIDFILE" ] &amp;&amp; return
        if running ; then
                kill -15 $pid
        # Is it really dead?
                sleep "$DIETIME"s
                if running ; then
                        kill -9 $pid
                        sleep "$DIETIME"s
                        if running ; then
                                echo "Cannot kill $NAME (pid=$pid)!"
                                exit 1
                        fi
                fi
        fi
        rm -f $PIDFILE
}

case "$1" in
  start)
        log_daemon_msg "Starting $DESC $NAME"
        # Check if it's running first
        if running ;  then
            log_progress_msg "apparently already running"
            log_end_msg 0
            exit 0
        fi
        if start_server ; then
            # NOTE: Some servers might die some time after they start,
            # this code will detect this issue if STARTTIME is set
            # to a reasonable value
            [ -n "$STARTTIME" ] &amp;&amp; sleep $STARTTIME # Wait some time 

            if  running ;  then
                # It's ok, the server started and is running
                log_end_msg 0
            else
                # It is not running after we did start
                log_end_msg 1
            fi
        else
            # Either we could not start it
            log_end_msg 1
        fi
        ;;
  stop)
        log_daemon_msg "Stopping $DESC" "$NAME"
        if running ; then
            # Only stop the server if we see it running
                        errcode=0
            stop_server || errcode=$?
            log_end_msg $errcode
        else
            # If it's not running don't do anything

            log_progress_msg "apparently not running"
            log_end_msg 0
            exit 0
        fi
        ;;
  force-stop)
        # First try to stop gracefully the program
        $0 stop
        if running; then
            # If it's still running try to kill it more forcefully
            log_daemon_msg "Stopping (force) $DESC" "$NAME"
                        errcode=0
            force_stop || errcode=$?
            log_end_msg $errcode
        fi
        ;;
  restart|force-reload)
        log_daemon_msg "Restarting $DESC" "$NAME"
                errcode=0
        stop_server || errcode=$?
        # Wait some sensible amount, some server need this

        [ -n "$DIETIME" ] &amp;&amp; sleep $DIETIME
        start_server || errcode=$?
        [ -n "$STARTTIME" ] &amp;&amp; sleep $STARTTIME
        running || errcode=$?
        log_end_msg $errcode
        ;;
  status)

        log_daemon_msg "Checking status of $DESC" "$NAME"
        if running ;  then
            log_progress_msg "running"
            log_end_msg 0
        else
            log_progress_msg "apparently not running"
            log_end_msg 1
            exit 1
        fi
        ;;
  # Use this if the daemon cannot reload
  reload)
        log_warning_msg "Reloading $NAME daemon: not implemented, as the daemon"

        log_warning_msg "cannot re-read the config file (use restart)."
        ;;

  *)
        N=/etc/init.d/$NAME
        echo "Usage: $N {start|stop|force-stop|restart|force-reload|status}" &gt;&amp;2
        exit 1
        ;;
esac

exit 0</pre>
<p>Finally <a title="MongoDB installation on Debian" href="http://www.mongodb.org/display/DOCS/Ubuntu+and+Debian+packages" target="_blank">Mongodb officially supplies mongodb apt-gettable packages</a> which also contains an initial script, but as per my testings, it has some errors in Ubuntu 9.10.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.admon.org/mongodb-init-script-on-ubuntu-debian/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Flashcache: caching data in SSD disks</title>
		<link>http://www.admon.org/flashcache-caching-data-in-ssd-disks/</link>
		<comments>http://www.admon.org/flashcache-caching-data-in-ssd-disks/#comments</comments>
		<pubDate>Fri, 30 Apr 2010 06:07:31 +0000</pubDate>
		<dc:creator>joseph</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[System Tuning]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[dm-cache]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[flashcache]]></category>

		<guid isPermaLink="false">http://planet.admon.org/?p=600</guid>
		<description><![CDATA[Facebook released a kernel module called Flashcache this wednesday, which is used to speed up MySQL by caching data in faster media like SSD disks.  It&#8217;s only tested for kernel versions 2.6.18 and 2.6.20. As mentioned at Facebook.com: We built Flashcache to help us scale InnoDB/MySQL, but it was designed as a generic caching module [...]]]></description>
			<content:encoded><![CDATA[<p>Facebook released a kernel module called <a href="http://github.com/facebook/flashcache">Flashcache</a> this wednesday, which is used to speed up MySQL by caching data in faster media like SSD disks.  It&#8217;s only tested for kernel versions 2.6.18 and 2.6.20.<span id="more-600"></span></p>
<p>As mentioned at <a href="http://www.facebook.com/">Facebook.com</a>:</p>
<blockquote><p>We built Flashcache to help us scale InnoDB/MySQL, but it was designed as a generic caching module that can be used with any application built on top of any block device. For InnoDB, when the working set does not fit in the InnoDB buffer pool, read latency is significantly improved due to caching more of the working set in faster media, such as SSD&#8217;s. We also improve write performance by first caching writes in SSD&#8217;s and lazily flushing the data back to disk.</p></blockquote>
<p>It looks like its based on the <a href="http://users.cis.fiu.edu/~zhaom/dmcache/index.html">dm-cache</a> work. It&#8217;s nice to see that moving again.</p>
<p>Read more details about Flashcache <a href="http://www.facebook.com/note.php?note_id=388112370932">here at Facebook&#8217;s announcing page</a>, and Flashcache&#8217;s source code is available at <a href="http://github.com/facebook/flashcache">GitHub.com</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.admon.org/flashcache-caching-data-in-ssd-disks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Purge MySQL Binary Logs periodically</title>
		<link>http://www.admon.org/purge-mysql-binary-logs-periodically/</link>
		<comments>http://www.admon.org/purge-mysql-binary-logs-periodically/#comments</comments>
		<pubDate>Tue, 09 Mar 2010 12:22:45 +0000</pubDate>
		<dc:creator>joseph</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[bin-log]]></category>
		<category><![CDATA[logfiles]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[replication]]></category>

		<guid isPermaLink="false">http://planet.admon.org/?p=553</guid>
		<description><![CDATA[If you have binary logging enabled on your MySQL server (i.e. the log-bin parameter is set in the config file), then you may notice a bulk of large files in the MySQL data directory over time. Generally you only need to enable this binary logging if your server is acting as a relication master or [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://planet.admon.org/wp-content/uploads/2010/01/mysql.jpg"><img class="alignleft size-full wp-image-758" title="mysql" src="http://planet.admon.org/wp-content/uploads/2010/01/mysql.jpg" alt="MySQL database" width="150" height="150" /></a>If you have binary logging enabled on your MySQL server (i.e. the <a href="http://dev.mysql.com/doc/refman/5.0/en/binary-log.html">log-bin parameter</a> is set in the config file), then you may notice a bulk of large files in the MySQL data directory over time. Generally you only need to enable this binary logging if your server is acting as a relication master or if you need the ability to do point in time recovery from your latest backup.<span id="more-553"></span></p>
<p>NOTE: On a <a href="http://www.howtoforge.com/mysql_database_replication">MySQL replication</a> environment, users must be careful in deleting binary logs. If slaves are lagging behind the server SOME days, the binary log purge might cause replication to fail. Make sure the logs file are not in use before removing them!</p>
<p>In any case here are some useful examples for purging binary log files easiliy. We&#8217;ll show you two quick ways on deleting the expired bin-log files.</p>
<p>As the purge work here is issued by mysql itself, please make sure you have MySQL-4.1 and later version installed. For version 4.0 and 3.xx, it does not support the following feathers.</p>
<p>1, <strong>Delete MySQL bin-log files by PURGE statement</strong></p>
<p>For example, if you need to delete all binary logs older than 7 days, you just need to run this sql:</p>
<pre>mysql&gt; PURGE BINARY LOGS BEFORE DATE_SUB( NOW( ), INTERVAL 7 DAY);</pre>
<p>To purge all logs before a specific date:</p>
<pre>mysql&gt; PURGE MASTER LOGS BEFORE '2010-03-01 00:00:00';</pre>
<p>To purge logs automatically (every Monday at 3am) you could use a cron job like this:</p>
<pre>0 3 * * mon mysql -uroot -e 'PURGE BINARY LOGS BEFORE DATE_SUB( NOW( ), INTERVAL 7 DAY)'</pre>
<p>2, <strong>Remove bin-log by <a href="http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html">the variable expire_log_days</a></strong></p>
<p>An alternative option is to set &#8220;expire_log_days&#8221; as MySQL server parameter. The default values for expire_log_days is not to purge logs. You can either set it in MySQL&#8217;s configuration file or in a command terminal like below:</p>
<pre>mysql&gt; SET GLOBAL expire_logs_days = 7;
Query OK, 0 rows affected (0.00 sec)

mysql&gt; show variables like 'expire_%';
+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| expire_logs_days |  7    |
+------------------+-------+
1 row in set (0.00 sec)</pre>
<p>When this vavirable takes effect, the log files will be removed automatically on a weekly basis.<br />
For any issues, don&#8217;t forget to raise a thread at our <a href="http://forum.admon.org/databases/">database support forum</a> here.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.admon.org/purge-mysql-binary-logs-periodically/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ways to reset MySQL user password</title>
		<link>http://www.admon.org/ways-to-reset-mysql-user-password/</link>
		<comments>http://www.admon.org/ways-to-reset-mysql-user-password/#comments</comments>
		<pubDate>Fri, 01 Jan 2010 06:10:26 +0000</pubDate>
		<dc:creator>joseph</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[DBA]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[permission]]></category>

		<guid isPermaLink="false">http://planet.admon.org/?p=517</guid>
		<description><![CDATA[How can I change user password under MySQL server when I lost my password? Here&#8217;s I&#8217;ll show two examples. The first example is about how to change password for normal user using Linux command line option, and the second example is on how to reset MySQL DBA password (By default, this user is called root). [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://planet.admon.org/wp-content/uploads/2010/01/mysql.jpg"><img class="alignleft size-full wp-image-758" title="mysql" src="http://planet.admon.org/wp-content/uploads/2010/01/mysql.jpg" alt="MySQL database" width="150" height="150" /></a>How can I change user password under MySQL server when I lost my password?<br />
Here&#8217;s I&#8217;ll show two examples. The first example is about how to change password for normal user using Linux command line option, and the second example is on how to reset MySQL DBA password (By default, this user is called root).<span id="more-517"></span></p>
<p><strong>Reset user password in MySQL</strong><br />
Let&#8217;s assume the normal user&#8217;s name is fatman, follow these steps to start:<br />
1), Login to MySQL server, type following command at shell prompt to login as root</p>
<pre>$ mysql -u root -p</pre>
<p>2), Choose the right database mysql database, it&#8217;s mysql:</p>
<pre>mysql&gt; use mysql;</pre>
<p>3), Change password for user fatman:</p>
<pre>mysql&gt; update user set password=PASSWORD("NEW-PASSWORD-HERE") where User='fatman';</pre>
<p>4), Finally,dont forget to flush privileges:</p>
<pre>mysql&gt; flush privileges;</pre>
<p>You can also use grant to reset a user&#8217;s password, the command is like this:</p>
<pre>mysql&gt; grant select,update,delete,insert on somedb.* to fatman@'somehost' identified by 'NEW-PASSWORD-HERE';</pre>
<p><strong>Reset DBA password in MySQL</strong><br />
When the DBA&#8217;s password lost, things become a little difficult, a restart might needed which is not so good for productive servers. There still have some possibilites to retrieval it without restart mysql service:</p>
<p>1), Is there any user has insert permission on the database &#8220;mysql&#8221;?<br />
If so, he can insert into mysql.user and create another DBA account.</p>
<p>2), Is there any user has super user permissions?<br />
For example, when the user was create like &#8220;<em>GRANT ALL ON *.* TO user@&#8217;localhost&#8217; WITH GRANT OPTION</em>&#8220;, then this use is actually another DBA, you can ask him to reset root&#8217;s password.</p>
<p>If you got no luck till now, we have a common way here to fix the password. We can ask mysql server to bypass its grant tables when starting it. Thus it will not verify user passwords and permissions when they logon. That means all users will have <a href="http://dev.mysql.com/doc/refman/5.1/en/privileges-provided.html">full access to all databases</a> as a database administrator.</p>
<pre>$ /usr/sbin/mysqld --verbose --help | grep skip-grant-tables -A1
  --skip-grant-tables Start without grant tables. This gives all users FULL
                      ACCESS to all tables!
--
skip-grant-tables                 FALSE
skip-slave-start                  FALSE
</pre>
<p>Before making this changes, you need to make sure there&#8217;s no queries running on mysql. Then shutdown mysql instance first (mysql&#8217;s control script will help do that. In RPM based systems, it&#8217;s <em>/etc/init.d/mysql</em>) , and apply this option in the script, and start the service again.</p>
<p>When the DBA password got reset, do forget to remove the changes in mysql&#8217;s control script. If there any issue occures, please dont hesitate to <a href="http://forum.admon.org/linux-databases/">create a topic</a> in our support forum!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.admon.org/ways-to-reset-mysql-user-password/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cassandra: Structured Key-Value based storage system</title>
		<link>http://www.admon.org/cassandra-structured-key-value-based-storage-system/</link>
		<comments>http://www.admon.org/cassandra-structured-key-value-based-storage-system/#comments</comments>
		<pubDate>Fri, 11 Dec 2009 05:53:48 +0000</pubDate>
		<dc:creator>joseph</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Reviews]]></category>
		<category><![CDATA[Cassandra]]></category>
		<category><![CDATA[digg]]></category>
		<category><![CDATA[nosql]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://planet.admon.org/?p=488</guid>
		<description><![CDATA[Cassandra is an open source distributed database management system. It was initially developed by Facebook for storing very large amounts of data. Jeff Hammerbacher, who led the Facebook Data team at the time, has described Cassandra as a BigTable data model running on a Amazon Dynamo-like infrastructure. As described on Wikipedia.org: Cassandra provides a structured [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://incubator.apache.org/cassandra/">Cassandra</a> is an open source distributed database management system. It was initially developed by Facebook for storing very large amounts of data. <a href="http://www.linkedin.com/in/jhammerb">Jeff Hammerbacher</a>, who led the Facebook Data team at the time, <a href="http://www.facebook.com/note.php?note_id=24413138919">has described Cassandra as a BigTable data model running on a Amazon Dynamo-like infrastructure</a>.<span id="more-488"></span></p>
<p>As described on <a href="http://en.wikipedia.org/wiki/Main_Page">Wikipedia.org</a>:</p>
<blockquote><p>Cassandra provides a structured key-value store with eventual consistency. Keys map to multiple values, which are grouped into column families. The column families are fixed when a Cassandra database is created, but columns can be added to a family at any time. Furthermore, columns are added only to specified keys, so different keys can have different numbers of columns in any given family. The values from a column family for each key are stored together, making Cassandra a hybrid between a column-oriented DBMS and a row-oriented store.</p></blockquote>
<p>Facebook released Cassandra as open source in July 2008, it is now an <a href="http://incubator.apache.org/">Apache Incubator project</a>.</p>
<p>Digg announced that it <a href="http://about.digg.com/blog/looking-future-cassandra">started to roll out its use of Cassandra</a> on Sep 9th, 2009. <a href="http://n2.nabble.com/Cassandra-users-survey-td4040068.html#a4040439">Twitter is also working on using Cassandra to replace their currents storage for all tweets</a>.</p>
<p>Twitter has a cluster in production that&#8217;s being populated outside the the user-critical path (ie, the cassandra writing is async).  They also evaluated a lot of solutions, including a custom mysql impl, voldemort, hbase, mongodb, memcachdb, hypertable, etc. Finally they settled on Cassandra.</p>
<p>It&#8217;s really a nice promation for <a href="http://www.computerworld.com/s/article/9135086/No_to_SQL_Anti_database_movement_gains_steam_">the NoSQL Movement</a>, and if you faced similiar issues on processing large amount of data, it&#8217;s suggested to have a try with it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.admon.org/cassandra-structured-key-value-based-storage-system/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tips for Rebuilding MySQL Replication</title>
		<link>http://www.admon.org/tips-for-rebuilding-mysql-replication/</link>
		<comments>http://www.admon.org/tips-for-rebuilding-mysql-replication/#comments</comments>
		<pubDate>Fri, 27 Nov 2009 04:42:53 +0000</pubDate>
		<dc:creator>joseph</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[replication]]></category>

		<guid isPermaLink="false">http://planet.admon.org/?p=462</guid>
		<description><![CDATA[Let&#8217;s keep this post smart. It&#8217;s intended to help you rebuild a crashed MySQL replication. We assume that bin-log has been enabled at the master side. Basically what you need to do is to retrival a snapshot of your master database. It covers three types of information, a snapshot of your current mysql database, and [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://planet.admon.org/wp-content/uploads/2010/01/mysql.jpg"><img class="alignleft size-full wp-image-758" title="mysql" src="http://planet.admon.org/wp-content/uploads/2010/01/mysql.jpg" alt="MySQL database" width="150" height="150" /></a>Let&#8217;s keep this post smart. It&#8217;s intended to help you rebuild a crashed MySQL replication. We assume that bin-log has been enabled at the master side.</p>
<p>Basically what you need to do is to retrival a snapshot of your master database. It covers three types of information, a snapshot of your current mysql database, and master log file name and its running position when this snapshot created.<span id="more-462"></span></p>
<p>You can achieve these information on a running DB like this:</p>
<p>Firstly, frozen your database, in order to disable any writes/updates on the databases. It affects your service for sure. Run two sql queries on a terminal:</p>
<pre>mysql&gt; FLUSH TABLES WITH READ LOCK;
Query OK, 0 rows affected (0.53 sec)

mysql&gt; SHOW MASTER STATUS;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| binlog-db.000004 |  88689   |              |                  |
+------------------+----------+--------------+------------------+
1 row in set (0.01 sec)
</pre>
<p>Keep this session open.  Note that when this session closes, READ LOCK will vanish, and your database will keep changing again.</p>
<p>Then open another terminal to create a copy of your current database files. There are three common ways to do that depending on your system environment. Either of these methods is okay.</p>
<p>1, Use mysqldump to copy all the data.</p>
<p>The disadvantage for mysqldump is that it uses very long time for dumpping large databases. It&#8217;s really unacceptable on productive servers.</p>
<pre>shell$ mysqldump --database db1 db2 &gt; fullbackup-timestamp.sql</pre>
<p>2, Use a LVM snapshot</p>
<p>It only takes some seconds to create a <a href="http://tldp.org/HOWTO/LVM-HOWTO/snapshots_backup.html">LVM snapshot</a>. When your snapshot created, you can copy the snapshot to the slave server.<br />
As all the database files are exactly the same as master DB, you need to make sure the configuration files are similar as well.</p>
<p>3, Use XFS&#8217; frozen feature to do that</p>
<pre>SYSTEM xfs_freeze -f /var/lib/mysql;
SYSTEM YOUR_SCRIPT_TO_CREATE_SNAPSHOT.sh;
SYSTEM xfs_freeze -u /var/lib/mysql;</pre>
<p>After the snapshot createed, you either leave the first session, or submit this query directly:</p>
<pre>mysql&gt; UNLOCK TABLES;</pre>
<p>Finally you need to restore these databases from mysql dump file or the snapshot at slave side. When recovering a large database, time make lots of sense. it might take you one or more days to finish a recovery.<br />
To speed up a mysql recovery, there&#8217;re always some valuable advises from wise man (The wise man here is &#8230; my friend). for example you can disable binlog when importing large sql files.</p>
<pre>mysql&gt; SET SQL_LOG_BIN=0;
Query OK, 0 rows affected (0.00 sec)

mysql&gt; SOURCE /PATH/TO/MYSQL-BACKUP.SQL</pre>
<p>When the files are importing, you need to make sure there are enough disk space avaiable, otherwise, it would crashed again. After importing all data files at slave side,  you need to tell the slave at which point it should read binlog from master:</p>
<pre>mysql&gt; SLAVE STOP;

mysql&gt; SLAVE RESET;

mysql&gt; CHANGE MASTER TO MASTER_HOST='pub.admon.org',MASTER_LOG_FILE='binlog-db.000004',MASTER_LOG_POS=88689;

myql&gt; SLAVE START;</pre>
<p>If all your recovery work is a remote operation, <a href="http://www.rackaid.com/resources/linux-screen-tutorial-and-how-to/">using Screen</a> is highly suggested.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.admon.org/tips-for-rebuilding-mysql-replication/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>13th Workshop on High Performance Transaction Systems</title>
		<link>http://www.admon.org/13th-workshop-on-high-performance-transaction-systems/</link>
		<comments>http://www.admon.org/13th-workshop-on-high-performance-transaction-systems/#comments</comments>
		<pubDate>Wed, 25 Nov 2009 06:38:08 +0000</pubDate>
		<dc:creator>joseph</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[System Tuning]]></category>
		<category><![CDATA[high performance]]></category>
		<category><![CDATA[hpts]]></category>

		<guid isPermaLink="false">http://planet.admon.org/?p=456</guid>
		<description><![CDATA[The 13th international workshop on HPTS held at October 25-28, 2009, Pacific Grove, CA. It&#8217;s all about real systems problems for real systems builders! The papers are listed at its official website. These papers are really really very informative, it&#8217;s suggested to have a read! Every two years, HPTS brings together a lively and opinionated [...]]]></description>
			<content:encoded><![CDATA[<p>The 13th international workshop on <a href="http://www.hpts.ws/index.html">HPTS</a> held at October 25-28, 2009, Pacific Grove, CA. It&#8217;s all about real systems problems for real systems builders! <a href="http://www.hpts.ws/agenda.html">The papers are listed</a> at its official website. These papers are really really very informative, it&#8217;s suggested to have a read!</p>
<p>Every two years, HPTS brings together a lively and opinionated group of participants to discuss and debate the pressing topics that affect today&#8217;s systems and their design and implementation.<span id="more-456"></span></p>
<p>I&#8217;ve downloaded <a href="http://planet.admon.org/papers/HPTS/13th.htm">these papers on my website</a>, you can read them on these links as well:</p>
<p><a href="http://planet.admon.org/papers/HPTS/A-Performance-Puzzle:-B-Tree-Insertions-Are-Slow-on-SSDs.pdf">A Performance Puzzle: B Tree Insertions Are Slow on SSDs</a></p>
<p><a href="http://planet.admon.org/papers/HPTS/A-Sea-Change-is-Coming-on-Transaction-Drivers.pdf">A Sea Change is Coming on Transaction Drivers</a></p>
<p><a href="http://planet.admon.org/papers/HPTS/Availability-in-the-Cloud.pdf">Availability in the Cloud</a></p>
<p><a href="http://planet.admon.org/papers/HPTS/Challenges-and-Lessons-from-Growing-an-e-Commerce-Platform-to-Planet-Scale-.pdf">Challenges and Lessons from Growing an e Commerce Platform to Planet Scale </a></p>
<p><a href="http://planet.admon.org/papers/HPTS/Cloud-DB.pdf">Cloud DB</a></p>
<p><a href="http://planet.admon.org/papers/HPTS/Enterprise-Systems-in-the-Cloud.pdf">Enterprise Systems in the Cloud</a></p>
<p><a href="http://planet.admon.org/papers/HPTS/Flash-on-Compute-Servers.pdf">Flash on Compute Servers</a></p>
<p><a href="http://planet.admon.org/papers/HPTS/H-Store:-A-specialized-architecture-for-high-throughput-OLTP-applications.pdf">H Store: A specialized architecture for high throughput OLTP applications</a></p>
<p><a href="http://planet.admon.org/papers/HPTS/Implementing-Search-in-the-Cloud.pdf">Implementing Search in the Cloud</a></p>
<p><a href="http://planet.admon.org/papers/HPTS/Implications-of-Storage-Class-Memories-on-Software-Architectures.pdf">Implications of Storage Class Memories on Software Architectures</a></p>
<p><a href="http://planet.admon.org/papers/HPTS/Lessons-Learned-Dealing-with-Massive-Scale-and-Slow-Networks-in-China.pdf">Lessons Learned Dealing with Massive Scale and Slow Networks in China</a></p>
<p><a href="http://planet.admon.org/papers/HPTS/Look-at-Clouds-from-Both-Sides.pdf">Look at Clouds from Both Sides</a></p>
<p><a href="http://planet.admon.org/papers/HPTS/Memory-Technologies-for-Data-Intensive-Computing.pdf">Memory Technologies for Data Intensive Computing</a></p>
<p><a href="http://planet.admon.org/papers/HPTS/Meter-Automation.pdf">Meter Automation</a></p>
<p><a href="http://planet.admon.org/papers/HPTS/Mobile-Personal-Sensing:-A-new-driver-for-high-performance-transaction-systems.pdf">Mobile Personal Sensing: A new driver for high performance transaction systems</a></p>
<p><a href="http://planet.admon.org/papers/HPTS/RAMCloud:-Scalable-High-Performance-Storage-Entirely-in-DRAM.pdf">RAMCloud: Scalable High Performance Storage Entirely in DRAM</a></p>
<p><a href="http://planet.admon.org/papers/HPTS/Scalable-transaction-execution-on-multicore-platforms.pdf">Scalable transaction execution on multicore platforms</a></p>
<p><a href="http://planet.admon.org/papers/HPTS/Scaling-Out-without-Partitioning.pdf">Scaling Out without Partitioning</a></p>
<p><a href="http://planet.admon.org/papers/HPTS/SciDB:-Unconventional-Choices-for-Scientific-Computing.pdf">SciDB: Unconventional Choices for Scientific Computing</a></p>
<p><a href="http://planet.admon.org/papers/HPTS/Smart-Grid-Challenges.pdf">Smart Grid Challenges</a></p>
<p><a href="http://planet.admon.org/papers/HPTS/Supporting-Large-Scale-Scientific-and-Engineering-Applications-Using-DBMS-Technology.pdf">Supporting Large Scale Scientific and Engineering Applications Using DBMS Technology</a></p>
<p><a href="http://planet.admon.org/papers/HPTS/Systems-Software-for-Multicore-Processors.pdf">Systems Software for Multicore Processors</a></p>
<p><a href="http://planet.admon.org/papers/HPTS/Trustworthy-Accounting.pdf">Trustworthy Accounting</a></p>
<p><a href="http://planet.admon.org/papers/HPTS/Write-Caching-with-Reduced-Durability.pdf">Write Caching with Reduced Durability</a></p>
<p><a href="http://planet.admon.org/papers/HPTS/Xtremely-Large-File-Systems-for-the-small-collaborative-world.pdf">Xtremely Large File Systems for the small collaborative world</a></p>
<p><a href="http://planet.admon.org/papers/HPTS/Zetta-Enterprise-Cloud-Storage-Service.pdf">Zetta Enterprise Cloud Storage Service</a></p>
<p>Note: These are all in PDF format, and total size for these 26 documents are 76MB in total.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.admon.org/13th-workshop-on-high-performance-transaction-systems/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MPB: Comparison of MyISAM Infobright and MonetDB</title>
		<link>http://www.admon.org/mpb-comparison-of-myisam-infobright-and-monetdb/</link>
		<comments>http://www.admon.org/mpb-comparison-of-myisam-infobright-and-monetdb/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 14:23:25 +0000</pubDate>
		<dc:creator>joseph</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Infobright]]></category>
		<category><![CDATA[MonetDB]]></category>
		<category><![CDATA[MPB]]></category>
		<category><![CDATA[MyISAM]]></category>

		<guid isPermaLink="false">http://planet.admon.org/?p=319</guid>
		<description><![CDATA[This post is originally created by Baron Schwartz at MPB (A.k.a. MySQLPerformanceBlog.com) days ago. What follows is not a realistic benchmark, it&#8217;s not scientific, it&#8217;s just some quick and dirty tinkering. Baron threw up an Ubuntu 9.04 small server on Amazon. (Because there&#8217;s a .deb of MonetDB for it), and created a table with 200 [...]]]></description>
			<content:encoded><![CDATA[<p>This post is originally created by <a href="http://www.percona.com/team/baron-schwartz.html">Baron Schwartz</a> at MPB (A.k.a. <a href="http://www.MySQLPerformanceBlog.com">MySQLPerformanceBlog.com</a>) days ago.</p>
<p>What follows is not a realistic benchmark, it&#8217;s not scientific, it&#8217;s just some quick and dirty tinkering. Baron threw up an Ubuntu 9.04 small server on Amazon. (Because there&#8217;s a .deb of MonetDB for it), and created a table with 200 integer columns and loaded it with random numbers between 0 and 10000. He used default tuning, out of the box, for all three databases.<span id="more-319"></span></p>
<p>The performance testings was led by three simple queries, which is much informative. And of course, the comments are as informative as well, which worths a careful read too.</p>
<p>Read the post at MPB:  <a href="http://www.mysqlperformanceblog.com/2009/09/29/quick-comparison-of-myisam-infobright-and-monetdb/">Quick comparison of MyISAM, Infobright, and MonetDB</a></p>
<p>Thank MPB for the nice work <img src='http://www.admon.org/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.admon.org/mpb-comparison-of-myisam-infobright-and-monetdb/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PostgreSQL Database Performance Tips</title>
		<link>http://www.admon.org/postgresql-database-performance-tips/</link>
		<comments>http://www.admon.org/postgresql-database-performance-tips/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 18:12:07 +0000</pubDate>
		<dc:creator>joseph</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[System Tuning]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://blog.admon.org/?p=190</guid>
		<description><![CDATA[What follows for the next few posts is a somewhat edited version of a set of advice I am giving to a Sun team on redesigning a C++ application which was built for MySQL, ported to PostgreSQL, and never performance optimized. It occurred to me that this advice would be generally useful to the community, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://planet.admon.org/wp-content/uploads/2009/09/postgresql.png"><img class="alignleft size-thumbnail wp-image-769" title="postgresql" src="http://planet.admon.org/wp-content/uploads/2009/09/postgresql-150x150.png" alt="PostgreSQL Logo" width="150" height="150" /></a>What  follows for the next few posts is a somewhat edited version of a set of advice I am giving to a Sun team on redesigning a C++ application which  was built for <a href="http://www.mysql.com">MySQL</a>, ported to <a href="http://www.PostgreSQL.org">PostgreSQL</a>, and never performance  optimized. It occurred to me that this advice would be generally useful  to the community, so here goes. (and yes, I&#8217;ll pick up &#8220;Four Horsemen&#8221; again eventually.)<span id="more-190"></span></p>
<p><strong>Query Writing Rules</strong></p>
<p>For  all database management systems (DBMSes), &#8220;round-trip&#8221; time is significant. This is the amount of time which it takes a query to get  through the the language parser, the driver, across the network  interface, the database parser, the planner, the executor, the parser  again, back across the network interface, through the driver data  handler, and to the client application. DBMSes vary in the amount of  time and CPU they take to process this cycle, and for a variety of  reasons PostgreSQL is a the high end of time and system resources per  round-trip.</p>
<p>Further, PostgreSQL has significant per-transaction  overhead, including log output and visibility rules which need to be  set with each transaction. While you may think that you are not using  transactions for singleton read-only SELECT statement, in fact every  single statement in PostgreSQL is in a transaction. In the absence of  an explicit transaction, the statement itself is an implicit  transaction.</p>
<p>Offsetting this, PostgreSQL is only barely second  to Oracle in processing large complex queries, and has the capability  to handle complex multi-statement transactions with overlapping  concurrency conflicts with ease. We also support cursors, both  scrollable and non-scrollable.</p>
<p><strong>Never use many small selects when one big query could go the job.</strong></p>
<p>It&#8217;s  common in MySQL applications to handle joins in the application code,<br />
that is, by querying the ID from the parent record and then looping  through the child records with that ID manually. This can result in  running hundreds or thousands of queries per user interface screen.  Each of these queries carres 2-6 milleseconds of round-trip time, which  doesn&#8217;t seem significant until you add it up for 1000 queries, at which  point you&#8217;re losing 3-5 seconds to round trip time. Comparatively,  retrieving all of those records in a single query only takes a few  hundred milleseconds, a time savings of 80%.</p>
<p><strong>Group many small UPDATES, INSERTS or DELETEs into large statements, or failing that, large transactions.</strong></p>
<p>First, the lack of subselects in early versions of MySQL has caused  application developers to design their data modification statements  (DML) in much the same way as joins-in-middleware. This is also a bad  approach for PostgreSQL. Instead, you want to take advantage of  subselects and joins in your UPDATE, INSERT and DELETE statements to  try to modify batches in a single statement. This reduces round-trip  time and transaction overhead.</p>
<p>In some cases, however, there is  no single query which can write all the rows you want and you have to  use a bunch of serial statements. In this case, you want to make sure  to wrap your series DML statements in an explicit transaction (e.g.  BEGIN; UPDATE; UPDATE; UPDATE; COMMIT; ). This reduces transaction  overhead and can cut execution time by as much as 50%.</p>
<p><strong>Consider bulk loading instead of serial INSERTS</strong></p>
<p>PostgreSQL  provides a bulk loading mechanism called COPY, which takes  tab-delimited or CSV input from a file or pipe. Where COPY can be used  instead of hundreds or thousands of INSERTS, it can cut execution time  by up to 75%.</p>
<p><strong>DELETE is expensive</strong></p>
<p>It&#8217;s  common for application developers to think that a DELETE statement is  virtually without cost. You&#8217;re just unlinking some nodes, right? Wrong.  DBMSes are not filesystems; when you delete a row, indexes need to be  updated and free space needs to be cleaned up, making a delete in fact  more costly than an insert. Thus applications which habitually delete  all detail rows and replace them with new every time a use makes any  change are saving effort on the application side by pushing it onto the  database. Where possible, this should be replaced with more  discriminating row-replacement behavior, like updating only modified  rows.</p>
<p>Also, when clearing a whole table, always use the TRUNCATE  TABLE statement rather than DELETE FROM TABLE. The former is up to 100 times faster than the latter because it batch processes the whole table  as a unit instead of one row at a time.</p>
<p><strong>Use PREPARE/EXECUTE for query loops</strong></p>
<p>Sometimes  despite your attempts to consolidate loops of near-identical queries  into large statements, it&#8217;s not possible due to the structure of your<br />
application. That&#8217;s what PREPARE &#8230; EXECUTE is for; it allows the  database engine to skip parsing and planning for each query iteration.  For example:</p>
<p>Prepare:<br />
query_handle = query(&#8216;SELECT * FROM TABLE WHERE id = ?&#8217;)(parameter_type = INTEGER)</p>
<p>Then start your loop:<br />
for 1..100<br />
query_handle.execute(i);<br />
end</p>
<p>Classes for prepared statements for C++ are explained in the libpqxx documentation.</p>
<p>This will reduce query execution time in direct proportion to the size of the looped set.</p>
<p><strong>Use connection pools effectively</strong></p>
<p>For a web application, you&#8217;ll find that as much as 50% of your potential  performance can be controlled through your use of, and proper  configuration of, connection pooling. This is because creating and  dropping database connections takes a significant amount of system  time, and excess idle connections still require RAM and system  resources.</p>
<p>There are a number of tools you can use to do  connection pooling on PostgreSQL. A third-party Open Source tool which  is very popular is pgPool. However, for a C++ application HA  requirements, it&#8217;s probably better to use libpqxx&#8217;s native  pseudo-pooling technique called &#8220;lazy connections&#8221; . I suggest  contacting the libpqxx mailing list for more information on how to use  this utility.</p>
<p>With PostgreSQL, you want to have as many  persistent connections (or connection objects) defined as your normal  peak concurrent connection usage. So if max normal usage (first thing  in the morning, say) is 200 concurrent connections from agents, users  and components, then you want to have that many defined so that your  application does not have to wait for new connections during a peak  when they will be slow to fork.</p>
<p><a href="http://www.ittoolbox.com/profiles/josh_berkus" target="_blank">Josh Berkus</a> (PostgreSQL Core Team Member) <a href="http://blogs.ittoolbox.com/database/soup/archives/postgresql-application-performance-tips-part-2-13194" target="_blank">Original Version is here</a>, posted in 11/28/2006, this forwared version is just for track record.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.admon.org/postgresql-database-performance-tips/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

