Userscript to make banning MediaWiki spammers easier

Somehow, I’ve come to be responsible for administering two MediaWiki-powered wikis. The main burden is having to ban spammers, which sometimes sign up in batches of 20 at a time.

To help with process, I’ve put together the following browser userscript. On Firefox, you can easily set it up using the Greasemonkey extension. Opera and Chrome have their own facilities.

The script basically makes the default values on the user ban form sane, so I can just click through without fiddling with dropdown and checkboxes. Obviously, the ban has to be permanent. Obviously, I don’t want spammers emailing anyone.

// ==UserScript==
// @name           Blocker
// @namespace
// @include*
// ==/UserScript==

// Set default expiry to 'infinite' or 'indefinite', depending on MediaWiki version
function makeExpiryInfinite () { "use strict";
  // Get the element
  var elExpiry = document.getElementById('wpBlockExpiry');
  if (!elExpiry) { elExpiry = document.getElementById('mw-input-wpExpiry'); }

  // Abort if element not found
  if (!elExpiry || !elExpiry.children) { return; }

  // Find the infinite option
  var expiryNodes = elExpiry.children;
  var index = 0;
  for (var i in expiryNodes) {
    if (expiryNodes[i].label && expiryNodes[i].label in {infinite:1, indefinite:1}) {
      index = i;

  // Set dropdown to the infinite option
  elExpiry.selectedIndex = index;

// Automatically prevent user from sending e-mail
function preventEmail() { "use strict";
  // Find check box
  var elEmailBan = document.getElementById('wpEmailBan');
  if (!elEmailBan) { elEmailBan = document.getElementById('mw-input-wpDisableEmail'); }

  // Abort if it's not there
  if (!elEmailBan) { return; }

  // Check the box
  elEmailBan.checked = true;

// Automatically prevent user from sending e-mail
function reallyBanThatIP() { "use strict";
  // Find check box
  var elHardBlock = document.getElementById('mw-input-wpHardBlock');
  if (!elHardBlock) { elHardBlock = document.getElementById('mw-input-wpHardBlock'); }

  // Abort if it's not there
  if (!elHardBlock) { return; }

  // Check the box
  elHardBlock.checked = true;


I’ve been hearing wonderful things about userscripts for years, but this is the first one I’ve put together for myself. It’s actually very easy to write these, assuming you know Javascript and have tools like Firefox’s Web Console and the Web Developer extension handy.

I’m planning to enhance it a little so that it handles the slightly different form for banning anonymous users, but I’m not sure if it makes sense to submit to any official repository. It helps with running small wikis that have open memberships, so there isn’t any one site I can identify it with. Obviously, it’s not suited for Wikipedia, as they have a very different set of problems.

Edit: Updated the script with better handling for banning anonymous users by IP address.

DB2 Express-C 9.7.5 released with Oracle compatibility

My team just put out DB2 Express-C 9.7.5. The big new feature is Oracle compatibility, which is now available in the free edition. It includes PL/SQL, CLPPlus, and other related things.

DB2 Express-C is a free database. It’s fairly straightforward to install on your own machine or deploy on a public cloud like Amazon EC2 or IBM SmartCloud Enterprise. Disclaimer: I’m the guy who puts together the DB2 virtual images for SCE.

DB2 University is a good place to learn how to use DB2 at your own pace.

SQL6048N A communication error occurred during START or STOP DATABASE MANAGER processing

I’ve written about issues related to “SQL6048N A communication error occurred during START or STOP DATABASE MANAGER processing” before, but I thought I’d add a few short notes.

  1. Your machine needs to be able to ping itself. If it can’t ping itself, it can’t DB2 itself either.
  2. The output of hostname, db2set -all, and cat /home/db2inst1/sqllib/db2nodes.cfg needs to match.

If your machine can’t ping itself, cat /etc/hosts. Chances are, you need to add a line like the following: myhostname.mydomain myhostname

If DB2SYSTEM is set to the wrong value, db2set -g DB2SYSTEM=`hostname` will fix it on Linux.

If db2nodes.cfg has the wrong value, overwrite it with the right one.

Webinar on private clouds, including stuff I’ve been working on

There’s a DB2 Chat with the Lab on Wednesday next week which will cover, among other things, the DB2 images I’ve developed for IBM Workload Deployer over this past while. I recommend checking it out, as the speakers know their stuff and this is a pretty cool product.

Easily Deploy Database Workloads on Private Clouds

Date:                 Wednesday, June 29, 2011 (29.6.2011)
Time:                 12:30 AM – 2:00 PM Eastern Time (ET)
11:30 AM Central / 9:30 AM Pacific / 17:30hrs London / 18:30hrs Frankfurt, Paris / India 10 PM
Speakers:         Sal Vella, Leon Katsnelson, Rav Ahuja, Chris Gruber

As more and more businesses look for ways to reduce costs within IT, their research typically discovers cloud computing. However Public Clouds are not an option for many enterprise workloads and applications with strict security and privacy requirements. Organizations with such needs can benefit from building Private Clouds within their own data centers. In this webcast we will look at a fast path to deploying private clouds for database workloads.

We will specifically look at instant provisioning of DB2 systems and databases in a private cloud infrastructure using the IBM Workload Deployer (IWD), previously called the WebSphere CloudBurst Appliance. We will also look at how IWD can be easily used for implementing complete web application patterns with web servers, application servers (WebSphere), and DB2 database servers with high availability options.

To learn more, please join experts from the IBM labs – Sal Vella, Leon Katsnelson, Rav Ahuja, and Chris Gruber.

Presentation charts will be available from just before the webcast starts.


DB2 images for IBM Workload Deployer

IBM Workload Deployer 3.0 has just come out along with the DB2 images I developed. IWD is a major revision of what was formerly known as WebSphere CloudBurst Appliance.  The idea behind it is that it lets you plug a box into your existing virtualization infrastructure (VMWare, pSeries, etc) and make it feel more like a proper private cloud with image templates, automation, reproducible deployments, monitoring, and such things.

I developed the three DB2 images  and, along with Dustin, the script packages and topology patterns that make them integrate nicely with WebSphere Application Server. Here’s a screenshot of what one of those patterns looks like in the IWD pattern editor:

Highly available cluster pattern on IWD
In addition to the images made available on the appliance, we are making five additional DB2 image templates available for download. They add Red Hat Enterprise Linux as an OS option as well as bump up the DB2 version to V9.7 FP4 and enhance the High Availability enablement on the AIX-based DB2 Enterprise image.

When you hear WebSphere folks talking about “DB2 Hypervisor Edition”, these images are what they are talking about.

I learned a lot about the arcana of Linux and AIX administration developing these, though of course learning a lot about something always highlights how much more one has to learn. Regardless, I’ve harvested some of that for a couple blogposts this past winter, and I hope to post more about it in the coming weeks.

On a side note, if you are interested in more of a Database-as-a-Service rather than Infrastructure-as-a-Service approach, IWD 3.0 also comes with Workload Pattern for DB2. It abstracts things to a higher level by letting you provision databases directly, which can be a nice option to have.

Triggers in DB2 Express-C 9.7.4

My team at IBM recently released DB2 Express-C 9.7.4, the latest and greatest version of our free database.

Raul wrote up a detailed article with the technical nitty-gritty of what’s new. There’s a bunch of different improvements, but one thing that’s caught my eye are the enhancements to triggers.

A trigger is something defined to fire automatically when you insert, update, or delete a row in a table. Starting with 9.7.4, you can basically inline a whole stored procedure in the trigger definition. This is nice because it lets you keep the code for all the different actions on a table together.

Let me quote Raul’s example:


         END IF;

         IF DELETING
         END IF;

         IF (UPDATING AND (N.SALARY > 1.1 * O.SALARY))
         THEN SIGNAL SQLSTATE '75000' SET MESSAGE_TEXT='Salary increase>10%';
         END IF;

Ignore that last part. All salary increases should be > 10%.

Reduce your stress by disabling notifiers, toasts, and every sort of popup

A month ago, I disabled email notification in my Gmail notifier before doing a presentation and neglected to turn it back on later.

It took me a long time to notice the lack of notifications. What I did notice was a reduced level of stress. I was able to effectively concentrate on a single task without unimportant, offtopic notices distracting me. This is enormously important in software development.

Let me quote from Eric S. Raymond’s classic Jargon File:

hack mode n.

a Zen-like state of total focus on The Problem that may be achieved when one is hacking (this is why every good hacker is part mystic). Ability to enter such concentration at will correlates strongly with wizardliness; it is one of the most important skills learned during larval stage. Sometimes amplified as deep hack mode.

Being yanked out of hack mode (see priority interrupt) may be experienced as a physical shock, and the sensation of being in hack mode is more than a little habituating. The intensity of this experience is probably by itself sufficient explanation for the existence of hackers, and explains why many resist being promoted out of positions where they can code. See also cyberspace (sense 3).

Some aspects of hacker etiquette will appear quite odd to an observer unaware of the high value placed on hack mode. For example, if someone appears at your door, it is perfectly okay to hold up a hand (without turning one’s eyes away from the screen) to avoid being interrupted. One may read, type, and interact with the computer for quite some time before further acknowledging the other’s presence (of course, he or she is reciprocally free to leave without a word). The understanding is that you might be in hack mode with a lot of delicate state (sense 2) in your head, and you dare not swap that context out until you have reached a good point to pause. See also juggling eggs.

Joel Spolsky wrote something similar in 2001. The basic idea is that multitasking is inherently wasteful because a context switch between one complicated task and another complicated task has costs. The more often you switch between tasks, the more often you incur the overhead of a context switch.

My advice to you is this: disable your email notifier, disable your Twitter notifier, disable every other sort of notifier you have. They are never as urgent as the task at hand. You’ll only be happier and more productive.

What is DB2 Hypervisor Edition?

Edit: Please see DB2 HV images for IWD.

It’s regular DB2. There’s no DB2 HV or DB2 HE. You use the same DB2 edition whether you are using it on physical hardware or a virtual server in the cloud. In fact, DB2 is fully supported in virtually every virtualized environment.

9 to 5, I’m the lead developer of DB2 database server images for WebSphere CloudBurst Appliance. What’s WCA? Well, it’s a purple box that takes your existing VMWare ESX or ESXi or PowerVM machines and turns them into a private cloud.

WCA has a shiny web interface that makes it easy to deploy patterns of machines running WebSphere (WAS), DB2, etc. and then redeploy the same environment for development, test, production, etc. It’s easy to configure the OSes to update themselves, to get everything to talk to each other, and so on.

The appliance is like a vending machine loaded up with delicious IBM licenses. Want a virtual machine with a DB2 database? Boom, here you go.

WCA is a private cloud solution. If you want to get started right now, we also have DB2 images for public clouds like Amazon EC2 and IBM Cloud, as well as templates targeting RightScale.

In fact, you can try an alpha of the next version of DB2 in the cloud today. Once you are approved, it takes all of ten minutes to get your own server running.

If you already have your very own WebSphere CloudBurst Appliance, you can download DB2 for WCA, get some script packages, or read a technical guide.

Find a list of views marked inoperative

When you drop and recreate a table, DB2 marks any views that query it inoperative. You will get the following error message if you try to query one of them:

View or materialized query table "TRENDADM.IWM_CONVERSION"
 cannot be used because it has been marked inoperative..
 SQLCODE=-575, SQLSTATE=51024, DRIVER=3.61.65

This has changed somewhat in DB2 9.7 with the introduction of DB2_DDL_SOFT_INVAL and auto_reval configuration settings. There are also ways to avoid it using transactions, CREATE OR REPLACE statements, and other measures.

However, suppose you do have some inoperative views, and you’d like to get a list of them. The following query will fetch the list:

SELECT viewname, viewschema, valid
	viewschema = 'TRENDADM'
	AND valid <> 'Y'

Simplify the DB2 9.7 security model

Starting in DB2 9.7, the DB2 security model was changed. Security administration (SECADM) was split off from database administration (DBADM), and users with SECADM permissions could no longer peek at data, at least not by default.

Secure by default is a great practice. It’s fantastic when deploying a production database at a financial institution. However, it’s not so good when you are a new user trying to learn a tool.

Control Center seems to run as SYSTEM by default on WinXP, which leads to errors like this:

SQL0551N  "SYSTEM" does NOT have the required authorization
OR privilege TO perform operation "SELECT" ON object "LEONSP.ACT". 

Let’s remedy this by granting lots of privileges all around.

Open up the DB2 Command Window.

Connect to the database as a user that already has permissions (leonsp for me):

db2 connect TO samptest user leonsp USING password

Grant all privileges to SYSTEM:


Did you create DB2ADMIN or some other id when installing DB2 on Windows? Let’s grant all privileges to that user as well:


You should now no longer see the SELECT privilege error. Note that you should not do this in a production environment, as this is less secure than the default configuration.