svn directory analyze.pgsql.logs has been renamed to pgsql-tools.
it still contains (and will contain) lgo analyzer, but now i will be able to put there more stuff 🙂
current url: http://svn.depesz.com/svn/pgsql-tools/trunk.
svn directory analyze.pgsql.logs has been renamed to pgsql-tools.
it still contains (and will contain) lgo analyzer, but now i will be able to put there more stuff 🙂
current url: http://svn.depesz.com/svn/pgsql-tools/trunk.
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:
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" 🙂
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.
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?
all of you know copy command. it's fast for inserting new data. but can it be used it we want to insert or update rows?
sure, it will be more than one command, but it's perfectly doable. here's how.
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" 🙂
[ wersja polska poniżej ]
just found this nice brain teaser.
i have this code in bash:
echo -e "1 1\n2 2" | while read A B; do echo "[$A] [$B]"; echo "ZZZ"; done
it will print:
[1] [1] ZZZ [2] [2] ZZZ
which is perfectly valid and sensible.
but if i'll change the command to:
echo -e "1 1\n2 2" | while read A B; do echo "[$A] [$B]"; ssh localhost date; echo "ZZZ"; done
i.e. i added ‘ssh localhost date' which connect to localhost over ssh, logins to my own account, and issues “date" command (can be any command), it shows only:
[1] [1] Tue Sep 18 15:45:24 CEST 2007 ZZZ
and finishes work. (i have a password-less login in localhost, so it doesn't ask for password).
and the question is: why there is no second step of while loop?
( side note: i know the answer, it's just a riddle for you 🙂
trafiłem właśnie na niezłą łamigłówkę:
poniższa linijka w bashu:
echo -e "1 1\n2 2" | while read A B; do echo "[$A] [$B]"; echo "ZZZ"; done
wypisze:
[1] [1] ZZZ [2] [2] ZZZ
co jest w pełni sensowe i oczekiwane.
ale jeśli zmienię ją na:
echo -e "1 1\n2 2" | while read A B; do echo "[$A] [$B]"; ssh localhost date; echo "ZZZ"; done
tzn. dodam ‘ssh localhost date', co łączy się na moje konto na localhoście i wykonuje polecenie “date" (może to być dowolne polecenie), wynikiem całości jest tylko:
[1] [1] Tue Sep 18 15:45:24 CEST 2007 ZZZ
i to koniec (mam logowanie bezhasłowe więc nie ma prośby o hasło).
pytanie: czemu nie ma drugiego wykonania kodu w pętli while?
( oczywiście (jak przy poprzednich łamigłówkach) znam odpowiedź ).
this questions pops every once in a while on irc.
some guy has a table, and it contains duplicated rows.
basically there are 2 possible scenarios:
so, how to remove duplicates from such tables?
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:
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).
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.