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-06-03 22:17:07 +04:00
|
|
|
Data poslednego obnovleniya: Ponedel'nik 30 maya 09:11:03 EDT 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)
|
|
|
|
|
2005-06-03 22:17:07 +04:00
|
|
|
Pereviol 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?
|
2005-06-03 22:17:07 +04:00
|
|
|
1.13) Kto upravlyaet PostgreSQL?
|
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-06-03 22:17:07 +04:00
|
|
|
4.9) Kak mne opredelit', chto znachenie polya ravno NULL v kakom-libo
|
|
|
|
zaprose? Mogu ya otsortirovat' polya NULL ili net?
|
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-06-03 22:17:07 +04:00
|
|
|
4.12) CHto takoe OID? CHto takoe CTID?
|
2005-02-11 07:53:51 +03:00
|
|
|
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?
|
2005-06-03 22:17:07 +04:00
|
|
|
4.15) Kak mne sozdat' kolonku kotoraya po umolchaniyu budet soderzhat'
|
2002-11-10 22:48:41 +03:00
|
|
|
tekuschee vremya?
|
2005-06-03 22:17:07 +04:00
|
|
|
4.16) Kak vypolnit' vneshnee svyazyvanie?
|
|
|
|
4.17) Kak vypolnyat' zaprosy, ispol'zuyuschie neskol'ko baz dannyh?
|
|
|
|
4.18) Kak mne vernut' iz funkcii neskol'ko strok tablicy?
|
|
|
|
4.19) Pochemu ya poluchayu oshibku "relation with OID #### ne
|
|
|
|
suschestvuet", kogda obraschayuts' k vremennym tablicam v funkciyah
|
|
|
|
PL/PgSQL?
|
|
|
|
4.20) Kakie est' resheniya dlya replikacii?
|
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
|
|
|
|
2005-06-03 22:17:07 +04:00
|
|
|
1.1) CHto takoe PostgreSQL? Kak proiznositsya `eto nazvanie?
|
|
|
|
|
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
|
|
|
|
2005-06-03 22:17:07 +04: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
|
2005-06-03 22:17:07 +04:00
|
|
|
Portions Copyright (c) 1994-1996 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-06-03 22:17:07 +04: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
|
|
|
|
2005-06-03 22:17:07 +04:00
|
|
|
PostgreSQL takzhe 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-06-03 22:17:07 +04:00
|
|
|
1.4) Gde mozhno vzyat' PostgreSQL?
|
|
|
|
|
|
|
|
CHerez brauzer, ispol'zuya http://www.postgresql.org/ftp/ i cherez
|
|
|
|
ftp, ispol'zuya ftp://ftp.PostgreSQL.org/pub/.
|
2002-11-10 22:48:41 +03:00
|
|
|
|
2005-06-03 22:17:07 +04:00
|
|
|
1.5) Gde poluchit' podderzhku?
|
|
|
|
|
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-06-03 22:17:07 +04:00
|
|
|
1.6) Kak mne soobschit' ob oshibke?
|
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
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
|
2005-06-03 22:17:07 +04:00
|
|
|
FTP sajte ftp://ftp.PostgreSQL.org/pub/.
|
2005-02-11 07:53:51 +03:00
|
|
|
|
2005-06-03 22:17:07 +04:00
|
|
|
1.7) Kakaya poslednyaya versiya?
|
|
|
|
|
|
|
|
Poslednij vypusk PostgreSQL - `eto versiya 8.0.2
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2005-06-03 22:17:07 +04:00
|
|
|
My planiruem vypuskat' novye starshie versii kazhdyj god, a mladshie
|
|
|
|
versii kazhdye neskol'ko mesyacev.
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2005-06-03 22:17:07 +04:00
|
|
|
1.8) Kakaya dokumentaciya imeetsya v nalichii?
|
|
|
|
|
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
|
2005-02-21 20:33:54 +03:00
|
|
|
http://www.PostgreSQL.org/docs/books/awbook.html i
|
2005-06-03 22:17:07 +04:00
|
|
|
http://www.commandprompt.com/ppbook/. Est' neskol'ko knig po
|
|
|
|
PostgreSQL, kotorye mozhno kupit'. Odnu iz naibolee populyarnyh
|
|
|
|
napisal Korri Duglas (Korry Douglas). Spisok obzorov po `etim knigam
|
|
|
|
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.
|
|
|
|
|
2005-06-03 22:17:07 +04:00
|
|
|
1.9) Kak najti informaciyu ob izvestnyh oshibkah ili otsutstvuyuschih
|
|
|
|
vozmozhnostyah?
|
|
|
|
|
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
|
|
|
|
2005-06-03 22:17:07 +04:00
|
|
|
1.10) Kak mne nauchit'sya SQL?
|
|
|
|
|
|
|
|
Vo-pervyh, voz'mite odnu iz knig po PostgreSQL, o kotoryh govorilos'
|
|
|
|
vyshe. 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. Mnogim
|
|
|
|
iz nashih pol'zovatelej nravitsya kniga The Practical SQL Handbook,
|
|
|
|
Bowman, Judith S., et al., Addison-Wesley. Drugim nravitsya The
|
|
|
|
Complete Reference SQL, Groff et al., McGraw-Hill.
|
|
|
|
Est' prekrasnyj uchebnik na
|
2002-11-10 22:48:41 +03:00
|
|
|
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
|
|
|
|
2005-06-03 22:17:07 +04:00
|
|
|
1.11) Kak prisoedinitsya k komande razrabotchikov?
|
|
|
|
|
|
|
|
Smotrite FAQ dlya razrabotchikov.
|
|
|
|
|
|
|
|
1.12) Kak sravnivat' PostgreSQL s drugimi SUBD?
|
|
|
|
|
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
|
2005-06-03 22:17:07 +04:00
|
|
|
bystree, v kakih-to medlennee. Nasha proizvoditel'nosti obychno
|
|
|
|
+/-10% po sravneniyu s drugimi SUBD.
|
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
|
|
|
|
2005-06-03 22:17:07 +04:00
|
|
|
1.13) Kto upravlyaet PostgreSQL?
|
|
|
|
|
|
|
|
Esli vy ischite kakogo-to osobennogo cheloveka, central'nyj komitet
|
|
|
|
ili upravlyayuschuyu kompaniyu, to naprasno --- ih net. U nas est'
|
|
|
|
yadro komiteta i razrabotchikov, rabotayuschih s CVS, no `eti gruppy
|
|
|
|
sluzhat bol'she dlya administrativnyh celej, chem dlya upravleniya.
|
|
|
|
Proekt napryamuyu funkcioniruet s pomosch'yu soobschestva
|
|
|
|
razrabotchikov i pol'zovatelej, k kotoromu mozhet prisoedinitsya
|
|
|
|
kazhdyj. Vsio chto nuzhno -- `eto podpisat'sya na spiski rassylki i
|
|
|
|
uchastvovat' v diskussiyah. (Podrobnosti o tom kak vklyuchit'sya v
|
|
|
|
razrabotku PostgreSQL smotrite v FAQ dlya razrabotchikov.)
|
|
|
|
_________________________________________________________________
|
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
Voprosy pol'zovatelej po klientskoj chasti
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2005-06-03 22:17:07 +04:00
|
|
|
2.1) Kakie interfejsy est' dlya PostgreSQL?
|
|
|
|
|
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
|
|
|
|
2005-06-03 22:17:07 +04:00
|
|
|
2.2) Kakie instrumenty suschestvuyut dlya ispol'zovaniya PostgreSQL cherez
|
|
|
|
Web?
|
|
|
|
|
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-06-03 22:17:07 +04:00
|
|
|
V slozhnyh sluchayah, mnogie pol'zuyutsya Perl i DBD::Pg s CGI.pm ili
|
|
|
|
mod_perl.
|
|
|
|
|
|
|
|
2.3) Est' li u PostgreSQL graficheskij interfejs pol'zovatelya?
|
|
|
|
|
|
|
|
Da, podrobnosti smotrite v
|
|
|
|
http://techdocs.postgresql.org/guides/GUITools.
|
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
|
|
|
|
2005-06-03 22:17:07 +04:00
|
|
|
3.1) Kak mne ustanovit' PostgreSQL v mesto otlichnoe ot /usr/local/pgsql?
|
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
Zadajte opciyu --prefix kogda zapuskaete configure.
|
|
|
|
|
2005-06-03 22:17:07 +04: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-06-03 22:17:07 +04:00
|
|
|
3.3) Kakie nastrojki mne nuzhno sdelat' dlya uluchsheniya 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/.
|
|
|
|
|
2005-06-03 22:17:07 +04:00
|
|
|
3.4) Kakie vozmozhnosti dlya otladki est' v nalichii?
|
|
|
|
|
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.
|
|
|
|
|
2005-06-03 22:17:07 +04:00
|
|
|
3.5) Pochemu ya poluchayu soobschenie "Sorry, too many clients" kogda
|
|
|
|
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-06-03 22:17:07 +04:00
|
|
|
3.6) Pochemu neobhodimo delat' dump i restore pri obnovlenii vypuskov
|
|
|
|
PostgreSQL?
|
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
Razrabotchiki PostgreSQL delayut tol'ko nebol'shie izmeneniya mezhdu
|
2005-06-03 22:17:07 +04:00
|
|
|
podvypuskami. Takim obrazom obnovlenie s versii 7.4.0 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-06-03 22:17:07 +04: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-06-03 22:17:07 +04:00
|
|
|
4.1) Kak vypolnit' SELECT tol'ko dlya neskol'kih pervyh strochek zaprosa?
|
|
|
|
Proizvol'noj stroki?
|
|
|
|
|
2005-02-11 07:53:51 +03:00
|
|
|
Dlya polucheniya tol'ko neskol'kih strok, esli vy znaete ih
|
2005-06-03 22:17:07 +04:00
|
|
|
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-06-03 22:17:07 +04: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?
|
|
|
|
|
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.
|
|
|
|
|
2005-06-03 22:17:07 +04:00
|
|
|
4.3) Kak izmenit' tip dannyh kolonki?
|
|
|
|
|
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-06-03 22:17:07 +04: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-06-03 22:17:07 +04:00
|
|
|
4.5) Kak mnogo diskovogo prostranstva v baze dannyh nuzhno dlya sohraneniya
|
|
|
|
dannyh iz obychnogo tekstovogo fajla?
|
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
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-06-03 22:17:07 +04:00
|
|
|
4.6) Pochemu moi zaprosy rabotayut medleno? Pochemu oni ne ispol'zuyut moi
|
|
|
|
indeksy?
|
|
|
|
|
|
|
|
Indeksy ne ispol'zuyutsya dlya kazhdogo zaprosa. Oni ispol'zuyutsya
|
|
|
|
tol'ko esli tablica bol'she minimal'nogo razmera i zapros vybiraet
|
|
|
|
tol'ko malen'kij procent strok v tablice. Tak ustroeno, potomu chto
|
|
|
|
dostup k disku s primeneniem randomizacii pri skanirovanii indeksov
|
|
|
|
mozhet byt' medlennee, chem prostoe chtenie tablicy ili ee
|
|
|
|
posledovatel'noe skanirovanie.
|
2002-11-10 22:48:41 +03:00
|
|
|
|
|
|
|
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
|
2005-06-03 22:17:07 +04:00
|
|
|
zapustite zapros snova, chtoby uvidet', dejstvitel'no li skanirovanie
|
|
|
|
indeksov bystree.
|
2003-02-14 17:05:00 +03:00
|
|
|
|
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-06-03 22:17:07 +04:00
|
|
|
4.7) Kak posmotret' na to, kak optimizator vypolnyaet moj zapros?
|
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
Smotrite stranicu rukovodstva posvyaschennuyu EXPLAIN.
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2005-06-03 22:17:07 +04:00
|
|
|
4.8) Kak mne vypolnit' poisk regulyarnogo vyrazheniya i poisk nezavisimyj ot
|
|
|
|
registra bukv poisk regulyarnogo vyrazheniya? Kak mne ispol'zovat' indeks
|
|
|
|
dlya poiska nezavisimogo ot registra bukv?
|
|
|
|
|
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-06-03 22:17:07 +04:00
|
|
|
4.9) Kak mne opredelit', chto znachenie polya ravno NULL v kakom-libo
|
|
|
|
zaprose? Mogu ya otsortirovat' polya NULL ili net?
|
|
|
|
|
|
|
|
Vy prosto sravnivaete znachenie s IS NULL i IS NOT NULL, kak zdes':
|
|
|
|
SELECT *
|
|
|
|
FROM tab
|
|
|
|
WHERE col IS NULL;
|
|
|
|
|
|
|
|
CHtoby otsortirovat' dannye po znacheniyu ispol'zujte modifikatory IS
|
|
|
|
NULL i IS NOT NULL v vyrazhenii ORDER BY. Kogda oni budut generirovat'
|
|
|
|
znacheniya istina, to pri sortirovke oni budut vyshe, chem znacheniya
|
|
|
|
lozh', tak chto zapisi s NULL budut v otsortirovannom spiske sverhu:
|
|
|
|
SELECT *
|
|
|
|
FROM tab
|
|
|
|
ORDER BY (col IS NOT NULL);
|
|
|
|
|
|
|
|
4.10) Kakovy otlichiya mezhdu raznymi simvol'nymi tipami?
|
|
|
|
|
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,
|
2005-06-03 22:17:07 +04:00
|
|
|
chem oboznachennyj razmer. Odnako, dlinnye znacheniya takzhe
|
|
|
|
szhimayutsya, 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-06-03 22:17:07 +04: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-06-03 22:17:07 +04: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-06-03 22:17:07 +04:00
|
|
|
4.11.3) Ne mozhet li poluchit'sya tak, chto ispol'zovanie currval() i
|
|
|
|
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-06-03 22:17:07 +04:00
|
|
|
4.11.4) Pochemu chisla iz moej posledovatel'nosti ne ispol'zuyutsya snova pri
|
|
|
|
otmene tranzakcii? Pochemu sozdayutsya razryvy pri numeracii v kolonke, gde
|
|
|
|
ya ispol'zuyu posledovatel'nost'/SERIAL?
|
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
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-06-03 22:17:07 +04:00
|
|
|
4.12) CHto takoe OID? CHto takoe CTID?
|
|
|
|
|
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
|
|
|
|
2005-06-03 22:17:07 +04:00
|
|
|
CTID ispol'zuetsya dlya identifikacii special'nyh fizicheskih zapisej
|
|
|
|
s blochnymi i offset znacheniyami. CTID izmenyaetsya posle togo kak
|
|
|
|
stroki v tablice byli izmeneny ili peregruzheny.
|
|
|
|
|
|
|
|
TID ispol'zuetsya indeksnymi zapisyami v kachestve ukazatelya na
|
|
|
|
fizicheskie zapisi.
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2005-06-03 22:17:07 +04:00
|
|
|
4.13) Pochemu ya poluchayu oshibku "ERROR: Memory exhausted in
|
|
|
|
AllocSetAlloc()"?
|
|
|
|
|
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-06-03 22:17:07 +04:00
|
|
|
4.14) Kak mne uznat', kakaya versiya PostgreSQL zapuschena?
|
|
|
|
|
2002-11-10 22:48:41 +03:00
|
|
|
Iz psql, naberite SELECT version();
|
2002-04-12 13:17:10 +04:00
|
|
|
|
2005-06-03 22:17:07 +04:00
|
|
|
4.15) Kak mne sozdat' kolonku kotoraya po umolchaniyu budet soderzhat'
|
|
|
|
tekuschee vremya?
|
|
|
|
|
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-06-03 22:17:07 +04:00
|
|
|
4.16) Kak mne vypolnit' vneshnee svyazyvanie?
|
|
|
|
|
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-06-03 22:17:07 +04:00
|
|
|
4.17) 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-06-03 22:17:07 +04:00
|
|
|
4.18) Kak mne vernut' iz funkcii neskol'ko strok tablicy?
|
|
|
|
|
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-06-03 22:17:07 +04:00
|
|
|
4.19) Pochemu ya poluchayu oshibku "relation with OID #### ne suschestvuet",
|
|
|
|
kogda obraschayuts' k vremennym tablicam v 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-06-03 22:17:07 +04:00
|
|
|
4.20) Kakie est' resheniya dlya replikacii?
|
|
|
|
|
|
|
|
Hotya "replikaciya" -- `eto edinyj termin, est' neskol'ko raznyh
|
|
|
|
tehnologij dlya vypolneniya replikacij s raznymi osobennostyami dlya
|
|
|
|
kazhdoj.
|
|
|
|
|
|
|
|
Replikaciya Master/slave pozvolyaet imet' odin glavnyj (master) server
|
|
|
|
dlya vypolneniya zaprosov chteniya/zapisi, v to vremya kak
|
|
|
|
podchinionnye (slave) servera mogut proizvodit' tol'ko zaprosy
|
|
|
|
chteniya/SELECT. Naibolee populyarnym resheniem dlya replikacii
|
|
|
|
master-slave v PostgreSQL yavlyaetsya Slony-I.
|
|
|
|
|
|
|
|
Replikaciya Multi-master pozvolyaet vypolnyat' zaprosy chteniya/zapisi
|
|
|
|
na neskol'kih, repliciruemyh drug s drugom komp'yuetrah. `Eta
|
|
|
|
osobennost' takzhe privodit k potere proizvoditel'nosti, potomu chto
|
|
|
|
neobhodima sinhronizaciya izmenenij mezhdu neskol'kimi serverami.
|
|
|
|
Naibolee populyarnym resheniem dlya takoj replikacii v PostgreSQL
|
|
|
|
yavlyaetsya Pgcluster.
|