Friday, 18 September 2009


I saw Depesz just came up against something on pgsql-bugs that I've done a couple of times.

ON tablename (column list);

Works perfectly. It adds an index called "concurrently" onto "tablename". That part is actually quite funny, and easily correctable using

ALTER INDEX concurrently RENAME TO something_sensible;

It's a very good lesson in why its a great idea to use tab completion, or a GUI. I have another story about that though, for another day.

Anyway, the really painful part about creating our index above is that the DBA (yours truly) intended to create an index concurrently, that is "concurrently" as an adverb rather than noun. The result is that you run a normal CREATE INDEX statement, so you end up applying a ShareLock to the table and all writes against the table stop. Of course, that happens right at the moment where you decide a cappuccino is a great plan and drive out for a round of coffee while the index build runs. Neat huh?

I figure I'm not the only person to forget to make mistakes and if we never admit them the software won't improve. So I'll see if we can come up with a little patch that avoids us adding "concurrently" as a reserved word. Not sure I see the problem really, since I never met anyone who named their database objects using adverbs rather than nouns. I bet there's one. There always is.

Anyway, the moral of the story is use

ON tablename (column list);

Well actually, its not, but this is: Production systems are like lions - never turn your back on them, even after they've been fed, no matter how long you've been training them. And even lion tamers get bitten, sometimes. (And that is why I spend so long developing recovery features).

Thursday, 10 September 2009

Winning the Lottery

This week I'm the lucky recipient of about £23,750,000. That comes from various wills, lottery wins and corrupt magnates who can't cash a cheque any other way, except via me. So they say.

Last week I won more, I'm sure of it.

Did these guys ever need a database so they can deploy advanced marketing techniques!
(phone rings) .... ah, what's that? .... really? .... oh, how embarrassing, 3 you say? ....Maybe it needs tuning then, or perhaps replication? It does? Cool.... what's that? Could I just send a cheque for £100, so you can have my payment details correct and then you'll send through the consulting fees?.... Hmmm, maybe not after all. (hangs up)

Definitely hard to know which communications to receive and which to ignore. I figure if you read everything you'd never get anything done at all. I guess it's a balance and everybody chooses their own personal balance point.

Anyway, forget that, I'm off to spend my winnings: Woo hoo - So long, Lao Che!

Monday, 7 September 2009

Hot Standby

I'm currently working on the Hot Standby project, which kicked off design and development around July 2008 and was active through to February 2009. After a break to assist with the release of Postgres 8.4, the project began again in July 2009 as planned. It's definitely been a voyage of discovery.

Hot Standby seems to be a popular feature from two recent polls, so I guess that is why some people have been getting fairly anxious about the project recently. Anyway, what is it? Why is it important? Let me explain.

If you set up Log Shipping replication with PostgreSQL (called "Warm Standby" in the docs), you'll discover that the standby node can't run queries. All it does is keep processing changes so that it keeps mostly/nearly/eventually up to date with the Master - hence why its called a "warm" standby. Useful, but not enough, hence we move on to Hot Standby.

Why "Hot"? I've used the terms Cold/Warm/Hot similarly to the way they're used in other areas of High Availability computing. A Cold Standby/Spare is one that isn't available for immediate use and requires some work to get things configured. A Warm Standby/Spare is one that can be put into action fairly quickly, while a Hot Standby/Spare is one that can be used immediately without taking the system offline.

With Postgres, Hot Standby refers to the ability to

* Run read-only queries on a standby server that is being concurrently maintained by log shipping replication. We use full MVCC so read-only queries don't block incoming changes, nor do the changes lock out queries. There are some conflicts that can occur, discussed later.

* Switch from standby mode to normal/master-mode without stopping/restarting the server. So queries keep on running without interruption while the database server changes mode - hence it is "Hot". Many people are unaware of this second aspect of the feature.

The reasons for query conflicts are fairly detailed for a short blog, so I'll cover that in a later post. There'll be detailed docs with the patch when it's available around Sept 15.

The strange thing about Hot Standby is "it just works". When you run a few queries there's an initial buzz, but then you realise that it all works normally without much fuss. That's a shame really because this is probably the most technical patch to hit Postgres in years, involving many different parts of the internals. Seems fair though, after all, I admit I give scarcely no thought to all the people who spent time on the hardware and software that allows me to write this and for you to read it.

I'll be in Tokyo for the JPUG 10th Anniversary meeting later this year to present about Hot Standby. I'm very pleased to be attending and it would be a good place to learn more.

There's a practical course in London in late September if you want to work together while we cover the full details on Hot Standby and replication. Probably be more training dates and other events over the coming months also.

Tuesday, 1 September 2009

Database Biology

From Biology we learn that all (known) complex organisms are comprised of multiple cells. Cells are not simple things, but their most important quality is their ability to work together to create something much bigger than themselves.

Large, mature businesses end up with hundreds of databases to perform all of their business functions. Yet we seem still to have much difficulty in making databases work together. ETL, EAI and information integration tools seem to help somewhat but that feels more like plumbing than intelligent integration.

My goal for some years now has been to create ways for databases to work together in more complex ways, not just operate as single-celled organisms. The backbone of that is change propagation between the cells, which most people call database replication. That is why I've been so engaged in enhancing replication for so many years but it is not an end in itself. Sure, most of that has been for PostgreSQL - but then that's OK because everybody uses that, whether they even know/admit it or not.

Making it work is the first step. Making it all work easily is important also. With my background in solutions, I've personally preferred a toolkit approach that allows good custom solutions to be developed. Shrink-wrap software is needed as well and that's why I've been working with Robert Hodges of Continuent to help bring a compelling solution forwards that has both a good out-of-the-box feel as well as the flexibility to solve those tricky requirements people keep throwing at me. (Don't stop! It's fun)

Streaming, synchronous replication will be with us by next Summer if the release dates all go to plan. The ability to run queries on standby servers while they actively accept new changes from their master will also be with us soon: Hot Standby.

I'll blog more about Hot Standby for PostgreSQL over the coming weeks. In the longer term I'll explain more about the directions I hope to take with clustered databases, and why.