Posts Tagged Linux

mysql –i-am-a-dummy

Posted by on Thursday, 9 April, 2009

I thought it was a joke when I first heard about it, but the MySQL command line client has this option where you can actually tell it you’re stupid:

 mysql --i-am-a-dummy -uroot test

Otherwise known as --safe-updates , this option prevents MySQL from performing update operations unless a key constraint in the WHERE clause and / or a LIMIT clause are provided, e.g.:

mysql> DELETE FROM bigtable;
ERROR 1175: You are using safe update mode and you
tried to update a table without a WHERE that uses a 
KEY column

This would wipe out bigtable – unless bigtable is an InnoDB table and the command is wrapped in a transaction. (If you don’t use transactions, you should have a lot more to worry about anyway).

See: http://dev.mysql.com/doc/mysql/en/safe-updates.html.

Note that the --safe-updates / --i-am-a-dummy option causes the following statement to be issued on connection:

SET SQL_SAFE_UPDATES=1,SQL_SELECT_LIMIT=1000,
SQL_MAX_JOIN_SIZE=1000000;
From the man page
–safe-updates, –i-am-a-dummy, -U
Allow only those UPDATE and DELETE statements that specify which rows to modify by using key values. If you have set this option in an option file, you can override it by using –safe-updates on the command line. See the section called MYSQL TIPS, for more information about this option.

Website migration from debian.co.nz

Posted by on Tuesday, 7 April, 2009

I’ve been wanting to move the old debian.co.nz onto a more generic name since its more than just debian. Its about Linux.

Ive also made the move for the first time into using somebody elses software for the site rather than my own home rolled stuff, as i really just dont have the time anymore.

Greets go out to those who helped with migrating posts (you can see who they are by who posted em!).

As for more news. The debian and ubnutu repository is going, and the server is now moved offshore. Orcon refused to respond when asked for more bandwidth and 128k international wasnt enough to maintain it. Also gone is the FTP with ISO images, for the same reason.

I have no hard feelings however, I now host on a rimuhosting VPS which has excellent resources, and saves me the hassle of having to deal with hardware and upgrades (PS, I work as a sysadmin at Rimu – and its the most awesome place to work.)

My goal now is to turn the website into more of a community hub for NZ Linux people both new and old, and geeks in general. I welcome you all to post news, gadgets, your own projects, or even how you managed to install Linux on the toaster.

When you post, just post as a Draft, ill review and approve. If I notice anyone who seems particularly into it, i will happily make you an admin who can approve or help manage the website.


Tweak your swappiness

Posted by on Tuesday, 7 April, 2009

In the world of operating system design, a lot of critical decisions are made by the developers concerning how the system uses the limited resources available to it.

Part of the design pertains to memory, and making use thereof. Most modern operating systems go by the theory that “free” can be equated with wasted when it comes to RAM utilisation.

For this reason Linux attempts to use your unused memory for one of two things, disk cache or virtual memory (aka swap).

A disk cache holds files in memory as they are read off the disk (usually also handling tasks like pre-fetching file contents before they’re requested).

On the other hand, virtual memory is (at least perceived to be) used primarily when there is not enough memory available.

Linux also makes use of virtual memory by proactively swapping out inactive tasks once a threshold of inactivity has been reached.

On the face of things this seems a very valid thing to do, after all who wants an application that only does anything once a day slurping up RAM for the rest of the time. Why not swap it out to virtual memory until it needs to do something?

The problem for interactivity is that Linux is not very granular or intelligent about how it manages the inactive tasks, often switching out tasks like instant messenger applications.

Often the whole point of leaving an application open all the time is to allow instant access to it, and swapping it out to disk effectively kills that benefit by creating a delay while you wait for the pages to be swapped back into memory.

Frequently swapping back an inactive application triggers the threshold for swapping out other active applications like the web browser.

The end result could pan out something like this; you’re reading a web page, when you get a message in your IM application, it swaps into ram to notify you, you pause to look at the message long enough for the kernel to decide your browser is inactive, you continue reading your web page, “activating” and swapping your browser back in and then decide to reply to the message, swapping your “inactive” IM program back in.

That’s a lot of disk activity, considering that you may well have enough RAM to contain both applications at the same time.

I’ve chosen a ridiculous worst case scenario to indicate something that might happen if you live in a lake of semi-frozen treacle and it takes 5 minutes for you to change from one application to another, but it’s still quite possible to end up in scenarios like this in the real world without needing to be submerged in viscous goo.

Thankfully the developers of Linux made provision for end users to easily change this behaviour using the /proc virtual filesystem. Here’s how to do it…

echo 0 > /proc/sys/vm/swappiness

The usual default value of swappiness is 60, valid values are from 0 (no pro-active swapping) to 100 (high tendency to swap out inactive tasks).

My opinion is that swapping out tasks before virtual memory is required is generally unhelpful on desktop computers unless you have VERY fast virtual memory so I set swappiness to 0, but using the example and information above you should be able to figure out how to tune swappiness to your liking.
Last-Modified: 2007-03-07 19:38:50