zapraszam na nowo-otwarty blog motoryzacyjny auta.cc.
who has birthday tomorrow?
so, there you have a users table, with a very basic structure:
Table "public.users" Column | Type | Modifiers -----------+---------+----------- id | integer | not null birthdate | date | Indexes: "x_pkey" PRIMARY KEY, btree (id)
then, you have a task: find a query that will return all users which have birthday tomorrow. how will you do it?
i just “love” locale issues.
nice machine with 2 gb of ram, 800 megabytes in 2 logfiles. single word as search phrase. polish utf-8 locale (pl_PL.UTF-8), gnu grep 2.5.1. results?
=> time grep -in reloading postgresql-2007-10-22_000000.log postgresql-2007-10-22_120909.log postgresql-2007-10-22_000000.log:40001:2007-10-22 10:50:13.528 CEST @ 24681 LOG: received SIGHUP, reloading configuration files postgresql-2007-10-22_120909.log:1215696:2007-10-22 12:15:21.769 CEST @ 24681 LOG: received SIGHUP, reloading configuration files real 1m21.212s user 1m20.909s sys 0m0.284s
same, check without -i:
=> time grep -n reloading postgresql-2007-10-22_000000.log postgresql-2007-10-22_120909.log postgresql-2007-10-22_000000.log:40001:2007-10-22 10:50:13.528 CEST @ 24681 LOG: received SIGHUP, reloading configuration files postgresql-2007-10-22_120909.log:1215696:2007-10-22 12:15:21.769 CEST @ 24681 LOG: received SIGHUP, reloading configuration files real 0m1.147s user 0m0.868s sys 0m0.268s
after setting locale to C:
=> time grep -in reloading postgresql-2007-10-22_000000.log postgresql-2007-10-22_120909.log postgresql-2007-10-22_000000.log:40001:2007-10-22 10:50:13.528 CEST @ 24681 LOG: received SIGHUP, reloading configuration files postgresql-2007-10-22_120909.log:1215696:2007-10-22 12:15:21.769 CEST @ 24681 LOG: received SIGHUP, reloading configuration files real 0m1.209s user 0m0.896s sys 0m0.316s
all tests were repeated many times to get all data in memory, and check for extreme values.
does anybody need another proof that locale “thing" is broken? of course it might be that only locale handling in grep is bad, but anyway – it's still locale issue.
grant XXX on * ?
one of the more common problems new users have with postgresql (especially those that came from mysql background), is the lack of easy way to grant/revoke/do-something with many objects (tables/sequences/views) at once.
there are number of pages that deal with the problem, let's just name some from #postgresql infobots:
- http://pgedit.com/public/sql/acl_admin/index.html
- http://www.archonet.com/pgdocs/grant-all.html
now, both of these pages have their benefits, but i'd like to show something simpler, yet (perhaps) more powerful.
instead of giving you the fish (figuratively speaking) i will give you the net and the skills so you'll be able to do the magic yourself.
find.best.tablespace.split.pl
Changes:
- get connection settings from command line:
./find.best.tablespace.split.pl “dbi:Pg:dbname=depesz;host=127.0.0.1;port=12345" depesz - calculate only for public schema (can be easily changed)
- distribute indexes as well – always put indexes on another tablespace than table
- add comment in generated file about total filesizes in tablespaces *after* migration – so it will be clearer on what to move
svn is located here.
finding missing pairs
let's assume we have a simple table:
Table "public.test" Column | Type | Modifiers --------+---------+----------- a | integer | not null b | integer | not null Indexes: "test_pkey" PRIMARY KEY, btree (a, b) "q" UNIQUE, btree (b, a)
now, let's insert some rows to it:
# insert into test select * from generate_series(1,100) as a, generate_series(1,100) as b^J; INSERT 0 10000
remove rows with a = b:
# delete from test where a = b; DELETE 100
and prepare test-case by randomly removing some rows:
# delete from test where random() < 0.002; DELETE 17
the question is – find all pairs of (a,b) where there is no row (a',b') where (a'=b and b'=a).
in other words – every row (a,b) should be paired. rows with a = 2 and b = 3, is paired by row with a = 3 and b = 2.
how to find incomplete pairs?
pgsql-tools/analyze.pgsql.logs.pl
Changes:
- doesn't use temp files – does everything in-memory. makes the whole process *way* faster
- allow setting header information using postgresql log_line_prefix syntax
- removes dependency on readonly perl module – it is not really common module, and the functionality in this program is very limited
- allows setting database to track as command line option, or track sqls from all databases
SVN repo at: http://svn.depesz.com/svn/pgsql-tools/trunk
“FATAL: Ident authentication failed”, or how cool ideas get bad usage schemas
UPDATE (2012-06-24): Version 9.1 of PostgreSQL renamed ident to peer (for local connections). So if you're having errors about “Peer authentication failed" – it is the same as “Ident authentication failed", and all described in this blogpost is still relevant.
ever seen one of those? i mean the “fatal: ident authentication failed"?
or, ever seen anyone having this problem when connecting to postgresql?
how often is this problem related to debian/post-debian linux distributions? 99%? 100%?
on #postgresql on irc.freenode.net it is the most common problem. my own irc logs show that “ident" showed over 300 times over last 41 days. now, that's something. and how come we have this problem? what can be done with it? read on.
Continue reading “FATAL: Ident authentication failed", or how cool ideas get bad usage schemas
motto na dziś: przed nami tylko wzrost.
nieoceniony glasbergen z dziś:
mbank frontem do klienta [polish only]
ci z was co mnie znają ciut bliżej wiedzą, że mam permanentne problemy finansowe.
jakiś czas temu w mbanku wystąpiłem o kartę kredytową (jak chcesz skomentować: co za łoś, ma kłopoty finansowe i jeszcze kartę bierze, to sobie odpuść). mam u nich konta, więc karta od nich była logiczna.
kartę dostałem bezproblemowo.
fajnie.
korzystałem, spłacałem. wszystko fajnie.
do czasu. w pewnym momencie moje konto zostało zablokowane (przez bank, ale na życzenie innej strony). aby je odblokować musiałbym wpłacić kwotę rzędu wartości nowego (prosto z salonu) samochodu.
w sumie to nawet nie duży problem. z jednym haczykiem. karta kredytowa w mbanku jest “spięta" z kontem. a konto zostało zablokowane. jeśli cokolwiek na nie wpłacę – to tak jakbym wyrzucił przez okno – od razu zniknie.
impas. nie mam jak spłacać karty. a nie chcę z niej rezygnować – pomijając wszystko inne – rezygnując musiałbym spłacić całe zadłużenie karty, które jest … istotne.
zadzwoniłem do mbanku. dowiedziałem się, że:
- jak nie spłacę karty to oni skierują ją do windykacji (czytaj: napomnienia, komornik, wejście na konto)
- skoro konto mam zablokowane to nie mam jak spłacić
- aby odblokować konto musiałbym wpłacić “samochód"
- aby karty nie skierowali do windykacji muszę rozwiązać umowę na konto, wtedy karta też zostanie skasowana. ale będę musiał od ręki wpłacić całe zadłużenie karty.
oops. zadłużenie karty to kilka średnich krajowych. nie uśmiecha mi się “rzeźbienie" by taką kasę “natrzepać". dodatkowo – nie chcę kasować konta – fajne jest i jak kiedyś w końcu odblokuję, to z przyjemnością będę sobie z niego korzystał.
pani w infolinii była bardzo miła, ale powiedziała, że innej metody nie ma. mogę co najwyżej wysłać do nich podanie pocztą (nie emailem, taką pocztą co to ślimakami ją dostarczają), ale i tak odpowiedzą mi to samo.
no nic. podanie napisałem, przedstawiłem sytuację, powołałem się na długi staż bycia klientem i brak zadrażnień.
2 tygodnie później dostałem odpowiedź. mbank specjalnie dla mnie założył nowe konto (na tyle interesujące, że nawet nie ma nazwy (tak jak mBiznes, eKonto czy eMax, to ma “*** UNNAMED ***"). konto to jest odblokowane i może służyć jedynie do spłat karty.
sprawdziłem – działa.
czyli jednak się da.
wnioski:
- banki potrafią iść na rękę. czasem wystarczy po prostu poprosić
- panie z infolinii nie zawsze pomogą, są przygotowane do obsłużenia 99.9% typowych spraw. a czasem się po prostu spada poza ten “nawias" 🙂
- lubię mbank