easy access to postgresql documentation from firefox

for whatever reason i seem to remember names of files in postgresql documentation.

for example – i know, that psql docs are in app-psql.html, base page for configuration options is runtime-config.html. manual for “alter table" sql command, is in sql-altertable.html.

yet full page url (http://www.postgresql.org/docs/current/app-psql.html) is very long. on the other hand going to http://www.postgresql.org/docs/current/ is not really useful, as i need to find specific page which i remember filename, but not necessarily title.

is there any solution? apparently, yes, simply follow these steps:

  1. go to http://www.postgresql.org/docs/current/
  2. bookmark this page
  3. go to “Bookmarks" -> “Organize Bookmarks…"
  4. find the bookmark that you just created, select it, and click on “properties" in toolbar
  5. in “keyword" enter letter “p" (without quotes)
  6. change url to http://www.postgresql.org/docs/current/%s.html
  7. press “ok" (you might want to create a special folder to hide this bookmark from standard view, as you will never use it directly)

and that's all. after you've done it, you can simply enter: “p app-psql" in your location edit box, press enter and you will be directed to correct page.

of course this trick works not only with postgresql docs. it can be used for google, search.postgresql.org, anything you want. but using this for postgresql manual will definitely shorten time spent on “going to manual" 🙂

dell powervault md1000 – storage test

i recently got new toy for tests – brand new dell powervault md1000.

what's this, you ask? basically – a rather nice das (direct attached storage) from dell.

the box i got had 15 sas discs, each disc being 72gb, 15krpm.

since this will be used as database storage, i wanted to make some performance tests.

Continue reading dell powervault md1000 – storage test

what fields are usually changed when update’ing?

there was this situation, that we had a lot of tables and a lot of update activity. so, we thought about splitting the most updated tables to parts that are usually stable, and parts (columns) which change often.

but how to know what changes? unfortunately orm that was used issued updates like this:

UPDATE TABLE SET field1='..', field2='...', field3='...' WHERE id = 123;

basically it always updated all fields. (don't even start to comment that orms are by definition broken).

so, i had to find a nice way to find out what was really updated.

Continue reading what fields are usually changed when update'ing?

postgresql tips & tricks

cortilap @ freenode's #postgresql asked about how to create a check() that will allow only one of the columns to be not null.

it doesn't sound cool, let's see:

with 2 columns (a,b) you make a check: check ( (a is not null and b is null) or (a is null and b is not null) or (a is null and b is null))

whoa. and what about 3 columns? 4?

of course it creates some questions about the schema, but is there a way to do it? without such long checks?

one solution is to make a function to check it. but perhaps a simpler solution is possible?

luckily all of the fields are ints.

a quick think, and here we go:

check (coalesce(a*0, 1) + coalesce(b*0, 1) + coalesce(c*0, 1) > 1)

and what is the field was text? same thing, but instead of doing “X"*0, i would do “length(X)*0" 🙂

my thoughts on getting random row

this topic has been written about by many smart people – from the recent past, by greg sabino mullane and josh berkus.

they show 4 different approaches:

  1. order by random()
  2. >= random() limit 1
  3. random column
  4. random aggregate

all these approaches have their benefits and drawbacks, but i'd like to show another one (polish readers saw the approach already in january 2007, but this time i will make the code more robust).

Continue reading my thoughts on getting random row

speeding up like ‘%xxx%’

as most of you know postgresql can easily speedup searches using:

field like 'something%'

and (less easily):

field like '%something'

but how about:

field like '%something%'

general idea is to use some kind of full text search/indexing – tsearch, lucene, sphinx, you name it.

but sometimes you can't install fts/fti, or it doesn't really solve your problem. is there any help? let's find out.

Continue reading speeding up like ‘%xxx%'

objects in categories – counters with triggers

so there you go, you have some “categories" and some objects. for simplicity let's assume one object can be in only one category.

if this is too theoretical for you – let's assume these are “mails in folders", “photos in galleries", “posts in categories" or “auctions in categories on ebay".

everything clear? now, let's assume you want to know how many “objects" are in given “category".

most basic way to do it is:

SELECT COUNT(*) FROM objects WHERE category = some_category;

but this method is far from optimal. now, we'll learn how to do it better.

one warning for those of you who read the rss feed – if you say “yeah, i know the code, it's simple" – ask yourself – is your code deadlock-proof?

Continue reading objects in categories – counters with triggers