2002-02-22 15:48:55 +03:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
Otvety na chasto zadavaemye voprosy po PostgreSQL
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
Data poslednego obnovleniya: Sreda 2 fevralya 12:44:03 EST 2005
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
Anglijskij variant soprovozhdaet: Bryus Mom'yan (Bruce Momjian)
|
2002-04-12 13:17:10 +04:00
|
|
|
(pgman@candle.pha.pa.us)
|
|
|
|
|
2003-11-28 23:20:33 +03:00
|
|
|
Perevel na russkij: Viktor Vislobokov (corochoone@perm.ru)
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
Samuyu svezhuyu anglijskuyu versiyu dokumenta mozhno najti na
|
2005-02-11 07:53:51 +03:00
|
|
|
http://www.PostgreSQL.org/files/documentation/faqs/FAQ.html.
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
Otvety na voprosy specifichnye dlya konkretnyh platform mozhno najti
|
2005-02-11 07:53:51 +03:00
|
|
|
na http://www.PostgreSQL.org/docs/faq/.
|
2002-04-12 13:17:10 +04:00
|
|
|
_________________________________________________________________
|
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
Obschie voprosy
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
1.1) CHto takoe PostgreSQL? Kak proiznositsya `eto nazvanie?
|
|
|
|
1.2) Kakovy avtorskie prava na PostgreSQL?
|
2005-02-11 07:53:51 +03:00
|
|
|
1.3) Na kakih platformah rabotaet PostgreSQL?
|
|
|
|
1.4) Gde mozhno vzyat' PostgreSQL?
|
|
|
|
1.5) Gde poluchit' podderzhku?
|
|
|
|
1.6) Kak mne soobschit' ob oshibke?
|
2004-01-08 19:01:58 +03:00
|
|
|
1.7) Kakaya versiya poslednyaya?
|
2002-11-10 22:48:41 +03:00
|
|
|
1.8) Kakaya dokumentaciya imeetsya v nalichii?
|
|
|
|
1.9) Kak najti informaciyu ob izvestnyh oshibkah ili otsutstvuyuschih
|
|
|
|
vozmozhnostyah?
|
|
|
|
1.10) Kak nauchit'sya SQL?
|
2005-02-11 07:53:51 +03:00
|
|
|
1.11) Kak prisoedinitsya k komande razrabotchikov?
|
|
|
|
1.12) Kak sravnivat' PostgreSQL s drugimi SUBD?
|
2002-11-10 22:48:41 +03:00
|
|
|
|
|
|
|
Voprosy pol'zovatelej po klientskoj chasti
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
2.1) Kakie interfejsy est' dlya PostgreSQL?
|
2002-11-10 22:48:41 +03:00
|
|
|
2.2) Kakie instrumenty suschestvuyut dlya ispol'zovaniya PostgreSQL
|
|
|
|
cherez Web?
|
|
|
|
2.3) Est' li u PostgreSQL graficheskij interfejs pol'zovatelya?
|
|
|
|
|
|
|
|
Voprosy administrirovaniya
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
3.1) Kak mne ustanovit' PostgreSQL v mesto otlichnoe ot
|
2002-04-12 13:17:10 +04:00
|
|
|
/usr/local/pgsql?
|
2005-02-11 07:53:51 +03:00
|
|
|
3.2) Kak mne upravlyat' soedineniyami s drugih komp'yuterov?
|
|
|
|
3.3) Kakie nastrojki mne nuzhno sdelat' dlya uluchsheniya
|
2002-11-10 22:48:41 +03:00
|
|
|
proizvoditel'nosti?
|
2005-02-11 07:53:51 +03:00
|
|
|
3.4) Kakie vozmozhnosti dlya otladki est' v nalichii?
|
|
|
|
3.5) Pochemu ya poluchayu soobschenie "Sorry, too many clients" kogda
|
2002-11-10 22:48:41 +03:00
|
|
|
pytayus' podklyuchit'sya k baze?
|
2005-02-11 07:53:51 +03:00
|
|
|
3.6) Pochemu neobhodimo delat' dump i restore pri obnovlenii vypuskov
|
2002-08-23 06:53:20 +04:00
|
|
|
PostgreSQL?
|
2005-02-11 07:53:51 +03:00
|
|
|
3.7) Kakoe komp'yuternoe "zhelezo" ya dolzhen ispol'zovat'?
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
Voprosy `ekspluatacii
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
4.1) Kak vypolnit' SELECT tol'ko dlya neskol'kih pervyh strochek
|
2003-06-23 20:58:21 +04:00
|
|
|
zaprosa? Dlya proizvol'noj stroki?
|
2005-02-11 07:53:51 +03:00
|
|
|
4.2) Kak mne najti kakie tablicy, indeksy, bazy dannyh i pol'zovateli
|
|
|
|
suschestvuyut? Kak mne uvidet' zaprosy, kotorye ispol'zuet psql dlya
|
|
|
|
polucheniya `etoj informacii?
|
|
|
|
4.3) Kak izmenit' tip dannyh kolonki?
|
|
|
|
4.4) Kakovy maksimal'nye razmery dlya strok v tablice, tablic i bazy
|
|
|
|
dannyh?
|
|
|
|
4.5) Kak mnogo diskovogo prostranstva v baze dannyh nuzhno dlya
|
2002-11-10 22:48:41 +03:00
|
|
|
sohraneniya dannyh iz obychnogo tekstovogo fajla?
|
2005-02-11 07:53:51 +03:00
|
|
|
4.6) Pochemu moi zaprosy rabotayut medleno? Pochemu oni ne ispol'zuyut
|
|
|
|
moi indeksy?
|
|
|
|
4.7) Kak posmotret' na to, kak optimizator vypolnyaet moj zapros?
|
|
|
|
4.8) Kak mne vypolnit' poisk regulyarnogo vyrazheniya i poisk
|
2002-11-10 22:48:41 +03:00
|
|
|
nezavisimyj ot registra bukv poisk regulyarnogo vyrazheniya? Kak mne
|
|
|
|
ispol'zovat' indeks dlya poiska nezavisimogo ot registra bukv?
|
2005-02-11 07:53:51 +03:00
|
|
|
4.9) Kak ya mogu opredelit', chto znachenie polya ravno NULL v
|
2002-11-10 22:48:41 +03:00
|
|
|
kakom-libo zaprose?
|
2005-02-11 07:53:51 +03:00
|
|
|
4.10) Kakovy otlichiya mezhdu raznymi simvol'nymi tipami?
|
|
|
|
4.11.1) Kak mne sozdat' pole serial/s-avto-uvelicheniem?
|
|
|
|
4.11.2) Kak mne poluchit' znachenie pri vstavke SERIAL?
|
|
|
|
4.11.3) Ne mozhet li poluchit'sya tak, chto ispol'zovanie currval() i
|
2002-11-10 22:48:41 +03:00
|
|
|
nextval() privedet k zaciklirovaniyu s drugimi pol'zovatelyami?
|
2005-02-11 07:53:51 +03:00
|
|
|
4.11.4) Pochemu chisla iz moej posledovatel'nosti ne ispol'zuyutsya
|
2002-11-10 22:48:41 +03:00
|
|
|
snova pri otmene tranzakcii? Pochemu sozdayutsya razryvy pri numeracii
|
|
|
|
v kolonke, gde ya ispol'zuyu posledovatel'nost'/SERIAL?
|
2005-02-11 07:53:51 +03:00
|
|
|
4.12) CHto takoe OID? CHto takoe TID?
|
|
|
|
4.13) Pochemu ya poluchayu oshibku "ERROR: Memory exhausted in
|
2002-04-12 13:17:10 +04:00
|
|
|
AllocSetAlloc()"?
|
2005-02-11 07:53:51 +03:00
|
|
|
4.14) Kak mne uznat', kakaya versiya PostgreSQL zapuschena?
|
|
|
|
4.15) Pochemu pri rabote s moim bol'shim ob"ektom ya poluchayu oshibku
|
2002-04-12 13:17:10 +04:00
|
|
|
"invalid large obj descriptor"?
|
2005-02-11 07:53:51 +03:00
|
|
|
4.16) Kak mne sozdat' kolonku kotoraya po umolchaniyu budet soderzhat'
|
2002-11-10 22:48:41 +03:00
|
|
|
tekuschee vremya?
|
2005-02-11 07:53:51 +03:00
|
|
|
4.17) Kak vypolnit' vneshnee svyazyvanie?
|
|
|
|
4.18) Kak vypolnyat' zaprosy, ispol'zuyuschie neskol'ko baz dannyh?
|
|
|
|
4.19) Kak mne vernut' iz funkcii neskol'ko strok tablicy?
|
|
|
|
4.20) Pochemu ya ne mogu nadezhno sozdavat'/udalyat' vremennye tablicy
|
2002-11-10 22:48:41 +03:00
|
|
|
v funkciyah PL/PgSQL?
|
2005-02-11 07:53:51 +03:00
|
|
|
4.21) Kakie opcii shifrovaniya suschestvuyut?
|
2002-11-10 22:48:41 +03:00
|
|
|
|
|
|
|
Rasshireniya PostgreSQL
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
5.1) YA napisal funkciyu opredelyaemuyu pol'zovatelem. Kogda ya
|
2004-04-12 07:22:20 +04:00
|
|
|
zapuskayu ee v psql, pochemu ya poluchayu core dump?
|
2002-11-10 22:48:41 +03:00
|
|
|
5.2) Kak ya mogu vnesti nekotorye klassnye novye tipy i funkcii v
|
2002-04-12 13:17:10 +04:00
|
|
|
PostgreSQL?
|
2005-02-11 07:53:51 +03:00
|
|
|
5.3) Kak mne napisat' C funkciyu, vozvraschayuschuyu stroku tablicy?
|
2002-11-10 22:48:41 +03:00
|
|
|
5.4) YA izmenil ishodnyj fajl. Pochemu posle perekompilyacii ya ne
|
|
|
|
vizhu izmenenij?
|
2002-04-12 13:17:10 +04:00
|
|
|
_________________________________________________________________
|
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
Obschie voprosy
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
1.1) CHto takoe PostgreSQL? Kak proiznositsya `eto nazvanie?
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
PostgreSQL proiznositsya Post-Gres-Q-L (Post-Gres-K'yu-`El), takzhe
|
|
|
|
chasto govoryat prosto Postgres.
|
|
|
|
|
|
|
|
PostgreSQL - `eto ob"ektno-relyacionnaya sistema upravleniya bazami
|
|
|
|
dannyh (SUBD), kotoraya imeet tradicionnye vozmozhnosti kommercheskih
|
|
|
|
SUBD s rasshireniyami, kotorye est' v SUBD novogo pokoleniya.
|
|
|
|
PostgreSQL - `eto svobodnoe i polnost'yu otkrytoe programmnoe
|
|
|
|
obespechenie.
|
|
|
|
|
|
|
|
Razrabotku PostgreSQL vypolnyaet komanda razrabotchikov, razbrosannaya
|
|
|
|
po vsemu miru i svyazannaya cherez Internet. Razrabotka yavlyaetsya
|
|
|
|
obschestvennym proektom i ne upravlyaetsya kakoj-libo kompaniej.
|
|
|
|
Podrobnosti smotrite v FAQ dlya razrabotchikov,
|
|
|
|
http://www.PostgreSQL.org/files/documentation/faqs/FAQ_DEV.html
|
2002-11-10 22:48:41 +03:00
|
|
|
|
|
|
|
1.2) Kakovy avtorskie prava na PostgreSQL?
|
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
PostgreSQL rasprostranyaetsya po klassicheskoj licenzii BSD. `Eta
|
|
|
|
licenziya ne soderzhit ogranichenij na to, kak budet ispol'zovat'sya
|
|
|
|
ishodnyj kod. Nam nravitsya `eta licenziya i u nas net namerenij eio
|
|
|
|
menyat'.
|
|
|
|
|
|
|
|
Vot `eta licenziya BSD, kotoruyu my ispol'zuem:
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
Sistema Upravleniya Bazami Dannyh PostgreSQL
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
Portions copyright (c) 1996-2005, PostgreSQL Global Development Group
|
2002-11-10 22:48:41 +03:00
|
|
|
Portions Copyright (c) 1994-6 Regents of the University of California
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
Predostavlyayutsya prava na ispol'zovanie, kopirovanie, izmenenie i
|
|
|
|
rasprostranenie dannogo programmnogo obespecheniya i ego dokumentacii
|
|
|
|
dlya lyubyh celej, besplatno i bez podpisaniya kakogo-libo
|
|
|
|
soglasheniya, pri uslovii chto dlya kazhdoj kopii budut predostavleny
|
|
|
|
dannoe vyshe zamechanie ob avtorskih pravah, tekuschij paragraf i dva
|
|
|
|
sleduyuschih paragrafa.
|
|
|
|
|
|
|
|
KALIFORNIJSKIJ UNIVERSITET NE NESET NIKAKOJ OTVETSTVENNOSTI ZA LYUBYE
|
|
|
|
POVREZHDENIYA, VKLYUCHAYA POTERYU DOHODA, NANESENNYE PRYAMYM ILI
|
|
|
|
NEPRYAMYM, SPECIAL'NYM ILI SLUCHAJNYM ISPOL'ZOVANIEM DANNOGO
|
|
|
|
PROGRAMMNOGO OBESPECHENIYA ILI EGO DOKUMENTACII, DAZHE ESLI
|
|
|
|
KALIFORNIJSKIJ UNIVERSITET BYL IZVESCHEN O VOZMOZHNOSTI TAKIH
|
|
|
|
POVREZHDENIJ.
|
|
|
|
|
|
|
|
KALIFORNIJSKIJ UNIVERSITET SPECIAL'NO OTKAZYVAZYVAETSYA PREDOSTAVLYAT'
|
|
|
|
LYUBYE GARANTII, VKLYUCHAYA, NO NE OGRANICHIVAYAS' TOL'KO `ETIMI
|
|
|
|
GARANTIYAMI: NEYAVNYE GARANTII PRIGODNOSTI TOVARA ILI PRIGODNOSTI DLYA
|
|
|
|
OTDEL'NOJ CELI. DANNOE PROGRAMMNOE OBESPECHENIE PREDOSTAVLYAETSYA NA
|
|
|
|
OSNOVE PRICIPA "KAK EST'" I KALIFORNIJSKIJ UNIVERSITET NE OBYAZAN
|
|
|
|
PREDOSTAVLYAT' SOPROVOZHDENIE, PODDERZHKU, OBNOVLENIYA, RASSHIRENIYA
|
|
|
|
ILI IZMENENIYA.
|
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
1.3) Na kakih platformah rabotaet PostgreSQL?
|
2002-11-10 22:48:41 +03:00
|
|
|
|
|
|
|
Obychno, PostgreSQL mozhet rabotat' na lyuboj sovremennoj platforme
|
|
|
|
sovmestimoj s Unix. V instrukcii po ustanovke, vy najdete spisok teh
|
|
|
|
platform, na kotoryh byli provedeny testovye zapuski PostgreSQL k
|
|
|
|
momentu vyhoda dannoj versii.
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2004-10-26 21:28:27 +04:00
|
|
|
Nachinaya s versii 8.0, PostgreSQL bez vsyakih uhischrenij rabotaet na
|
|
|
|
operacionnyh sistemah Microsoft Windows, osnovannyh na NT, takih kak
|
|
|
|
Win2000, WinXP i Win2003. Paket installyatora dostupen po adresu
|
2005-01-04 06:47:03 +03:00
|
|
|
http://pgfoundry.org/projects/pginstaller. Versii Windows, osnovannye
|
|
|
|
na MS-DOS (Win95, Win98, WinMe) mogut zapuskat' PostgreSQL s
|
|
|
|
pomosch'yu Cygwin.
|
2003-06-02 20:39:06 +04:00
|
|
|
|
|
|
|
Takzhe suschestvuet versiya sportirovannaya pod Novell Netware 6 na
|
2005-02-11 07:53:51 +03:00
|
|
|
http://forge.novell.com, i versiya dlya OS/2 (eComStation) na
|
|
|
|
http://hobbes.nmsu.edu/cgi-bin/h-search?sh=1&button=Search&key=postgre
|
|
|
|
SQL&stype=all&sort=type&dir=%2F.
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
1.4) Gde mozhno vzyat' PostgreSQL?
|
2002-11-10 22:48:41 +03:00
|
|
|
|
|
|
|
Naprimer, vospol'zovavshis' anonimnym dostupom na ftp sajt PostgreSQL
|
|
|
|
ftp://ftp.PostgreSQL.org/pub. Spisok zerkal vy najdete na nashem
|
|
|
|
osnovnom sajte.
|
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
1.5) Gde poluchit' podderzhku?
|
2002-11-10 22:48:41 +03:00
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
Soobschestvo PostgreSQL predostavlyaet pomosch' mnozhestvu
|
|
|
|
pol'zovatelej cherez E-mail. Osnovnoj web-sajt dlya podpiski na spiski
|
|
|
|
rassylki po E-mail `eto: http://www.postgresql.org/community/lists/.
|
|
|
|
Horoshim mestom dlya togo, chtoby nachat' zadavat' voprosy
|
|
|
|
yavlyayutsya spiski general (obschie voprosy) ili bugs (oshibki).
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2005-01-04 06:47:03 +03:00
|
|
|
Glavnym IRC kanalom yavlyaetsya #postgreql, raspolozhennyj na servere
|
|
|
|
Freenode (irc.freenode.net). CHtoby podklyuchit'sya, vy mozhete
|
2005-02-11 07:53:51 +03:00
|
|
|
ispol'zovat' v Unix vyzov programmy irc -c '#postgresql' "$USER"
|
2005-01-04 06:47:03 +03:00
|
|
|
irc.freenode.net ili lyuboj drugoj IRC klient. Na `etom zhe servere
|
|
|
|
suschestvuyut kanaly na ispanskom (#postgresql-es) i francuzskom
|
|
|
|
(#postgresqlfr) yazykah. Takzhe suschestvuet kanal po PostgreSQL na
|
|
|
|
servere EFNet.
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
Spisok kommercheskoj podderzhki kompanij dostupen na
|
2003-10-10 06:52:12 +04:00
|
|
|
http://techdocs.postgresql.org/companies.php.
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
1.6) Kak mne soobschit' ob oshibke?
|
|
|
|
|
|
|
|
Posetite stranichku so special'noj formoj otchiota ob oshibke v
|
|
|
|
PostgreSQL po adresu: http://www.postgresql.org/support/submitbug.
|
|
|
|
|
|
|
|
Takzhe prover'te nalichie bolee svezhej versii PostgreSQL na nashem
|
|
|
|
FTP sajte ftp://ftp.PostgreSQL.org/pub.
|
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
1.7) Kakaya poslednyaya versiya?
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
Poslednij vypusk PostgreSQL - `eto versiya 8.0.1
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
My planiruem vypuskat' novye versii kazhdye 10-12 mesyacev.
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
1.8) Kakaya dokumentaciya imeetsya v nalichii?
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
PostgreSQL soderzhit mnogo dokumentacii, vklyuchaya bol'shoe
|
|
|
|
rukovodstvo, stranicy `elektronnogo rukovodstva man i nekotorye
|
|
|
|
malen'kie testovye primery. Smotrite v katalog /doc. Vy takzhe mozhete
|
|
|
|
prosmatrivat' dokumentaciyu v Internet po adresu
|
|
|
|
http://www.PostgreSQL.org/docs.
|
2002-11-10 22:48:41 +03:00
|
|
|
|
|
|
|
Suschestvuet dve knigi po PostgreSQL dostupnye po adresam
|
|
|
|
http://www.PostgreSQL.org/docs/awbook.html i
|
|
|
|
http://www.commandprompt.com/ppbook/. Spisok knig po PostgreSQL,
|
|
|
|
kotorye mozhno kupit' dostupen po adresu
|
2003-10-10 06:52:12 +04:00
|
|
|
http://techdocs.postgresql.org/techdocs/bookreviews.php. Krome togo,
|
|
|
|
po adresu http://techdocs.PostgreSQL.org/ vy mozhete najti kollekciyu
|
2002-11-10 22:48:41 +03:00
|
|
|
tehnicheskih statej posvyaschennyh PostgreSQL.
|
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
Klient komandnoj stroki psql imeet neskol'ko komand \d dlya
|
|
|
|
otobrazheniya informacii po tipam, operatoram, funkciyam, agregatam i
|
|
|
|
t.d. - ispol'zujte \? dlya polucheniya spiska dostupnyh komand.
|
2002-11-10 22:48:41 +03:00
|
|
|
|
|
|
|
Nash sajt soderzhit esche bol'she informacii.
|
|
|
|
|
|
|
|
1.9) Kak najti informaciyu ob izvestnyh oshibkah ili otsutstvuyuschih
|
|
|
|
vozmozhnostyah?
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
PostgreSQL podderzhivaet rasshirennyj podklass SQL-92. Smotrite nash
|
|
|
|
spisok TODO na predmet izvestnyh oshibok, otsutstvuyuschih
|
2003-04-01 07:10:44 +04:00
|
|
|
vozmozhnostej i buduschih planov.
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
1.10) Kak mne nauchit'sya SQL?
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
Kniga po PostgreSQL na http://www.PostgreSQL.org/docs/awbook.html
|
|
|
|
nauchit SQL. Suschestvuet drugaya kniga po PostgreSQL na
|
|
|
|
http://www.commandprompt.com/ppbook. Est' prekrasnyj uchebnik na
|
|
|
|
http://www.intermedia.net/support/sql/sqltut.shtm, na
|
2002-04-12 13:17:10 +04:00
|
|
|
http://ourworld.compuserve.com/homepages/graeme_birchall/HTM_COOK.HTM,
|
2002-11-10 22:48:41 +03:00
|
|
|
i na http://sqlcourse.com.
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
Esche odin uchebnik - `eto kniga "Teach Yourself SQL in 21 Days,
|
|
|
|
Second Edition" (Osvoj samostoyatel'no SQL za 21 den', Vtoraya
|
|
|
|
redakciya) na http://members.tripod.com/er4ebus/sql/index.htm
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
Mnogim iz nashih pol'zovatelej nravitsya kniga The Practical SQL
|
|
|
|
Handbook, Bowman, Judith S., et al., Addison-Wesley. Drugim nravitsya
|
2002-04-12 13:17:10 +04:00
|
|
|
The Complete Reference SQL, Groff et al., McGraw-Hill.
|
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
1.11) Kak prisoedinitsya k komande razrabotchikov?
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
Dlya nachala, skachajte poslednyuyu versiyu ishodnyh tekstov i
|
2005-02-11 07:53:51 +03:00
|
|
|
prochtite FAQ i dokumentaciyu dlya razrabotchikov PostgreSQL na nashem
|
|
|
|
sajte ili v distributive. Zatem, podpishites' na spiski rassylki
|
|
|
|
pgsql-hackers i pgsql-patches. Dalee, otpravlyajte ispravleniya
|
|
|
|
(patches) vysokogo kachestva v spisok pgsql-patches.
|
2002-11-10 22:48:41 +03:00
|
|
|
|
|
|
|
Suschestvuet ogranichennyj spisok lyudej, kotoryj imeyut privelegiyu
|
|
|
|
vnosit' izmeneniya v CVS arhiv PostgreSQL. Kazhdyj iz `etih lyudej v
|
|
|
|
svoe vremya otpravil tak mnogo vysokokachestvennyh ispravlenij, chto
|
|
|
|
ih bylo nevozmozhno ostavit' bez vnimaniya i oni byli udostoeny
|
|
|
|
previlegii vnosit' izmeneniya, i my uvereny, chto te ispravleniya,
|
|
|
|
kotorye oni vnesut budut vysokogo kachestva.
|
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
1.12) Kak sravnivat' PostgreSQL s drugimi SUBD?
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
Suschestvuet neskol'ko metodov sravneniya programmnogo obespecheniya:
|
|
|
|
vozmozhnosti, proizvoditel'nost', nadezhnost', podderzhka i cena.
|
|
|
|
|
|
|
|
Vozmozhnosti
|
|
|
|
PostgreSQL imeet bol'shinstvo vozmozhnostej predstavlennyh v
|
|
|
|
bol'shih kommercheskih SUBD, takie kak: tranzakcii, podzaprosy,
|
2004-04-12 07:22:20 +04:00
|
|
|
triggery, predstavleniya, ssylochnoj celostnosti vtorichnogo
|
|
|
|
klyucha i raznye blokirovki. U nas est' nekotorye vozmozhnosti,
|
|
|
|
kotoryh net u nih: tipy, opredelyaemye pol'zovatelem, mehanizm
|
|
|
|
nasledovaniya, pravila i konkuretnoe mnogoversionnoe upravlenie
|
|
|
|
dlya raboty s soderzhimym blokirovok.
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
Proizvoditel'nost'
|
2005-02-11 07:53:51 +03:00
|
|
|
Proizvoditel'nost' PostgreSQL shodna s drugimi kommercheskimi
|
|
|
|
SUBD i s SUBD s otkrytym ishodnym kodom. V kakih-to veschah my
|
|
|
|
bystree, v kakih-to medlennee. V sravnenii s MySQL ili linejnoj
|
|
|
|
SUBD, my bystree, kogda pol'zovatelej mnogo, a takzhe na
|
|
|
|
slozhnyh zaprosah i pri chtenii/zapisi zagruzki zaprosa. MySQL
|
|
|
|
bystree dlya prostyh SELECT zaprosov, vypolnyaemyh nebol'shim
|
|
|
|
kolichestvom pol'zovatelej. I razumeetsya, MySQL ne imeet
|
|
|
|
kakih-libo vozmozhnostej iz perechislenyh vyshe, v sekcii
|
|
|
|
Vozmozhnosti. My delaem upor na nadezhnost' i rasshirennye
|
|
|
|
vozmozhnosti, no my takzhe prodolzhaem uvelichivat'
|
|
|
|
proizvoditel'nost' s kazhdym vypuskom.
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
Nadezhnost'
|
|
|
|
My ponimali, chto nasha SUBD dolzhna byt' nadezhnoj ili ona
|
|
|
|
nichego ne budet stoit'. My staraemsya vypuskat' horosho
|
|
|
|
proverennyj, stabil'nyj kod, kotoryj soderzhit minimum oshibok.
|
|
|
|
Kazhdyj vypusk prohodit stadiyu beta-testirovaniya po krajnej
|
|
|
|
mere v techenii odnogo mesyaca i nasha istoriya vypuskov
|
|
|
|
pokazyvaet chto my mozhem predostavlyat' stabil'nye, monolitnye
|
|
|
|
vypuski, kotorye gotovy k produktivnomu ispol'zovaniyu. My
|
|
|
|
verim, chto my proizvodim proverku ne huzhe, chem u drugih
|
|
|
|
SUBD.
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
Podderzhka
|
|
|
|
Nash spisok rassylki predostavlyaet vozmozhmozhnost' obscheniya
|
|
|
|
s bol'shoj gruppoj razrabotchikov i pol'zovatelej, kotorye
|
|
|
|
mogut pomoch' reshit' lyubye voznikshie problemy. V to zhe
|
|
|
|
vremya, my ne garantiruem kakie-libo ispravleniya, no i
|
|
|
|
razrabotchiki kommercheskih SUBD ne vsegda delayut
|
|
|
|
ispravleniya. Pryamoj dostup k razrabotchikam, soobschestvu
|
|
|
|
pol'zovatelej, rukovodstvam i ishodnym tekstam chasto delayut
|
|
|
|
podderzhku PostgreSQL prevoshodyaschej drugie SUBD.
|
|
|
|
Suschestvuet kommercheskaya podderzhka po rezul'tam voznikshih
|
|
|
|
incidentov, kotoraya dostupna dlya teh komu ona nuzhna.
|
2005-02-11 07:53:51 +03:00
|
|
|
(Smotrite Sekciyu 1.5.)
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
Cena
|
|
|
|
Nash produkt besplaten kak dlya kommercheskogo tak, i ne dlya
|
|
|
|
kommercheskogo ispol'zovaniya. Vy mozhete dobavlyat' svoj kod v
|
|
|
|
nash produkt bez ogranichenij, za isklyucheniem teh, chto
|
|
|
|
opisyvayutsya v nashej licenzii stilya BSD, kotoraya privedena
|
|
|
|
vyshe.
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
Voprosy pol'zovatelej po klientskoj chasti
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
2.1) Kakie interfejsy est' dlya PostgreSQL?
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
Ustanovka PostgreSQL vklyuchaet tol'ko C i vstroennyj (embedded) C
|
|
|
|
interfejsy. Vse drugie interfejsy yavlyayutsya nezavisimymi proektami
|
|
|
|
i zagruzhayutsya otdel'no; samostoyatel'nost' proektov pozvolyaet im
|
|
|
|
organizovat' sobstvennoe raspisanie vypuskov novyh versij i imet'
|
|
|
|
sobstvennuyu komandu razrabotchikov.
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
Nekotorye yazyki programmirovaniya, takie kak PHP vklyuchayut v sebya
|
|
|
|
interfejs k PostgreSQL. Interfejsy dlya takih yazykov kak Perl, TCL,
|
|
|
|
Python i mnogih drugih, dostupny na http://gborg.postgresql.org v
|
|
|
|
sekcii Drivers/Interfaces, a takzhe cherez poisk v Internet.
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
2.2) Kakie instrumenty suschestvuyut dlya ispol'zovaniya PostgreSQL cherez
|
|
|
|
Web?
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
Prekrasnoe vvedenie vo vzaimodejstvie baz dannyh i Web mozhno najti
|
|
|
|
na: http://www.webreview.com
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
Dlya integracii s Web, PHP http://www.php.net yavlyaetsya neplohim
|
|
|
|
interfejsom.
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
V slozhnyh sluchayah, mnogie pol'zuyutsya Perl i CGI.pm ili mod_perl.
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-12-18 23:38:48 +03:00
|
|
|
2.3) Est' li u PostgreSQL graficheskij interfejs pol'zovatelya?
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-12-18 23:38:48 +03:00
|
|
|
Da, suschestvuet neskol'ko graficheskih interfejsov dlya PostgreSQL.
|
2005-02-11 07:53:51 +03:00
|
|
|
Oni vklyuchayut PgAdmin III (http://www.pgadmin.org), PgAccess
|
|
|
|
(http://www.pgaccess.org), RHDB Admin
|
2005-01-04 06:47:03 +03:00
|
|
|
(http://sources.redhat.com/rhdb/), TORA (http://www.globecom.net/tora/
|
2005-02-11 07:53:51 +03:00
|
|
|
chastichno kommercheskoe PO) i Rekall (
|
|
|
|
http://www.rekallrevealed.org/). Takzhe est' PhpPgAdmin (
|
|
|
|
http://phppgadmin.sourceforge.net/) - interfejs k PostgreSQL,
|
|
|
|
osnovannyj na Web.
|
2002-04-12 13:17:10 +04:00
|
|
|
_________________________________________________________________
|
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
Voprosy administrirovaniya
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
3.1) Kak mne ustanovit' PostgreSQL v mesto otlichnoe ot /usr/local/pgsql?
|
|
|
|
|
|
|
|
Zadajte opciyu --prefix kogda zapuskaete configure.
|
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
3.2) Kak mne upravlyat' soedineniyami s drugih komp'yuterov?
|
2002-11-10 22:48:41 +03:00
|
|
|
|
|
|
|
Po umolchaniyu, PostgreSQL razreshaet tol'ko soedineniya na lokal'noj
|
2005-02-11 07:53:51 +03:00
|
|
|
mashine cherez sokety domena Unix ili TCP/IP soedineniya. Dlya togo,
|
|
|
|
chtoby drugie mashiny smogli podklyuchit'sya k baze vy dolzhny
|
|
|
|
izmenit' listen_addresses v postgresql.conf, razreshit'
|
|
|
|
host-avtorizaciya v fajle $PGDATA/pg_hba.conf i perestartovat' server.
|
2002-11-10 22:48:41 +03:00
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
3.3) Kakie nastrojki mne nuzhno sdelat' dlya uluchsheniya
|
2002-11-10 22:48:41 +03:00
|
|
|
proizvoditel'nosti?
|
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
Suschestvuet tri glavnyh oblasti, kotorye potencial'no mogut
|
|
|
|
uvelichit' proizvoditel'nost':
|
|
|
|
|
|
|
|
Izmenenie zaprosa
|
|
|
|
`Eto oznachaet modifikaciyu zaprosov dlya polucheniya luchshej
|
|
|
|
proizvoditel'nosti:
|
|
|
|
|
|
|
|
+ Sozdanie indeksov, vklyuchaya indeksy vyrazhenij i
|
|
|
|
chastichnye indeksy
|
|
|
|
+ Ispol'zovanie COPY vmesto mnozhestva INSERT
|
|
|
|
+ Gruppirovka neskol'kih operatorov v edinuyu tranzakciyu dlya
|
|
|
|
umen'sheniya nagruzki pri vypolnenii zaversheniya tranzakcii
|
|
|
|
+ Ispol'zovanie CLUSTER, kogda iz indeksa beriotsya mnozhestvo
|
|
|
|
strok
|
|
|
|
+ Ispol'zovanie LIMIT dlya togo, chtoby vozvraschalas' tol'ko
|
|
|
|
chast' vyvoda ot zaprosa
|
|
|
|
+ Ispol'zovanie Podgotovlennyh (Prepared) zaprosov
|
|
|
|
+ Ispol'zovanie ANALYZE dlya obsluzhivaniya statistiki
|
|
|
|
optimizatora
|
|
|
|
+ Regulyarnoe ispol'zovanie VACUUM ili pg_autovacuum
|
|
|
|
+ Udalenie indeksov vo vremya bol'shih izmenenij dannyh
|
|
|
|
|
|
|
|
Nastrojka servera
|
|
|
|
Nekotorye ustanovki v postgresql.conf vliyayut na
|
|
|
|
proizvoditel'nost'. Podrobnyj polnyj spisok ustanovok sm. v
|
|
|
|
Administration Guide/Server Run-time Environment/Run-time
|
|
|
|
Configuration, a kommentarii sm. v
|
|
|
|
http://www.varlena.com/varlena/GeneralBits/Tidbits/annotated_co
|
|
|
|
nf_e.html i
|
|
|
|
http://www.varlena.com/varlena/GeneralBits/Tidbits/perf.html.
|
|
|
|
|
|
|
|
Vybor "zheleza" - apparatnogo obespecheniya
|
|
|
|
Vliyanie "zheleza" na proizvoditel'nost' podrobno opisano v
|
|
|
|
http://candle.pha.pa.us/main/writings/pgsql/hw_performance/inde
|
|
|
|
x.html i http://www.powerpostgresql.com/PerfList/.
|
|
|
|
|
|
|
|
3.4) Kakie vozmozhnosti dlya otladki est' v nalichii?
|
2002-11-10 22:48:41 +03:00
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
Est' mnozhestvo ustanovok v nastrojkah servera, nachinayuschihsya na
|
|
|
|
log_*, pozvolyayuschih protokolirovat' zaprosy i statistiku raboty
|
|
|
|
processa, kotoraya ochen' polezna dlya otladki i izmereniya
|
|
|
|
proizvoditel'nosti.
|
|
|
|
|
|
|
|
Dlya predostavleniya bolee detal'noj informacii razrabotchikam servera
|
|
|
|
pri otladke kakoj-libo problemy dolzhny pol'zovat'sya sleduyuschie
|
|
|
|
instrukcii.
|
|
|
|
|
|
|
|
Takim zhe obrazom mozhno proizvodit' i otladku severa, esli on
|
|
|
|
rabotaet nepravil'no. Vo-pervyh, pri zapuske configure s opciej
|
|
|
|
--enable-cassert, mnogie vyzovy assert() pozvolyayut otslezhivat'
|
|
|
|
rabotu backend processa i ostanovku programmy pri vozniknovenii
|
|
|
|
kakih-libo neozhidannostej.
|
2002-11-10 22:48:41 +03:00
|
|
|
|
|
|
|
Esli postmaster ne zapuschen, vy mozhete zapustit' postgres backend iz
|
|
|
|
komandnoj stroki i vvesti vash operator SQL napryamuyu. `Eto
|
|
|
|
rekomenduetsya tol'ko dlya celej otladki. Zametim, chto v `etom
|
|
|
|
rezhime, zapros zavershaetsya simvolom novoj stroki, a ne tochkoj s
|
2005-02-11 07:53:51 +03:00
|
|
|
zapyatoj. Esli vy proizvodili kompilyaciyu s otladochnymi simvolami,
|
2002-11-10 22:48:41 +03:00
|
|
|
vy mozhete ispol'zovat' lyuboj otladchik, chtoby posmotret', chto
|
|
|
|
sluchilos'. Poskol'ku backend zapuskaetsya ne iz postmaster, on ne
|
|
|
|
zapuskaetsya v identichnom okruzhenii i znachit problemy iteracij
|
|
|
|
blokirovok/backend ne mogut byt' vosproizvedeny.
|
|
|
|
|
|
|
|
Esli postmaster zapuschen, zapustite psql v odnom okne, zatem najdite
|
2005-02-11 07:53:51 +03:00
|
|
|
PID processa postgres, ispol'zuemyj psql, ispol'zuya SELECT
|
|
|
|
pg_backend_pid(). Ispol'zujte otladchik dlya podklyucheniya k postgres
|
|
|
|
PID. Vy mozhete ustanovit' tochki preryvaniya v otladchike i zapustit'
|
|
|
|
zapros iz psql. Esli vy proizvodite otladku zapuska postgres, vy
|
|
|
|
mozhete ustanovit' PGOPTIONS="-W n", i zatem zapustit' psql. `Eta
|
|
|
|
opciya privodit k zaderzhke processa zapuska na n sekund, v techenie
|
|
|
|
kotoryh vy mozhete podklyuchit' k processu otladchik, ustanovit'
|
|
|
|
lyubye tochki preryvaniya i prodolzhit' zapusk.
|
2002-11-10 22:48:41 +03:00
|
|
|
|
|
|
|
Vy takzhe mozhete skompilirovat' PostgreSQL s profilirovaniem dlya
|
|
|
|
togo, chtoby uvidet' kakie funkcii skol'ko vremeni vypolnyayutsya.
|
|
|
|
Fajly profilirovaniya backend'a nahodyatsya v kataloge
|
|
|
|
pgsql/data/base/dbname. Fajl profilirovaniya klienta budet pomeschen v
|
|
|
|
tekuschij katalog klienta. V Linux dlya vypolneniya profilirovaniya
|
|
|
|
trebuetsya kompilyacii s -DLINUX_PROFILE.
|
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
3.5) Pochemu ya poluchayu soobschenie "Sorry, too many clients" kogda
|
2002-11-10 22:48:41 +03:00
|
|
|
pytayus' podklyuchit'sya k baze?
|
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
Vy dostigli ustanovlennogo po umolchaniyu ogranicheniya na 100 sessij
|
|
|
|
podklyucheniya k baze dannyh. Vam neobhodimo uvelichit' dlya
|
|
|
|
postmaster limit na kolichestvo konkurentnyh backend processov,
|
|
|
|
izmeniv znachenie max_connections v fajle postgresql.conf i
|
|
|
|
perestartovat' postmaster.
|
2002-08-23 06:53:20 +04:00
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
3.6) Pochemu neobhodimo delat' dump i restore pri obnovlenii vypuskov
|
2002-11-10 22:48:41 +03:00
|
|
|
PostgreSQL?
|
|
|
|
|
|
|
|
Razrabotchiki PostgreSQL delayut tol'ko nebol'shie izmeneniya mezhdu
|
2005-02-11 07:53:51 +03:00
|
|
|
podvypuskami. Takim obrazom obnovlenie s versii 7.4 do 7.4.1 ne
|
2002-11-10 22:48:41 +03:00
|
|
|
trebuet vypolneniya dump i restore. Odnako pri vyhode ocherednogo
|
2005-02-11 07:53:51 +03:00
|
|
|
vypuska (t.e. pri obnovlenii naprimer, s 7.3 na 7.4) chasto menyaetsya
|
2002-11-10 22:48:41 +03:00
|
|
|
vnutrennij format sistemnyh tablic i fajlov dannyh. `Eti izmeneniya
|
|
|
|
chasto nosyat kompleksnyj harakter, tak chto net vozmozhnosti
|
|
|
|
obespechit' obratnuyu sovmestimost' fajlov dannyh. Vypolenie dump
|
|
|
|
pozvolyaet poluchit' dannye v obschem formate, kotoryj zatem mozhet
|
|
|
|
byt' zagruzhen pri ispol'zovanii novogo vnutrennego formata.
|
|
|
|
|
|
|
|
V teh vypuskah, gde format dannyh na diske ne menyaetsya, dlya
|
|
|
|
provedeniya obnovleniya mozhet byt' ispol'zovan scenarij pg_upgrade
|
|
|
|
bez ispol'zovaniya dump/restore. Kommentarii k vypusku govorit kogda
|
|
|
|
mozhno ispol'zovat' pg_upgrade dlya `etogo vypuska.
|
2004-10-26 21:28:27 +04:00
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
3.7) Kakoe komp'yuternoe "zhelezo" ya dolzhen ispol'zovat'?
|
2004-10-26 21:28:27 +04:00
|
|
|
|
|
|
|
Poskol'ku "zhelezo" personal'nyh komp'yuterov yavlyaetsya naibolee
|
|
|
|
sovmestimym, lyudi sklonny verit', chto takoe "zhelezo" imeet
|
|
|
|
odinakovoe kachestvo. `Eto ne tak. Pamyat' ECC, SCSI i kachestvennye
|
|
|
|
materinskie platy yavlyayutsya bolee nadiozhnymi i imeyut bolee
|
|
|
|
luchshuyu proizvoditel'nost', chem menee dorogoe "zhelezo". PostgreSQL
|
|
|
|
budet rabotat' na lyubom "zheleze", no esli dlya vas vazhny
|
|
|
|
nadiozhnost' i proizvoditel'nost', to s vashej storony budet mudro
|
|
|
|
postavit' sootvetstvuyuschee "zhelezo". Obsudit' raznoe "zhelezo"
|
|
|
|
mozhno v nashih spiskah rassylki.
|
2002-04-12 13:17:10 +04:00
|
|
|
_________________________________________________________________
|
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
Voprosy `ekspluatacii
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
4.1) Kak vypolnit' SELECT tol'ko dlya neskol'kih pervyh strochek zaprosa?
|
2003-06-23 20:58:21 +04:00
|
|
|
Proizvol'noj stroki?
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
Dlya polucheniya tol'ko neskol'kih strok, esli vy znaete ih
|
|
|
|
kolichestvo na moment vypolneniya SELECT ispol'zujte LIMIT.
|
|
|
|
Esli est' kakoj-libo indeks, kotoryj sovpadaet s ORDER BY, to
|
|
|
|
vozmozhno, chto ves' zapros vypolnen i ne budet. Esli vy ne znaete
|
|
|
|
kolichestva neobhodimyh strok na moment vypolneniya SELECT,
|
|
|
|
ispol'zujte kursor i FETCH.
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2003-06-23 20:58:21 +04:00
|
|
|
To SELECT a random row, use:
|
|
|
|
SELECT col
|
|
|
|
FROM tab
|
|
|
|
ORDER BY random()
|
|
|
|
LIMIT 1;
|
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
4.2) Kak mne najti kakie tablicy, indeksy, bazy dannyh i pol'zovateli
|
|
|
|
suschestvuyut? Kak mne uvidet' zaprosy, kotorye ispol'zuet psql dlya
|
|
|
|
polucheniya `etoj informacii?
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2004-05-18 17:18:30 +04:00
|
|
|
CHtoby prosmatrivat' tablicy v psql, ispol'zujte komandu \dt. Polnyj
|
|
|
|
spisok komand v psql vy mozhete poluchit', ispol'zuya \?. Krome togo,
|
|
|
|
vy mozhete posmotret' ishodnyj kod psql v fajle
|
2002-11-10 22:48:41 +03:00
|
|
|
pgsql/src/bin/psql/describe.c. On soderzhit komandy SQL kotorye
|
|
|
|
generiruyutsya pri vvode v psql komand, nachinayuschihsya s obratnoj
|
2004-05-18 17:18:30 +04:00
|
|
|
kosoj cherty. Vy takzhe mozhete zapustit' psql s opciej -E tak, chtoby
|
|
|
|
`eta programma vydavala zaprosy, kotorye ona ispol'zuet dlya
|
2005-02-11 07:53:51 +03:00
|
|
|
vypolneniya zadannyh vami komand. PostgreSQL takzhe predostavlyaet SQL
|
|
|
|
sovmestimyj s INFORMATION SCHEMA interfejs, s pomosch'yu kotorogo, vy
|
|
|
|
mozhete sformirovat' zapros na poluchenie informacii o baze dannyh.
|
|
|
|
|
|
|
|
Takzhe suschestvuyut sistemnye tablicy, nachinayuschiesya s pg_.
|
|
|
|
|
|
|
|
Ispol'zujte psql -l dlya polucheniya spiska vseh baz dannyh.
|
2002-11-10 22:48:41 +03:00
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
Takzhe posmotrite fajl pgsql/src/tutorial/syscat.source. On pokazyvaet
|
|
|
|
mnogie iz operatorov SELECT neobhodimyh dlya polucheniya informacii iz
|
|
|
|
sistemnyh tablic bazy dannyh.
|
|
|
|
|
|
|
|
4.3) Kak izmenit' tip dannyh kolonki?
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
V 8.0 i bolee pozdnih versiyah, izmenenie tipa kolonki vypolnyaetsya
|
|
|
|
ochen' legko cherez ALTER TABLE ALTER COLUMN TYPE.
|
|
|
|
|
|
|
|
V bolee rannih versiyah sdelajte tak:
|
2003-06-23 20:58:21 +04:00
|
|
|
BEGIN;
|
|
|
|
ALTER TABLE tab ADD COLUMN new_col new_data_type;
|
|
|
|
UPDATE tab SET new_col = CAST(old_col AS new_data_type);
|
2003-10-10 06:52:12 +04:00
|
|
|
ALTER TABLE tab DROP COLUMN old_col;
|
2003-06-23 20:58:21 +04:00
|
|
|
COMMIT;
|
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
4.4) Kakovy maksimal'nye razmery dlya strok v tablice, tablic i bazy
|
|
|
|
dannyh?
|
2002-11-10 22:48:41 +03:00
|
|
|
|
|
|
|
Suschestvuyut sleduyuschie ogranicheniya:
|
2005-02-11 07:53:51 +03:00
|
|
|
|
|
|
|
Maksimal'nyj razmer bazy? neogranichen (suschestvuyut bazy na 32 TB)
|
|
|
|
Maksimal'nyj razmer tablicy? 32 TB
|
|
|
|
Maksimal'nyj razmer stroki? 1.6 TB
|
|
|
|
Maksimal'nyj razmer polya? 1 GB
|
|
|
|
Maksimal'noe kolichestvo strok v tablice? neogranicheno
|
|
|
|
Maksimal'noe kolichestvo kolonok v tablice? 250-1600 v zavisimosti ot
|
|
|
|
tipa
|
|
|
|
Maksimal'noe kolichestvo indeksov v tablice? neogranicheno
|
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
Razumeetsya, ponyatie "neogranicheno" na samom dele ogranichivaetsya
|
|
|
|
dostupnym diskovym prostranistvom i razmerami pamyati/svoppinga. Kogda
|
|
|
|
znacheniya perechislennye vyshe neopravdano bol'shie, mozhet
|
|
|
|
postradat' proizvoditel'nost'.
|
|
|
|
|
2003-10-10 06:52:12 +04:00
|
|
|
Maksimal'nyj razmer tablicy v 32 TB ne trebuet chtoby operacionnaya
|
2002-11-10 22:48:41 +03:00
|
|
|
sistema podderzhivala fajly bol'shih razmerov. Bol'shie tablicy
|
|
|
|
hranyatsya kak mnozhestvo fajlov razmerom v 1 GB, tak chto
|
|
|
|
ogranicheniya, kotorye nakladyvaet fajlovaya sistema ne vazhny.
|
|
|
|
|
|
|
|
Maksimal'nyj razmer tablicy i maksimal'noe kolichestvo kolonok mogut
|
2003-10-10 06:52:12 +04:00
|
|
|
byt' uvelicheny v chetyre raza, esli razmer bloka po umolchaniyu budet
|
|
|
|
uvelichen do 32k.
|
2002-11-10 22:48:41 +03:00
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
4.5) Kak mnogo diskovogo prostranstva v baze dannyh nuzhno dlya sohraneniya
|
2002-11-10 22:48:41 +03:00
|
|
|
dannyh iz obychnogo tekstovogo fajla?
|
|
|
|
|
|
|
|
SUBD PostgreSQL mozhet potrebovat'sya diskovogo prostranstva do 5 raz
|
|
|
|
bol'she dlya sohraneniya dannyh iz prostogo tekstovogo fajla.
|
|
|
|
|
|
|
|
V kachestve primera, rassmotrim fajl v 100,000 strok v kazhdoj, iz
|
|
|
|
kotoryh celoe chislo i tekstovoe opisanie. Pri `etom dlina teksta, v
|
|
|
|
srednem, sostavlyaet 20 bajt. Razmer prostogo fajla sostavit 2.8 MB.
|
|
|
|
Razmer bazy PostgreSQL, soderzhaschej `eti zhe dannye sostavit
|
|
|
|
priblizitel'no 6.4 MB iz kotoryh:
|
2005-02-11 07:53:51 +03:00
|
|
|
32 bajt: na kazhdyj zagolovok stroki v tablice (priblizitel'no)
|
2002-11-10 22:48:41 +03:00
|
|
|
+ 24 bajta: odno pole s celochislennym tipom i odno tekstovoe pole
|
2005-02-11 07:53:51 +03:00
|
|
|
+ 4 bajta: ukazatel' na stranice dlya vsej tablichnoj stroki
|
2002-04-12 13:17:10 +04:00
|
|
|
----------------------------------------
|
2005-02-11 07:53:51 +03:00
|
|
|
60 bajt na stroku v tablice
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
Razmer stranicy dannyh v PostgreSQL sostavlyaet 8192 bajt (8 KB), tak chto:
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
8192 bajt na stranicu
|
2005-02-11 07:53:51 +03:00
|
|
|
--------------------- = 136 strok v tablice na stranicu BD (okruglionno)
|
|
|
|
60 bajt na stroku v tablice
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2004-04-12 07:22:20 +04:00
|
|
|
100000 strok dannyh
|
2004-10-26 21:28:27 +04:00
|
|
|
----------------------- = 735 stranic v BD (okruglionno)
|
2005-02-11 07:53:51 +03:00
|
|
|
128 strok v tablice na stranicu
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2004-10-26 21:28:27 +04:00
|
|
|
735 stranic BD * 8192 bajt na stranicu = 6,021,120 bajt (6 MB)
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
Indeksy ne trebuyut tak mnogo, no poskol'ku oni sozdayutsya dlya
|
|
|
|
bol'shogo kolichestva dannyh, oni takzhe mogut byt' veliki.
|
|
|
|
|
2004-04-12 07:22:20 +04:00
|
|
|
Znacheniya NULL hranyatsya kak bitovye karty i po`etomu oni zanimayut
|
2004-03-12 16:51:33 +03:00
|
|
|
ochen' malo mesta.
|
2002-11-10 22:48:41 +03:00
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
4.6) Pochemu moi zaprosy rabotayut medleno? Pochemu oni ne ispol'zuyut moi
|
|
|
|
indeksy?
|
2002-11-10 22:48:41 +03:00
|
|
|
|
|
|
|
Indeksy ne ispol'zuyutsya dlya kazhdogo zaprosa avtomaticheski. Oni
|
|
|
|
ispol'zuyutsya tol'ko esli tablica bol'she minimal'nogo razmera i
|
2005-02-11 07:53:51 +03:00
|
|
|
zapros vybiraet tol'ko malen'kij procent strok v tablice. Tak
|
2002-11-10 22:48:41 +03:00
|
|
|
ustroeno, potomu chto dostup k disku s primeneniem randomizacii pri
|
|
|
|
skanirovanii indeksov mozhet byt' medlennee, chem prostoe chtenie
|
|
|
|
tablicy ili ee posledovatel'noe skanirovanie.
|
|
|
|
|
|
|
|
CHtoby opredelit' neobhodimost' ispol'zovaniya indeksa dlya kakoj-libo
|
|
|
|
tablicy, PostgreSQL dolzhen imet' statistiku po `etoj tablice. `Eta
|
|
|
|
statistika sobiraetsya pri ispol'zovanii VACUUM ANALYZE ili prosto
|
|
|
|
ANALYZE. Ispol'zuya statistiku, optimizator uznaet o tom kak mnogo
|
2005-02-11 07:53:51 +03:00
|
|
|
strok v tablice i esli on dolzhen ispol'zovat' indeksy, to on mozhet
|
2002-11-10 22:48:41 +03:00
|
|
|
prinimat' luchshie resheniya. Statistika takzhe vliyaet na opredelenie
|
2005-02-11 07:53:51 +03:00
|
|
|
optimal'nogo poryadka svyazyvaniya i metoda svyazyvaniya. Pri
|
|
|
|
izmenenii soderzhimogo tablicy dolzhen periodicheski vypolnyatsya sbor
|
|
|
|
statistiki.
|
2002-11-10 22:48:41 +03:00
|
|
|
|
|
|
|
Obychno indeksy ne ispol'zuyutsya dlya ORDER BY ili dlya vypolneniya
|
|
|
|
svyazyvanij. Posledovatel'nyj perebor sleduyuschij za yavnoj
|
|
|
|
sortirovkoj obychno bystree, chem poisk po indeksam v bol'shoj
|
|
|
|
tablice. Odnako, ORDER BY chasto kombiniruetsya s LIMIT i v `etom
|
|
|
|
sluchae indeks budet ispol'zovat'sya, poskol'ku pri vypolnenii budet
|
|
|
|
vozvraschat'sya nebol'shaya chast' tablicy. Fakticheski MAX() i MIN()
|
|
|
|
ne ispol'zuyut indeksy, no indeks ispol'zuetsya pri postroenii
|
|
|
|
zaprosov s ORDER BY i LIMIT:
|
2002-08-23 06:53:20 +04:00
|
|
|
SELECT col
|
|
|
|
FROM tab
|
|
|
|
ORDER BY col [ DESC ]
|
2002-11-10 22:48:41 +03:00
|
|
|
LIMIT 1;
|
2002-08-23 06:53:20 +04:00
|
|
|
|
2004-04-12 07:22:20 +04:00
|
|
|
Esli vam kazhetsya, chto optimizator nekorrektno vybiraet
|
2003-02-14 17:05:00 +03:00
|
|
|
posledovatel'nyj perebor, ispol'zujte SET enable_seqscan TO 'off' i
|
|
|
|
zapustite testy, chtoby uvidet', ne stalo-li skanirovanie indeksov
|
|
|
|
bystree.
|
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
Kogda ispol'zuyutsya operacii s shablonami, naprimer LIKE ili ~,
|
|
|
|
indeksy mogut byt' ispol'zovany v sleduyuschih sluchayah:
|
|
|
|
* Nachalo stroki poiska dolzhno sovpadat' s nachalom iskomoj stroki,
|
|
|
|
t.e.:
|
|
|
|
+ LIKE shablony ne dolzhny nachinat'sya s %..
|
|
|
|
+ ~ shablony regulyarnyh vyrazhenij dolzhna nachinat'sya na ^.
|
|
|
|
* Stroka poiska ne dolzhna nachinat'sya s simvola klassa, t.e.
|
|
|
|
[a-e].
|
|
|
|
* Poisk nezavisimyj ot registra, takoj kak ILIKE i ~* ne ispol'zuet
|
2005-02-11 07:53:51 +03:00
|
|
|
indeksy. Vmesto nego, ispol'zujte indeksy vyrazhenij, kotorye
|
|
|
|
opisyvayutsya v sekcii 4.8.
|
2005-01-04 06:47:03 +03:00
|
|
|
* Vo vremya initdb dolzhna ispol'zovat'sya lokal' po umolchaniyu C,
|
2005-02-11 07:53:51 +03:00
|
|
|
potomu chto ne suschestvuet vozmozhnosti uznat' sleduyuschij
|
|
|
|
naibol'shij simvol dlya ne-C lokali. Vy mozhete dlya takih
|
|
|
|
sluchaev sozdat' special'nyj indeks text_pattern_ops kotoryj
|
|
|
|
rabotaet tol'ko dlya LIKE indeksirovaniya.
|
2002-08-23 06:53:20 +04:00
|
|
|
|
2004-10-26 21:28:27 +04:00
|
|
|
V vypuskah do versii 8.0, indeksy chasto nel'zya bylo ispol'zovat',
|
|
|
|
esli tipy dannyh tochno ne sovpadali s indeksnymi tipami kolonok. `Eto
|
|
|
|
osobenno kasalos' int2, int8 i numeric indeksov kolonok.
|
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
4.7) Kak posmotret' na to, kak optimizator vypolnyaet moj zapros?
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
Smotrite stranicu rukovodstva posvyaschennuyu EXPLAIN.
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
4.8) Kak mne vypolnit' poisk regulyarnogo vyrazheniya i poisk nezavisimyj
|
2002-11-10 22:48:41 +03:00
|
|
|
ot registra bukv poisk regulyarnogo vyrazheniya? Kak mne ispol'zovat'
|
|
|
|
indeks dlya poiska nezavisimogo ot registra bukv?
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
Operator ~ proizvodit poisk regulyarnogo vyrazheniya, a operator ~*
|
|
|
|
proizvodit nezavisimyj ot registra bukv poisk regulyarnogo
|
|
|
|
vyrazheniya. Nezavisimyj ot registra variant LIKE nazyvaetsya ILIKE.
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
Nezavisimoe ot registra sravnenie obychno vyrazhaetsya tak:
|
2002-04-12 13:17:10 +04:00
|
|
|
SELECT *
|
|
|
|
FROM tab
|
2002-11-10 22:48:41 +03:00
|
|
|
WHERE lower(col) = 'abc';
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
`Eta konstrukciya ne budet ispol'zovat' standartnyj indeks. Odnako,
|
2005-02-11 07:53:51 +03:00
|
|
|
esli vy sozdadite indeks vyrazheniya, on budet ispol'zovan:
|
2002-11-10 22:48:41 +03:00
|
|
|
CREATE INDEX tabindex ON tab (lower(col));
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
4.9) Kak ya mogu opredelit', chto znachenie polya ravno NULL v kakom-libo
|
2002-11-10 22:48:41 +03:00
|
|
|
zaprose?
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
Vy prosto sravnivaete znachenie s IS NULL i IS NOT NULL.
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
4.10) Kakovy otlichiya mezhdu raznymi simvol'nymi tipami?
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
Tip Vnutrennee imya Zamechaniya
|
|
|
|
VARCHAR(n) varchar razmer zadaet maksimal'nuyu dlinu, net zapolneniya
|
|
|
|
CHAR(n) bpchar zapolnyaetsya pustotoj do fiksirovannoj dliny
|
|
|
|
TEXT text net zadavaemogo verhnego ogranicheniya ili dliny
|
|
|
|
BYTEA bytea massiv bajt peremennoj dliny (mozhno ispol'zovat'
|
|
|
|
null-bajt bez opaski)
|
|
|
|
"char" char odin simvol
|
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
Vnutrennee imya vy mozhete uvidet', kogda smotrite sistemnye katalogi
|
|
|
|
i v nekotoryh soobscheniyah ob oshibkah.
|
|
|
|
|
2003-03-07 08:46:51 +03:00
|
|
|
Pervye chetyre tipa yavlyayutsya "varlena" tipami (t.e., pervye
|
2002-11-10 22:48:41 +03:00
|
|
|
chetyre bajta na diske yavlyayutsya dlinnoj, za kotoroj sleduyut
|
|
|
|
dannye). Takim obrazom, fakticheski ispol'zuemoe prostranstvo bol'she,
|
|
|
|
chem oboznachennyj razmer. Odnako, `eti tipy dannyh takzhe poddayutsya
|
|
|
|
szhatiyu ili mogut byt' sohraneny ne v strokom vide cherez TOAST, tak
|
|
|
|
chto zanimaemoe diskovoe prostranstvo mozhet takzhe byt' i men'she,
|
|
|
|
chem ozhidalos'.
|
2003-02-14 17:05:00 +03:00
|
|
|
VARCHAR(n) - `eto luchshee reshenie, kogda nuzhno hranit' stroki
|
|
|
|
peremennoj dliny, ne prevyshayuschie opredelennogo razmera. TEXT -
|
|
|
|
`eto luchshee reshenie dlya strok neogranichennoj dliny, s maksimal'no
|
|
|
|
dopustimoj dlinoj v 1 gigabajt.
|
2002-11-10 22:48:41 +03:00
|
|
|
|
|
|
|
CHAR(n) - `eto luchshee reshenie dlya hraneniya strok, kotorye obychno
|
2003-02-14 17:05:00 +03:00
|
|
|
imeyut odinakovuyu dlinu. CHAR(n) zapolnyaetsya pustotoj do zadannoj
|
|
|
|
dliny, v to vremya kak VARCHAR(n) hranit tol'ko simvoly, iz kotoryh
|
|
|
|
sostoit stroka. BYTEA ispol'zuetsya dlya hraneniya binarnyh dannyh,
|
2003-03-07 08:46:51 +03:00
|
|
|
znacheniya kotoryh mogut vklyuchat' NULL bajty. Vse tipy opisannye
|
|
|
|
zdes', imeyut shodnye harakteristiki proizvoditel'nosti.
|
2002-11-10 22:48:41 +03:00
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
4.11.1) Kak mne sozdat' pole serial/s-avto-uvelicheniem?
|
2002-11-10 22:48:41 +03:00
|
|
|
|
|
|
|
PostgreSQL podderzhivaet tip dannyh SERIAL. On avtomaticheski sozdaet
|
2003-11-28 23:20:33 +03:00
|
|
|
posledovatel'nost'. Naprimer:
|
2002-04-12 13:17:10 +04:00
|
|
|
CREATE TABLE person (
|
|
|
|
id SERIAL,
|
|
|
|
name TEXT
|
|
|
|
);
|
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
avtomaticheski transliruetsya v:
|
2002-04-12 13:17:10 +04:00
|
|
|
CREATE SEQUENCE person_id_seq;
|
|
|
|
CREATE TABLE person (
|
|
|
|
id INT4 NOT NULL DEFAULT nextval('person_id_seq'),
|
|
|
|
name TEXT
|
|
|
|
);
|
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
Smotrite podrobnosti o posledovatel'nostyah na stranice rukovodstva
|
2005-02-11 07:53:51 +03:00
|
|
|
posvyaschennoj create_sequence.
|
2002-11-10 22:48:41 +03:00
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
4.11.2) Kak mne poluchit' znachenie pri vstavke SERIAL?
|
2002-11-10 22:48:41 +03:00
|
|
|
|
|
|
|
Odin iz sposobov sostoit v poluchenii sleduyuschego znacheniya SERIAL
|
|
|
|
iz ob"ekta sequence s pomosch'yu funkcii nextval() pered vstavkoj i
|
|
|
|
zatem vstavlyat' `eto znachenie yavno. Ispol'zujte tablicu-primer v
|
2005-02-11 07:53:51 +03:00
|
|
|
4.11.1, primer v psevdoyazyke pokazhet kak `eto delaetsya:
|
2002-11-10 22:48:41 +03:00
|
|
|
new_id = execute("SELECT nextval('person_id_seq')");
|
|
|
|
execute("INSERT INTO person (id, name) VALUES (new_id, 'Blaise Pascal')");
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
Zatem vy dolzhny takzhe sohranit' novoe znachenie v peremennoj new_id
|
|
|
|
dlya ego ispol'zovaniya v drugih zaprosah (naprimer takih kak vneshnij
|
|
|
|
klyuch dlya tablicy person). Zametim, chto imya avtomaticheski
|
|
|
|
sozdannogo ob"ekta SEQUENCE budet <table>_<serialcolumn>_seq, gde
|
|
|
|
table i serialcolumn yavlyayutsya sootvetstvenno imenami vashej
|
|
|
|
tablicy i vashej kolonki SERIAL.
|
|
|
|
|
|
|
|
V kachestve al'ternativy, vy mozhete poluchit' naznachennoe znachenie
|
|
|
|
SERIAL s pomosch'yu funkcii currval() posle provedeniya obychnoj
|
|
|
|
operacii vstavki, naprimer
|
|
|
|
execute("INSERT INTO person (name) VALUES ('Blaise Pascal')");
|
|
|
|
new_id = execute("SELECT currval('person_id_seq')");
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
4.11.3) Ne mozhet li poluchit'sya tak, chto ispol'zovanie currval() i
|
2002-11-10 22:48:41 +03:00
|
|
|
nextval() privedet k zaciklirovaniyu s drugimi pol'zovatelyami?
|
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
Net. currval() vozvraschaet tekuschee znachenie, naznachennoe vashej
|
|
|
|
sessiej, a ne drugimi sessiyami.
|
2002-11-10 22:48:41 +03:00
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
4.11.4) Pochemu chisla iz moej posledovatel'nosti ne ispol'zuyutsya snova
|
2002-11-10 22:48:41 +03:00
|
|
|
pri otmene tranzakcii? Pochemu sozdayutsya razryvy pri numeracii v kolonke,
|
|
|
|
gde ya ispol'zuyu posledovatel'nost'/SERIAL?
|
|
|
|
|
|
|
|
Dlya realizacii konkuretnosti, znacheniya posledovatel'nostej, pri
|
|
|
|
neobhodimosti vydayutsya vo vremya zapuska tranzakcij i ne
|
|
|
|
blokiruyutsya do polnogo vypolneniya tranzakcij. `Eto mozhet vyzyvat'
|
|
|
|
razryvy v numeracii pri otmene tranzakcij.
|
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
4.12) CHto takoe OID? CHto takoe TID?
|
2002-11-10 22:48:41 +03:00
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
Kazhdaya, sozdavaemaya v PostgreSQL tablichnaya stroka, poluchaet
|
|
|
|
unikal'nyj indentifikator OID za isklyucheniem sluchaya kogda
|
|
|
|
ispol'zovalos' WITHOUT OIDS. OID - `eto avtomaticheski naznachaemoe
|
|
|
|
unikal'noe 4-h bajtovoe celoe chislo. Odnako, posle togo kak ego
|
|
|
|
znachenie prevysit 4 milliarda, znacheniya OID nachinayut
|
|
|
|
dublirovat'sya. PostgreSQL ispol'zuet OID dlya svyazyvaniya svoih
|
|
|
|
vnutrennih tablic.
|
|
|
|
|
|
|
|
Dlya unikal'nyh znachenij v kolonkah tablicy pol'zovatelya, luchshim
|
|
|
|
sposobom yavlyaetsya ispol'zovanie SERIAL vmesto OID, potomu chto
|
|
|
|
posledovatel'nosti SERIAL unikal'ny tol'ko vnutri tablicy i takim
|
|
|
|
obrazom men'she podverzheny perepolneniyu. Dlya hraneniya znachenij
|
|
|
|
8-mi bajtnoj posledovatel'nosti dostupen tip SERIAL8.
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
TID ispol'zuetsya dlya identifikacii special'nyh fizicheskih zapisej s
|
|
|
|
blochnymi i offset znacheniyami. TID izmenyaetsya posle togo kak
|
2005-02-11 07:53:51 +03:00
|
|
|
stroki v tablice byli izmeneny ili peregruzheny.
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
TID ispol'zuetsya indeksnymi zapisyami v kachestve ukazatelya na
|
|
|
|
fizicheskie zapisi.
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
4.13) Pochemu ya poluchayu oshibku "ERROR: Memory exhausted in
|
2002-11-10 22:48:41 +03:00
|
|
|
AllocSetAlloc()"?
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
Predpolozhitel'no u vas zakonchilas' virtual'naya pamyat' ili chto
|
|
|
|
vashe yadro imeet malen'kij limit na opredelennye resursy. Popytajtes'
|
|
|
|
pered zapuskom postmaster vypolnit' sleduyuschie komandy:
|
2002-04-12 13:17:10 +04:00
|
|
|
ulimit -d 262144
|
|
|
|
limit datasize 256m
|
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
V zavisimosti ot komandnogo interpretatora shell, tol'ko odna iz
|
|
|
|
dannyh komand vypolnitsya uspeshno, no ona pozvolit vam ustanovit'
|
|
|
|
bol'shij segment dannyh processa i vozmozhno reshit problemu. `Eta
|
|
|
|
komanda izmenyaet parametry tekuschego processa i vseh ego potomkov,
|
|
|
|
sozdannyh posle eio zapuska. Esli u vas voznikla problema s SQL
|
|
|
|
klientom, potomu chto backend vozvraschaet slishkom bol'shoj ob"em
|
|
|
|
dannyh, popytajtes' vypolnit' `etu komandu pered zapuskom klienta.
|
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
4.14) Kak mne uznat', kakaya versiya PostgreSQL zapuschena?
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
Iz psql, naberite SELECT version();
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
4.15) Pochemu pri rabote s moim bol'shim ob"ektom ya poluchayu oshibku
|
2002-11-10 22:48:41 +03:00
|
|
|
"invalid large obj descriptor"?
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
Vam nuzhno pri ispol'zovanii bol'shogo ob"ekta pomestit' v nachale
|
|
|
|
BEGIN WORK i v konce COMMIT, a vnutri poluchivshegosya bloka lo_open
|
|
|
|
... lo_close.
|
|
|
|
|
|
|
|
V nastoyaschij moment PostgreSQL trebuet, chtoby pri zakrytii
|
|
|
|
bol'shogo ob"ekta proishodilo vypolnenie tranzakcii. Takim obrazom,
|
|
|
|
pervaya zhe popytka sdelat' chto-libo s bol'shim ob"ektom, ne
|
|
|
|
soblyudaya dannogo pravila privedet k soobscheniyu invalid large obj
|
|
|
|
descriptor, tak kak kod vypolnyayuschij rabotu nad bol'shim ob"ektom
|
|
|
|
(po krajnej mere v nastoyaschij moment) budet generirovat' soobschenie
|
|
|
|
ob oshibke esli vy ne ispol'zuete tranzakciyu.
|
|
|
|
|
|
|
|
Esli vy ispol'zuete takoj interfejs klienta kak ODBC, vam vozmozhno
|
|
|
|
ponadobitsya ustanovit' auto-commit off.
|
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
4.16) Kak mne sozdat' kolonku kotoraya po umolchaniyu budet soderzhat'
|
2002-11-10 22:48:41 +03:00
|
|
|
tekuschee vremya?
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
Ispol'zujte CURRENT_TIMESTAMP:
|
2005-02-11 07:53:51 +03:00
|
|
|
CREATE TABLE test (x int, modtime TIMESTAMP DEFAULT CURRENT_TIMESTAMP );
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
4.17) Kak mne vypolnit' vneshnee svyazyvanie?
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
PostgreSQL podderzhivaet vneshnee svyazyvanie, ispol'zuya standartnyj
|
|
|
|
sintaksis SQL. Vot dva primera:
|
2002-04-12 13:17:10 +04:00
|
|
|
SELECT *
|
|
|
|
FROM t1 LEFT OUTER JOIN t2 ON (t1.col = t2.col);
|
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
ili
|
2002-04-12 13:17:10 +04:00
|
|
|
SELECT *
|
|
|
|
FROM t1 LEFT OUTER JOIN t2 USING (col);
|
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
`Eto identichnye zaprosy svyazyvaniya t1.col i t2.col, takzhe
|
2005-02-11 07:53:51 +03:00
|
|
|
vozvraschayut lyubye nesvyazannye stroki v t1 (kotorye ne sovpadayut s
|
|
|
|
t2). RIGHT svyazyvanie dolzhno dobavit' nesvyazannye stroki t2. FULL
|
|
|
|
svyazyvanie dolzhno vozvratit' sovpavshie stroki plyus vse
|
|
|
|
nesvyazannye stroki iz t1 i t2. Slovo OUTER yavlyaetsya
|
2002-11-10 22:48:41 +03:00
|
|
|
neobyazatel'nym i naznachaetsya v LEFT, RIGHT i FULL svyazyvaniyah.
|
|
|
|
Obychnye svyazyvaniya nazyvayutsya INNER svyazyvaniya.
|
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
4.18) Kak vypolnyat' zaprosy, ispol'zuyuschie neskol'ko baz dannyh?
|
2002-11-10 22:48:41 +03:00
|
|
|
|
|
|
|
Ne suschestvuet sposoba sozdat' zapros k bazam dannyh otlichnym ot
|
|
|
|
tekuschej. Poskol'ku PostgreSQL zagruzhaet sistemnye katalogi
|
|
|
|
specifichnye dlya bazy dannyh, neponyatno dazhe, kak dolzhen sebya
|
|
|
|
vesti takoj mezhbazovyj zapros.
|
|
|
|
|
|
|
|
contrib/dblink pozvolyaet zaprosy mezhdu bazami, ispol'zuya vyzovy
|
2005-02-11 07:53:51 +03:00
|
|
|
funkcij. Razumeetsya, klient mozhet odnovremenno takzhe ustanavlivat'
|
2002-11-10 22:48:41 +03:00
|
|
|
soedieneniya s razlichnymi bazami dannyh i takih obrazom ob"edinyat'
|
|
|
|
informaciyu iz nih.
|
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
4.19) Kak mne vernut' iz funkcii neskol'ko strok tablicy?
|
2002-11-10 22:48:41 +03:00
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
Vy mozhete legko ispol'zovat' funkcii, vozvraschayuschie spisok,
|
|
|
|
http://techdocs.postgresql.org/guides/SetReturningFunctions.
|
2002-11-10 22:48:41 +03:00
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
4.20) Pochemu ya ne mogu nadezhno sozdavat'/udalyat' vremennye tablicy v
|
2002-11-10 22:48:41 +03:00
|
|
|
funkciyah PL/PgSQL?
|
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
PL/PgSQL k`eshiruet scenarii funkcii i odin iz negativnyh `effektov
|
2002-11-10 22:48:41 +03:00
|
|
|
`etogo sostoit v tom, chto esli funkciya PL/PgSQL obraschaetsya k
|
|
|
|
vremennoj tablice i `eta tablica pozdnee udalyaetsya i peresozdaetsya,
|
|
|
|
a funkciya zatem vyzyvaetsya snova, to ee vyzov privedet k oshibke,
|
|
|
|
potomu chto sk`eshirovannoe soderzhimoe funkcii soderzhit ukazatel' na
|
|
|
|
staruyu vremennuyu tablicu. CHtoby reshit' `etu problemu, ispol'zujte
|
|
|
|
EXECUTE dlya dostupa k vremennym tablicam v PL/PgSQL. Ispol'zovanie
|
|
|
|
`etogo operatora zastavit zapros peregenerirovat'sya kazhdyj raz.
|
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
4.21) Kakie opcii shifrovaniya suschestvuyut?
|
2002-11-10 22:48:41 +03:00
|
|
|
|
|
|
|
* contrib/pgcrypto soderzhit mnogo funkcij shifrovaniya dlya
|
|
|
|
ispol'zovaniya v SQL zaprosah.
|
2003-10-10 06:52:12 +04:00
|
|
|
* Dlya shifrovaniya peredavaemyh dannyh ot klienta k serveru, na
|
|
|
|
servere v fajle postgresql.conf, opciya ssl dolzhna byt'
|
|
|
|
ustanovlena v true, v fajle pg_hba.conf dolzhna byt'
|
|
|
|
sootvetstvuyuschaya zapis' host ili hostssl i na storone klienta
|
|
|
|
sslmode ne dolzhen byt' zapreschion cherez disable. (Zametim, chto
|
|
|
|
takzhe vozmozhno ispol'zovanie nezavisimyh vneshnih shifruyuschih
|
|
|
|
transportov, takih kak stunnel ili ssh, vmesto sobstvennyh SSL
|
|
|
|
soedinenij PostgreSQL).
|
2002-11-10 22:48:41 +03:00
|
|
|
* Paroli pol'zovatelej k baze dannyh avtomaticheski shifruyutsya,
|
2005-02-11 07:53:51 +03:00
|
|
|
pri sohranenii v sistemnyh tablicah.
|
2002-11-10 22:48:41 +03:00
|
|
|
* Server mozhno zapustit', ispol'zuya shifrovannuyu fajlovuyu
|
|
|
|
sistemu.
|
2002-04-12 13:17:10 +04:00
|
|
|
_________________________________________________________________
|
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
Rasshireniya PostgreSQL
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
5.1) YA napisal funkciyu opredelyaemuyu pol'zovatelem. Kogda ya zapuskayu
|
2004-04-12 07:22:20 +04:00
|
|
|
ee v psql, pochemu ya poluchayu core dump?
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
Problema mozhet zaklyuchat'sya v neskol'kih veschah. Popytajtes'
|
|
|
|
sperva protestirovat' vashu funkciyu v otdel'noj samostoyatel'noj
|
|
|
|
programme.
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
5.2) Kak ya mogu vnesti nekotorye klassnye novye tipy i funkcii v
|
2002-04-12 13:17:10 +04:00
|
|
|
PostgreSQL?
|
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
Otprav'te vashi rasshireniya v spisok rassylki pgsql-hackers i oni po
|
|
|
|
vozmozhnosti budut pomescheny v podkatalog contrib/.
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
5.3) Kak mne napisat' C funkciyu, vozvraschayuschuyu stroku tablicy?
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
V versiyah PostgreSQL, nachinaya s 7.3, funkcii, vozvraschayuschie
|
|
|
|
tablicy polnost'yu podderzhivayutsya v C, PL/PgSQL i SQL. Podrobnosti
|
|
|
|
smotrite v Rukovodstve Programmista. Primer vozvraschayuschej tablicu
|
|
|
|
funkcii, napisannoj na C, mozhno najti v contrib/tablefunc.
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
5.4) YA izmenil ishodnyj fajl. Pochemu posle perekompilyacii ya ne vizhu
|
|
|
|
izmenenij?
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
Fajly Makefile ne imeyut pravil'nyh zavisimostej dlya include fajlov.
|
|
|
|
Vy dolzhny vypolnit' make clean i zatem make. Esli vy ispol'zuete GCC
|
|
|
|
vy mozhete ispol'zovat' opciyu --enable-depend v configure chtoby
|
|
|
|
poruchit' kompilyatoru avtomaticheski otslezhivat' zavisimosti.
|