2002-02-22 20:48:55 +08:00
|
|
|
|
2002-11-11 03:48:41 +08:00
|
|
|
Otvety na chasto zadavaemye voprosy po PostgreSQL
|
2002-04-12 17:17:10 +08:00
|
|
|
|
2008-08-16 09:14:49 +08:00
|
|
|
Data poslednego obnovleniya: Sreda 25 iyunya 23:54:14 EDT 2008
|
2002-04-12 17:17:10 +08:00
|
|
|
|
2002-11-11 03:48:41 +08:00
|
|
|
Anglijskij variant soprovozhdaet: Bryus Mom'yan (Bruce Momjian)
|
2008-08-16 09:14:49 +08:00
|
|
|
(bruce@monjian.us)
|
2002-04-12 17:17:10 +08:00
|
|
|
|
2008-08-16 09:14:49 +08:00
|
|
|
Pereviol na russkij: Viktor Vislobokov (admin@postgresql.ru.net)
|
2002-04-12 17:17:10 +08:00
|
|
|
|
2002-11-11 03:48:41 +08:00
|
|
|
Samuyu svezhuyu anglijskuyu versiyu dokumenta mozhno najti na
|
2008-08-16 09:14:49 +08:00
|
|
|
http://www.postgresql.org/files/documentation/faqs/FAQ.html.
|
|
|
|
|
|
|
|
Samuyu svezhuyu russkuyu versiyu dokumenta mozhno najti na
|
|
|
|
http://postgresql.ru.net/docs/FAQ_russian.html.
|
2002-04-12 17:17:10 +08:00
|
|
|
|
2002-11-11 03:48:41 +08:00
|
|
|
Otvety na voprosy specifichnye dlya konkretnyh platform mozhno najti
|
2008-08-16 09:14:49 +08:00
|
|
|
na http://www.postgresql.org/docs/faq/.
|
2002-04-12 17:17:10 +08:00
|
|
|
_________________________________________________________________
|
|
|
|
|
2002-11-11 03:48:41 +08:00
|
|
|
Obschie voprosy
|
2002-04-12 17:17:10 +08:00
|
|
|
|
2008-08-16 09:14:49 +08:00
|
|
|
1.1) CHto takoe PostgreSQL? Kak proiznositsya `eto nazvanie? CHto
|
|
|
|
takoe Postgres?
|
2006-04-11 23:48:11 +08:00
|
|
|
1.2) Kto upravlyaet PostgreSQL?
|
|
|
|
1.3) Kakovy avtorskie prava na PostgreSQL?
|
|
|
|
1.4) Na kakih platformah rabotaet PostgreSQL?
|
|
|
|
1.5) Gde mozhno vzyat' PostgreSQL?
|
2006-06-28 21:10:18 +08:00
|
|
|
1.6) Kakaya versiya naibolee svezhaya?
|
2006-04-11 23:48:11 +08:00
|
|
|
1.7) Gde poluchit' podderzhku?
|
|
|
|
1.8) Kak mne soobschit' ob oshibke?
|
2002-11-11 03:48:41 +08:00
|
|
|
1.9) Kak najti informaciyu ob izvestnyh oshibkah ili otsutstvuyuschih
|
|
|
|
vozmozhnostyah?
|
2006-04-11 23:48:11 +08:00
|
|
|
1.10) Kakaya dokumentaciya imeetsya v nalichii?
|
|
|
|
1.11) Kak nauchit'sya SQL?
|
2006-06-28 21:10:18 +08:00
|
|
|
1.12) Kak mne otpravit' ispravlenie ili prisoedinitsya k komande
|
|
|
|
razrabotchikov?
|
2008-08-16 09:14:49 +08:00
|
|
|
1.13) Kak sravnit' PostgreSQL s drugimi SUBD? Mozhet li PostgreSQL
|
|
|
|
byt' vstroennoj?
|
|
|
|
1.14) Budet li PostgreSQL rabotat' s poslednimi izmeneniyami, v raznyh
|
|
|
|
stranyh, kasayuschimisya dnevnogo vremeni?
|
|
|
|
1.15) Kak mne otpisat'sya ot spiskov rassylki PostgreSQL? Kak
|
|
|
|
izbezhat' polucheniya dubliruyuschihsya soobschenij?
|
2002-11-11 03:48:41 +08:00
|
|
|
|
|
|
|
Voprosy pol'zovatelej po klientskoj chasti
|
2002-04-12 17:17:10 +08:00
|
|
|
|
2005-02-11 12:53:51 +08:00
|
|
|
2.1) Kakie interfejsy est' dlya PostgreSQL?
|
2002-11-11 03:48:41 +08: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 17:17:10 +08:00
|
|
|
|
2002-11-11 03:48:41 +08:00
|
|
|
3.1) Kak mne ustanovit' PostgreSQL v mesto otlichnoe ot
|
2002-04-12 17:17:10 +08:00
|
|
|
/usr/local/pgsql?
|
2006-04-11 23:48:11 +08:00
|
|
|
3.2) Kak mne upravlyat' soedineniyami ot drugih komp'yuterov?
|
2005-02-11 12:53:51 +08:00
|
|
|
3.3) Kakie nastrojki mne nuzhno sdelat' dlya uluchsheniya
|
2002-11-11 03:48:41 +08:00
|
|
|
proizvoditel'nosti?
|
2005-02-11 12:53:51 +08:00
|
|
|
3.4) Kakie vozmozhnosti dlya otladki est' v nalichii?
|
|
|
|
3.5) Pochemu ya poluchayu soobschenie "Sorry, too many clients" kogda
|
2002-11-11 03:48:41 +08:00
|
|
|
pytayus' podklyuchit'sya k baze?
|
2006-06-28 21:10:18 +08:00
|
|
|
3.6) Kak vypolnit' obnovlenie PostgreSQL?
|
2005-02-11 12:53:51 +08:00
|
|
|
3.7) Kakoe komp'yuternoe "zhelezo" ya dolzhen ispol'zovat'?
|
2002-04-12 17:17:10 +08:00
|
|
|
|
2002-11-11 03:48:41 +08:00
|
|
|
Voprosy `ekspluatacii
|
2002-04-12 17:17:10 +08:00
|
|
|
|
2005-02-11 12:53:51 +08:00
|
|
|
4.1) Kak vypolnit' SELECT tol'ko dlya neskol'kih pervyh strochek
|
2003-06-24 00:58:21 +08:00
|
|
|
zaprosa? Dlya proizvol'noj stroki?
|
2005-02-11 12:53:51 +08: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-11 03:48:41 +08:00
|
|
|
sohraneniya dannyh iz obychnogo tekstovogo fajla?
|
2005-02-11 12:53:51 +08: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-11 03:48:41 +08:00
|
|
|
nezavisimyj ot registra bukv poisk regulyarnogo vyrazheniya? Kak mne
|
|
|
|
ispol'zovat' indeks dlya poiska nezavisimogo ot registra bukv?
|
2008-08-16 09:14:49 +08:00
|
|
|
4.9) Kak mne opredelit', chto znachenie polya v kakom-libo zaprose
|
|
|
|
ravno NULL? Kak mne soedinit' vozmozhnye NULL? Mogu ya sortirovat'
|
|
|
|
polya NULL ili net?
|
2005-02-11 12:53:51 +08: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-11 03:48:41 +08:00
|
|
|
nextval() privedet k zaciklirovaniyu s drugimi pol'zovatelyami?
|
2005-02-11 12:53:51 +08:00
|
|
|
4.11.4) Pochemu chisla iz moej posledovatel'nosti ne ispol'zuyutsya
|
2002-11-11 03:48:41 +08:00
|
|
|
snova pri otmene tranzakcii? Pochemu sozdayutsya razryvy pri numeracii
|
|
|
|
v kolonke, gde ya ispol'zuyu posledovatel'nost'/SERIAL?
|
2005-06-04 02:17:07 +08:00
|
|
|
4.12) CHto takoe OID? CHto takoe CTID?
|
2005-02-11 12:53:51 +08:00
|
|
|
4.13) Pochemu ya poluchayu oshibku "ERROR: Memory exhausted in
|
2002-04-12 17:17:10 +08:00
|
|
|
AllocSetAlloc()"?
|
2005-02-11 12:53:51 +08:00
|
|
|
4.14) Kak mne uznat', kakaya versiya PostgreSQL zapuschena?
|
2005-06-04 02:17:07 +08:00
|
|
|
4.15) Kak mne sozdat' kolonku kotoraya po umolchaniyu budet soderzhat'
|
2002-11-11 03:48:41 +08:00
|
|
|
tekuschee vremya?
|
2005-06-04 02:17:07 +08: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?
|
2005-09-28 19:32:49 +08:00
|
|
|
4.21) Pochemu imena tablicy i kolonok ne raspoznayutsya v v moiom
|
2008-08-16 09:14:49 +08:00
|
|
|
zaprose? Pochemu ne sohranyayutsya zaglavnye bukvy?
|
2002-04-12 17:17:10 +08:00
|
|
|
_________________________________________________________________
|
|
|
|
|
2002-11-11 03:48:41 +08:00
|
|
|
Obschie voprosy
|
2002-04-12 17:17:10 +08:00
|
|
|
|
2008-08-16 09:14:49 +08:00
|
|
|
1.1) CHto takoe PostgreSQL? Kak proiznositsya `eto nazvanie? CHto takoe
|
|
|
|
Postgres?
|
2005-06-04 02:17:07 +08:00
|
|
|
|
2008-08-16 09:14:49 +08:00
|
|
|
PostgreSQL proiznositsya Post-Gres-Q-L (Post-Gres-K'yu-`El). (Dlya
|
|
|
|
osobo lyubopytstvuyuschih kak proiznosit' "PostgreSQL", suschestvuet
|
|
|
|
audio-fajl).
|
2005-02-11 12:53:51 +08:00
|
|
|
|
|
|
|
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,
|
2008-08-16 09:14:49 +08:00
|
|
|
http://www.postgresql.org/docs/faqs.FAQ_DEV.html
|
|
|
|
|
|
|
|
Postgres -- `eto shiroko ispol'zuemoe sokraschenie dlya PostgreSQL.
|
|
|
|
Pervonachal'nym imenem proekta v Berkli bylo Postgres i `etot nik
|
|
|
|
teper' naibolee populyaren v razgovorah o PostgreSQL po sravneniyu s
|
|
|
|
drugimi. Esli vam trudno polnost'yu progovarivat' 'PostgreSQL', mozhno
|
|
|
|
prosto govorit' 'Postgres'.
|
2002-11-11 03:48:41 +08:00
|
|
|
|
2006-04-11 23:48:11 +08:00
|
|
|
1.2) 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.)
|
|
|
|
|
|
|
|
1.3) Kakovy avtorskie prava na PostgreSQL?
|
2005-06-04 02:17:07 +08:00
|
|
|
|
2005-02-11 12:53:51 +08: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
|
2006-04-11 23:48:11 +08:00
|
|
|
menyat'. Vot `eta licenziya BSD, kotoruyu my ispol'zuem:
|
2002-04-12 17:17:10 +08:00
|
|
|
|
2002-11-11 03:48:41 +08:00
|
|
|
Sistema Upravleniya Bazami Dannyh PostgreSQL
|
2002-04-12 17:17:10 +08:00
|
|
|
|
2008-08-16 09:14:49 +08:00
|
|
|
Portions copyright (c) 1996-2008, PostgreSQL Global Development Group
|
2005-06-04 02:17:07 +08:00
|
|
|
Portions Copyright (c) 1994-1996 Regents of the University of
|
|
|
|
California
|
2002-04-12 17:17:10 +08:00
|
|
|
|
2002-11-11 03:48:41 +08: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.
|
|
|
|
|
2006-04-11 23:48:11 +08:00
|
|
|
1.4) Na kakih platformah rabotaet PostgreSQL?
|
2005-06-04 02:17:07 +08:00
|
|
|
|
2002-11-11 03:48:41 +08: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 17:17:10 +08:00
|
|
|
|
2005-06-04 02:17:07 +08:00
|
|
|
PostgreSQL takzhe rabotaet na operacionnyh sistemah Microsoft Windows,
|
2008-08-16 09:14:49 +08:00
|
|
|
osnovannyh na NT, takih kak Win2000 SP4, WinXP i Win2003. Paket
|
2005-06-04 02:17:07 +08:00
|
|
|
installyatora dostupen po adresu
|
2008-08-16 09:14:49 +08:00
|
|
|
http://www.postgresql.org/download/windows. Versii Windows, osnovannye
|
2005-01-04 11:47:03 +08:00
|
|
|
na MS-DOS (Win95, Win98, WinMe) mogut zapuskat' PostgreSQL s
|
|
|
|
pomosch'yu Cygwin.
|
2003-06-03 00:39:06 +08:00
|
|
|
|
|
|
|
Takzhe suschestvuet versiya sportirovannaya pod Novell Netware 6 na
|
2008-08-16 09:14:49 +08:00
|
|
|
http://developer.novell.com/wiki/index.php/Postgresql, i versiya dlya
|
|
|
|
OS/2 (eComStation) na
|
2005-02-11 12:53:51 +08:00
|
|
|
http://hobbes.nmsu.edu/cgi-bin/h-search?sh=1&button=Search&key=postgre
|
|
|
|
SQL&stype=all&sort=type&dir=%2F.
|
2002-04-12 17:17:10 +08:00
|
|
|
|
2006-04-11 23:48:11 +08:00
|
|
|
1.5) Gde mozhno vzyat' PostgreSQL?
|
2005-06-04 02:17:07 +08:00
|
|
|
|
|
|
|
CHerez brauzer, ispol'zuya http://www.postgresql.org/ftp/ i cherez
|
2008-08-16 09:14:49 +08:00
|
|
|
ftp, ispol'zuya ftp://ftp.postgresql.org/pub/.
|
2002-11-11 03:48:41 +08:00
|
|
|
|
2006-06-28 21:10:18 +08:00
|
|
|
1.6) Kakaya versiya naibolee svezhaya?
|
2006-04-11 23:48:11 +08:00
|
|
|
|
2008-08-16 09:14:49 +08:00
|
|
|
Poslednij vypusk PostgreSQL - `eto versiya 8.3.3
|
2006-04-11 23:48:11 +08:00
|
|
|
|
|
|
|
My planiruem vypuskat' novye starshie versii kazhdyj god, a mladshie
|
|
|
|
versii kazhdye neskol'ko mesyacev.
|
|
|
|
|
|
|
|
1.7) Gde poluchit' podderzhku?
|
2005-06-04 02:17:07 +08:00
|
|
|
|
2005-02-11 12:53:51 +08: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 17:17:10 +08:00
|
|
|
|
2005-01-04 11:47:03 +08:00
|
|
|
Glavnym IRC kanalom yavlyaetsya #postgreql, raspolozhennyj na servere
|
|
|
|
Freenode (irc.freenode.net). CHtoby podklyuchit'sya, vy mozhete
|
2005-02-11 12:53:51 +08:00
|
|
|
ispol'zovat' v Unix vyzov programmy irc -c '#postgresql' "$USER"
|
2005-01-04 11:47:03 +08:00
|
|
|
irc.freenode.net ili lyuboj drugoj IRC klient. Na `etom zhe servere
|
2008-08-16 09:14:49 +08:00
|
|
|
suschestvuyut kanaly na ispanskom (#postgresql-es), francuzskom
|
|
|
|
(#postgresqlfr) i brazil'skom (#postgresql-br) yazykah. Takzhe
|
|
|
|
suschestvuet kanal po PostgreSQL na servere EFNet.
|
2002-04-12 17:17:10 +08:00
|
|
|
|
2002-11-11 03:48:41 +08:00
|
|
|
Spisok kommercheskoj podderzhki kompanij dostupen na
|
2008-08-16 09:14:49 +08:00
|
|
|
http://www.postgresql.org/support/professional_support.
|
2002-04-12 17:17:10 +08:00
|
|
|
|
2006-04-11 23:48:11 +08:00
|
|
|
1.8) Kak mne soobschit' ob oshibke?
|
2005-06-04 02:17:07 +08:00
|
|
|
|
2005-02-11 12:53:51 +08: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
|
2008-08-16 09:14:49 +08:00
|
|
|
FTP sajte ftp://ftp.postgresql.org/pub/.
|
2005-02-11 12:53:51 +08:00
|
|
|
|
2006-04-11 23:48:11 +08:00
|
|
|
Na oshibki, uvedomlenie o kotoryh byli sdelany cherez special'nuyu
|
|
|
|
formu ili otpravlennye v kakoj-libo spisok rassylki PostgreSQL,
|
|
|
|
obychno generiruetsya odin iz sleduyuschih otvetov:
|
|
|
|
* `Eto ne oshibka i pochemu
|
|
|
|
* `Eto izvestnaya oshibka i ona uzhe est' v spiske TODO
|
|
|
|
* Dannaya oshibka byla ispravlena v tekuschem vypuske
|
|
|
|
* Dannaya oshibka byla ispravlena, no ispravlenie poka ne popalo v
|
|
|
|
oficial'nyj vypusk
|
|
|
|
* Zaprashivaetsya bolee detal'naya informaciya:
|
|
|
|
+ Operacionnaya sistema
|
|
|
|
+ Versiya PostgreSQL
|
|
|
|
+ Test, vosproizvodyaschij oshibku
|
|
|
|
+ Otladochnaya informaciya
|
|
|
|
+ Vyvod backtrace otladchika
|
|
|
|
* `Eto novaya oshibka. Mozhet proizojti sleduyuschee:
|
|
|
|
+ Budet sozdano ispravlenie, kotoroe budet vklyucheno v
|
|
|
|
sleduyuschij vypusk
|
|
|
|
+ Oshibka ne mozhet byt' ispravlena nemedlenno i budet
|
|
|
|
dobavlena v spisok TODO
|
|
|
|
|
|
|
|
1.9) Kak najti informaciyu ob izvestnyh oshibkah ili otsutstvuyuschih
|
|
|
|
vozmozhnostyah?
|
2005-06-04 02:17:07 +08:00
|
|
|
|
2006-04-11 23:48:11 +08:00
|
|
|
PostgreSQL podderzhivaet rasshirennyj podklass SQL:2003. Smotrite nash
|
|
|
|
spisok TODO na predmet izvestnyh oshibok, otsutstvuyuschih
|
|
|
|
vozmozhnostej i buduschih planov.
|
2002-04-12 17:17:10 +08:00
|
|
|
|
2006-04-11 23:48:11 +08:00
|
|
|
Na zapros kakoj-libo vozmozhnosti obychno prihodyat sleduyuschie
|
|
|
|
otvety:
|
|
|
|
* Dannaya vozmozhnost' uzhe est' v spiske TODO
|
|
|
|
* Dannaya vozmozhnost' nezhelatel'na potomu chto:
|
|
|
|
+ Ona dubliruet suschestvuyuschuyu funkcional'nost', kotoraya
|
|
|
|
sleduet standartu SQL
|
|
|
|
+ Dannaya vozmozhnost' sil'no uslozhnila by kod, no dala by
|
|
|
|
malen'kuyu vygodu
|
|
|
|
+ Dannaya vozmozhnost' nebezopasna ili nenadiozhna
|
|
|
|
* Dannaya novaya vozmozhnost' dobavlena v spisok TODO
|
|
|
|
|
|
|
|
PostgreSQL ne ispol'zuet kakuyu-libo sistemu otslezhivaniya oshibok,
|
|
|
|
potomu chto my obnaruzhili, chto ispol'zovanie pryamogo obrascheniya
|
|
|
|
po `elektronnoj pochte i obnovlyaemogo spiska TODO yavlyaetsya bolee
|
|
|
|
`effektivnym. Na praktike, oshibki v programmnom obespechenii
|
|
|
|
sohranyayutsya ochen' nedolgo, a oshibki, kotorye vazhny bol'shomu
|
|
|
|
kolichestvu pol'zovatelej ispravlyayutsya momental'no. Est' tol'ko
|
|
|
|
odno mesto, gde mozhno najti vse izmeneniya, uluchsheniya i
|
|
|
|
ispravleniya, sdelannye v vypuske PostgreSQL - `eto zhurnaly
|
|
|
|
soobschenij sistemy kontrolya versij CVS. Dazhe zamechaniya k vypuskam
|
|
|
|
ne soderzhat vse izmeneniya, sdelannye v programmnom obespechenii.
|
|
|
|
|
|
|
|
1.10) Kakaya dokumentaciya imeetsya v nalichii?
|
2005-06-04 02:17:07 +08:00
|
|
|
|
2005-02-11 12:53:51 +08: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
|
2008-08-16 09:14:49 +08:00
|
|
|
http://www.postgresql.org/docs.
|
2002-11-11 03:48:41 +08:00
|
|
|
|
|
|
|
Suschestvuet dve knigi po PostgreSQL dostupnye po adresam
|
2005-02-22 01:33:54 +08:00
|
|
|
http://www.PostgreSQL.org/docs/books/awbook.html i
|
2005-06-04 02:17:07 +08: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
|
2008-08-16 09:14:49 +08:00
|
|
|
dostupen po adresu http://www.postgresql.org/docs/books/. Krome togo,
|
|
|
|
po adresu
|
|
|
|
http://wiki.postgresql.org/wiki/Community_Generated_Articles%2C_Guides
|
|
|
|
%2C_and_Documentation vy mozhete najti kollekciyu tehnicheskih statej,
|
|
|
|
posveschennyh PostgreSQL.
|
2002-11-11 03:48:41 +08:00
|
|
|
|
2005-02-11 12:53:51 +08: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-11 03:48:41 +08:00
|
|
|
|
|
|
|
Nash sajt soderzhit esche bol'she informacii.
|
|
|
|
|
2006-04-11 23:48:11 +08:00
|
|
|
1.11) Kak mne nauchit'sya SQL?
|
2005-06-04 02:17:07 +08:00
|
|
|
|
|
|
|
Vo-pervyh, voz'mite odnu iz knig po PostgreSQL, o kotoryh govorilos'
|
2008-08-16 09:14:49 +08:00
|
|
|
vyshe. Mnogim iz nashih pol'zovatelej takzhe nravitsya kniga The
|
|
|
|
Practical SQL Handbook, Bowman, Judith S., et al., Addison-Wesley.
|
|
|
|
Drugim nravitsya The Complete Reference SQL, Groff et al.,
|
|
|
|
McGraw-Hill.
|
2002-04-12 17:17:10 +08:00
|
|
|
|
2006-06-28 21:10:18 +08:00
|
|
|
Suschestvuet takzhe mnozhestvo prekrasnyh uchebnikov dostupnyh v
|
|
|
|
online:
|
|
|
|
* http://www.intermedia.net/support/sql/sqltut.shtm,
|
|
|
|
* http://sqlcourse.com.
|
|
|
|
* http://www.w3school.com/sql/default.asp
|
|
|
|
* http://mysite.verizon.net/Graeme_Birchall/id1.html
|
|
|
|
|
|
|
|
1.12) Kak mne prislat' ispravlenie ili prisoedinitsya k komande
|
|
|
|
razrabotchikov?
|
2005-06-04 02:17:07 +08:00
|
|
|
|
|
|
|
Smotrite FAQ dlya razrabotchikov.
|
|
|
|
|
2008-08-16 09:14:49 +08:00
|
|
|
1.13) Kak sravnit' PostgreSQL s drugimi SUBD? Mozhet li PostgreSQL byt'
|
|
|
|
vstroennym?
|
2005-06-04 02:17:07 +08:00
|
|
|
|
2002-11-11 03:48:41 +08: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 11:22:20 +08: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 17:17:10 +08:00
|
|
|
|
2002-11-11 03:48:41 +08:00
|
|
|
Proizvoditel'nost'
|
2005-02-11 12:53:51 +08:00
|
|
|
Proizvoditel'nost' PostgreSQL shodna s drugimi kommercheskimi
|
|
|
|
SUBD i s SUBD s otkrytym ishodnym kodom. V kakih-to veschah my
|
2005-06-04 02:17:07 +08:00
|
|
|
bystree, v kakih-to medlennee. Nasha proizvoditel'nosti obychno
|
|
|
|
+/-10% po sravneniyu s drugimi SUBD.
|
2002-04-12 17:17:10 +08:00
|
|
|
|
2002-11-11 03:48:41 +08: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 17:17:10 +08:00
|
|
|
|
2002-11-11 03:48:41 +08: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.
|
2006-04-11 23:48:11 +08:00
|
|
|
(Smotrite Sekciyu 1.7.)
|
2002-04-12 17:17:10 +08:00
|
|
|
|
2002-11-11 03:48:41 +08: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.
|
2008-08-16 09:14:49 +08:00
|
|
|
|
|
|
|
PostgreSQL razrabatyvaetsya po arhitekture klient/server, kotoraya
|
|
|
|
trebuet otdel'nyh processov dlya kazhdogo klienta i servera, a takzhe
|
|
|
|
neskol'ko vspomogatel'nyh processov. Mnogie vstraivaemye arhitektury
|
|
|
|
mogut sootvetstvovat' takim trebovaniyam. Odnako, esli vasha
|
|
|
|
vstraivaemaya arhitektura trebuet server baz dannyh dlya zapuska
|
|
|
|
vnutri prikladnogo processa, vy ne mozhete ispol'zovat' Postgres i vam
|
|
|
|
luchshe by vybrat' dlya bazy dannyh kakoe-libo drugoe oblegchennoe
|
|
|
|
reshenie.
|
|
|
|
|
|
|
|
1.14) Budet li PostgreSQL rabotat' s poslednimi izmeneniyami, v raznyh
|
|
|
|
stranyh, kasayuschimisya dnevnogo vremeni?
|
|
|
|
|
|
|
|
Izmeneniya v sohranenii dnevnogo vremeni v SSHA vklyucheny v
|
|
|
|
PostgreSQL versii 8.0.[4+] i vo vse sleduyuschie vypuski, naprimer v
|
|
|
|
8.1. Izmeneniya po Kanade i Zapadnoj Avstralii vklyucheny v 8.0.[10+],
|
|
|
|
8.1.[6+] i vse sleduyuschie vypuski. Vypuski PostgreSQL do 8.0
|
|
|
|
ispol'zuyut informaciyu o sohranenii dnevnogo vremeni iz bazy dannyh
|
|
|
|
vremennyh zon v operacionnoj sisteme.
|
|
|
|
_________________________________________________________________
|
|
|
|
|
|
|
|
1.15) Kak mne otpisat'sya ot spiskov rassylki PostgreSQL? Kak izbezhat'
|
|
|
|
polucheniya dubliruyuschih soobschenij?
|
|
|
|
|
|
|
|
Stranica Majordomo na sajte PostgreSQL pozvolyaet podpisat'sya ili
|
|
|
|
otpisat'sya ot lyubogo iz spiskov rassylki PostgreSQL. (Vam mozhet
|
|
|
|
ponadobitsya vash parol' dlya Majordomo, kotoryj otpravlyaetsya na
|
|
|
|
vash E-mail, chtoby vojti v upravlenie vashimi podpiskami.)
|
|
|
|
|
|
|
|
Vse spiski rassylki PostgreSQL nastarivayutsya tak, chtoby gruppovoj
|
|
|
|
otvet uhodil na adres spiska i na adres avtora soobscheniya. Tak
|
|
|
|
sdelano, chtoby pol'zovateli poluchali otvety na E-mail kak mozhno
|
|
|
|
bystree. Esli vy ne hotite poluchat' dubliruyuschie E-mail
|
|
|
|
soobscheniya iz spiska, v sluchayah kogda vy uzhe poluchili `eti
|
|
|
|
soobscheniya napryamuyu, ustanovite flazhok eliminatecc na stranice
|
|
|
|
Change Settings v Majordomo. Vy takzhe mozhete izbezhat' polucheniya
|
|
|
|
kopij svoih soobschenij dlya samogo sebya, esli snimite flazhok
|
|
|
|
selfcopy.
|
2005-06-04 02:17:07 +08:00
|
|
|
_________________________________________________________________
|
|
|
|
|
2002-11-11 03:48:41 +08:00
|
|
|
Voprosy pol'zovatelej po klientskoj chasti
|
2002-04-12 17:17:10 +08:00
|
|
|
|
2005-06-04 02:17:07 +08:00
|
|
|
2.1) Kakie interfejsy est' dlya PostgreSQL?
|
|
|
|
|
2005-02-11 12:53:51 +08: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 17:17:10 +08:00
|
|
|
|
2005-02-11 12:53:51 +08:00
|
|
|
Nekotorye yazyki programmirovaniya, takie kak PHP vklyuchayut v sebya
|
|
|
|
interfejs k PostgreSQL. Interfejsy dlya takih yazykov kak Perl, TCL,
|
2008-08-16 09:14:49 +08:00
|
|
|
Python i mnogih drugih, dostupny na http://pgfoundry.org.
|
2002-04-12 17:17:10 +08:00
|
|
|
|
2005-06-04 02:17:07 +08:00
|
|
|
2.2) Kakie instrumenty suschestvuyut dlya ispol'zovaniya PostgreSQL cherez
|
|
|
|
Web?
|
|
|
|
|
2002-11-11 03:48:41 +08:00
|
|
|
Prekrasnoe vvedenie vo vzaimodejstvie baz dannyh i Web mozhno najti
|
|
|
|
na: http://www.webreview.com
|
2002-04-12 17:17:10 +08:00
|
|
|
|
2005-02-11 12:53:51 +08:00
|
|
|
Dlya integracii s Web, PHP http://www.php.net yavlyaetsya neplohim
|
|
|
|
interfejsom.
|
2002-04-12 17:17:10 +08:00
|
|
|
|
2005-06-04 02:17:07 +08: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?
|
|
|
|
|
2006-06-28 21:10:18 +08:00
|
|
|
Dlya PostgreSQL suschestvuet bol'shoe kolichestvo instrumentov s
|
|
|
|
graficheskim interfejsom kak kommercheskih, tak i otkrytyh.
|
2008-08-16 09:14:49 +08:00
|
|
|
Podrobnosti mozhno najti v Dokumentacii soobschestva dlya GUI
|
|
|
|
istrumentov PostgreSQL
|
2002-04-12 17:17:10 +08:00
|
|
|
_________________________________________________________________
|
|
|
|
|
2002-11-11 03:48:41 +08:00
|
|
|
Voprosy administrirovaniya
|
2002-04-12 17:17:10 +08:00
|
|
|
|
2005-06-04 02:17:07 +08:00
|
|
|
3.1) Kak mne ustanovit' PostgreSQL v mesto otlichnoe ot /usr/local/pgsql?
|
|
|
|
|
2002-11-11 03:48:41 +08:00
|
|
|
Zadajte opciyu --prefix kogda zapuskaete configure.
|
|
|
|
|
2006-04-11 23:48:11 +08:00
|
|
|
3.2) Kak mne upravlyat' soedineniyami ot drugih komp'yuterov?
|
2005-06-04 02:17:07 +08:00
|
|
|
|
2002-11-11 03:48:41 +08:00
|
|
|
Po umolchaniyu, PostgreSQL razreshaet tol'ko soedineniya na lokal'noj
|
2005-02-11 12:53:51 +08: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'
|
2008-08-16 09:14:49 +08:00
|
|
|
host-avtorizaciya v fajle $PGDATA/pg_hba.conf i perestartovat' server
|
|
|
|
SUBD.
|
2002-11-11 03:48:41 +08:00
|
|
|
|
2005-06-04 02:17:07 +08:00
|
|
|
3.3) Kakie nastrojki mne nuzhno sdelat' dlya uluchsheniya proizvoditel'nosti?
|
|
|
|
|
2005-02-11 12:53:51 +08: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
|
2008-08-16 09:14:49 +08:00
|
|
|
http://www.powerpostgresql.com/PerfList/ i
|
|
|
|
http://momjian.us/main/writings/pgsql/hw_performance/index.html
|
|
|
|
.
|
2005-02-11 12:53:51 +08:00
|
|
|
|
2005-06-04 02:17:07 +08:00
|
|
|
3.4) Kakie vozmozhnosti dlya otladki est' v nalichii?
|
|
|
|
|
2005-02-11 12:53:51 +08:00
|
|
|
Est' mnozhestvo ustanovok v nastrojkah servera, nachinayuschihsya na
|
2008-08-16 09:14:49 +08:00
|
|
|
log_* na
|
|
|
|
http://www.postgresql.org/docs/current/interactive/runtime-config-logg
|
|
|
|
ing.html, pozvolyayuschih protokolirovat' zaprosy i statistiku raboty
|
2005-02-11 12:53:51 +08:00
|
|
|
processa, kotoraya ochen' polezna dlya otladki i izmereniya
|
|
|
|
proizvoditel'nosti.
|
|
|
|
|
2005-06-04 02:17:07 +08:00
|
|
|
3.5) Pochemu ya poluchayu soobschenie "Sorry, too many clients" kogda
|
|
|
|
pytayus' podklyuchit'sya k baze?
|
|
|
|
|
2008-08-16 09:14:49 +08:00
|
|
|
Vy dostigli ustanovlennogo po umolchaniyu ogranicheniya v 100 sessij
|
|
|
|
podklyucheniya k baze dannyh. Vam neobhodimo uvelichit' limit na
|
|
|
|
kolichestvo konkurentnyh backend processov dlya vashego servera BD,
|
2005-02-11 12:53:51 +08:00
|
|
|
izmeniv znachenie max_connections v fajle postgresql.conf i
|
2008-08-16 09:14:49 +08:00
|
|
|
perestartovat' server BD.
|
2002-08-23 10:53:20 +08:00
|
|
|
|
2006-06-28 21:10:18 +08:00
|
|
|
3.6) Kak vypolnit' obnovlenie PostgreSQL?
|
2005-06-04 02:17:07 +08:00
|
|
|
|
2008-08-16 09:14:49 +08:00
|
|
|
Sm. informaciyu ob obnovlenii v
|
|
|
|
http://www.postgresql.org/support/versioning i special'nye instrukcii
|
|
|
|
v
|
|
|
|
http://www.postgresql.org/docs/current/static/install-upgrading.html.
|
2004-10-27 01:28:27 +08:00
|
|
|
|
2005-06-04 02:17:07 +08:00
|
|
|
3.7) Kakoe komp'yuternoe "zhelezo" ya dolzhen ispol'zovat'?
|
|
|
|
|
2004-10-27 01:28:27 +08: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 17:17:10 +08:00
|
|
|
_________________________________________________________________
|
|
|
|
|
2002-11-11 03:48:41 +08:00
|
|
|
Voprosy `ekspluatacii
|
2002-04-12 17:17:10 +08:00
|
|
|
|
2005-06-04 02:17:07 +08:00
|
|
|
4.1) Kak vypolnit' SELECT tol'ko dlya neskol'kih pervyh strochek zaprosa?
|
|
|
|
Proizvol'noj stroki?
|
|
|
|
|
2005-02-11 12:53:51 +08:00
|
|
|
Dlya polucheniya tol'ko neskol'kih strok, esli vy znaete ih
|
2005-06-04 02:17:07 +08: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 17:17:10 +08:00
|
|
|
|
2003-06-24 00:58:21 +08:00
|
|
|
To SELECT a random row, use:
|
|
|
|
SELECT col
|
|
|
|
FROM tab
|
|
|
|
ORDER BY random()
|
|
|
|
LIMIT 1;
|
|
|
|
|
2005-06-04 02:17:07 +08: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 21:18:30 +08: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-11 03:48:41 +08:00
|
|
|
pgsql/src/bin/psql/describe.c. On soderzhit komandy SQL kotorye
|
|
|
|
generiruyutsya pri vvode v psql komand, nachinayuschihsya s obratnoj
|
2004-05-18 21:18:30 +08: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 12:53:51 +08: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-11 03:48:41 +08:00
|
|
|
|
2005-02-11 12:53:51 +08: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-04 02:17:07 +08:00
|
|
|
4.3) Kak izmenit' tip dannyh kolonki?
|
|
|
|
|
2005-02-11 12:53:51 +08: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-24 00:58:21 +08: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 10:52:12 +08:00
|
|
|
ALTER TABLE tab DROP COLUMN old_col;
|
2003-06-24 00:58:21 +08:00
|
|
|
COMMIT;
|
|
|
|
|
2005-06-04 02:17:07 +08:00
|
|
|
4.4) Kakovy maksimal'nye razmery dlya strok v tablice, tablic i bazy dannyh?
|
|
|
|
|
2002-11-11 03:48:41 +08:00
|
|
|
Suschestvuyut sleduyuschie ogranicheniya:
|
2005-02-11 12:53:51 +08:00
|
|
|
|
|
|
|
Maksimal'nyj razmer bazy? neogranichen (suschestvuyut bazy na 32 TB)
|
|
|
|
Maksimal'nyj razmer tablicy? 32 TB
|
2006-06-28 21:10:18 +08:00
|
|
|
Maksimal'nyj razmer stroki? 400 Gb
|
2005-02-11 12:53:51 +08:00
|
|
|
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-11 03:48:41 +08: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 10:52:12 +08:00
|
|
|
Maksimal'nyj razmer tablicy v 32 TB ne trebuet chtoby operacionnaya
|
2002-11-11 03:48:41 +08: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 10:52:12 +08:00
|
|
|
byt' uvelicheny v chetyre raza, esli razmer bloka po umolchaniyu budet
|
|
|
|
uvelichen do 32k.
|
2002-11-11 03:48:41 +08:00
|
|
|
|
2005-09-28 19:32:49 +08:00
|
|
|
Suschestvuet ogranichenie, po kotoromu indeksy ne mogut sozdavat'sya
|
|
|
|
dlya kolonok dlinnee chem 2,000 simvolov. K schast'yu takie indeksy
|
|
|
|
vryad li dejstvitel'no komu-to nuzhny. Unikal'nost' garantiruetsya
|
|
|
|
nailuchim obrazom, s pomosch'yu funkcional'nogo indeksa iz h`esha MD5
|
|
|
|
dlinnoj kolonki, a polnotekstovoe indeksirovanie pozvolyaet iskat'
|
|
|
|
slova vnutri kolonki.
|
|
|
|
|
2005-06-04 02:17:07 +08:00
|
|
|
4.5) Kak mnogo diskovogo prostranstva v baze dannyh nuzhno dlya sohraneniya
|
|
|
|
dannyh iz obychnogo tekstovogo fajla?
|
|
|
|
|
2002-11-11 03:48:41 +08: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
|
2008-08-16 09:14:49 +08:00
|
|
|
priblizitel'no 5.2 MB iz kotoryh:
|
|
|
|
24 bajt: na kazhdyj zagolovok stroki v tablice (priblizitel'no)
|
2002-11-11 03:48:41 +08:00
|
|
|
+ 24 bajta: odno pole s celochislennym tipom i odno tekstovoe pole
|
2005-02-11 12:53:51 +08:00
|
|
|
+ 4 bajta: ukazatel' na stranice dlya vsej tablichnoj stroki
|
2002-04-12 17:17:10 +08:00
|
|
|
----------------------------------------
|
2005-09-28 19:32:49 +08:00
|
|
|
56 bajt na stroku v tablice
|
2002-04-12 17:17:10 +08:00
|
|
|
|
2002-11-11 03:48:41 +08:00
|
|
|
Razmer stranicy dannyh v PostgreSQL sostavlyaet 8192 bajt (8 KB), tak chto:
|
2002-04-12 17:17:10 +08:00
|
|
|
|
2002-11-11 03:48:41 +08:00
|
|
|
8192 bajt na stranicu
|
2008-08-16 09:14:49 +08:00
|
|
|
--------------------- = 158 strok v tablice na stranicu BD (okruglionno)
|
|
|
|
52 bajt na stroku v tablice
|
2002-04-12 17:17:10 +08:00
|
|
|
|
2004-04-12 11:22:20 +08:00
|
|
|
100000 strok dannyh
|
2008-08-16 09:14:49 +08:00
|
|
|
----------------------- = 633 stranic v BD (okruglionno)
|
|
|
|
158 strok v tablice na stranicu
|
2002-04-12 17:17:10 +08:00
|
|
|
|
2008-08-16 09:14:49 +08:00
|
|
|
633 stranic BD * 8192 bajt na stranicu = 5,185,536 bajt (5.2 MB)
|
2002-04-12 17:17:10 +08:00
|
|
|
|
2002-11-11 03:48:41 +08:00
|
|
|
Indeksy ne trebuyut tak mnogo, no poskol'ku oni sozdayutsya dlya
|
|
|
|
bol'shogo kolichestva dannyh, oni takzhe mogut byt' veliki.
|
|
|
|
|
2004-04-12 11:22:20 +08:00
|
|
|
Znacheniya NULL hranyatsya kak bitovye karty i po`etomu oni zanimayut
|
2004-03-12 21:51:33 +08:00
|
|
|
ochen' malo mesta.
|
2002-11-11 03:48:41 +08:00
|
|
|
|
2005-06-04 02:17:07 +08: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-11 03:48:41 +08: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 12:53:51 +08:00
|
|
|
strok v tablice i esli on dolzhen ispol'zovat' indeksy, to on mozhet
|
2002-11-11 03:48:41 +08:00
|
|
|
prinimat' luchshie resheniya. Statistika takzhe vliyaet na opredelenie
|
2005-02-11 12:53:51 +08:00
|
|
|
optimal'nogo poryadka svyazyvaniya i metoda svyazyvaniya. Pri
|
|
|
|
izmenenii soderzhimogo tablicy dolzhen periodicheski vypolnyatsya sbor
|
|
|
|
statistiki.
|
2002-11-11 03:48:41 +08: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
|
2006-04-11 23:48:11 +08:00
|
|
|
vozvraschat'sya nebol'shaya chast' tablicy.
|
|
|
|
|
2004-04-12 11:22:20 +08:00
|
|
|
Esli vam kazhetsya, chto optimizator nekorrektno vybiraet
|
2003-02-14 22:05:00 +08:00
|
|
|
posledovatel'nyj perebor, ispol'zujte SET enable_seqscan TO 'off' i
|
2005-06-04 02:17:07 +08:00
|
|
|
zapustite zapros snova, chtoby uvidet', dejstvitel'no li skanirovanie
|
|
|
|
indeksov bystree.
|
2003-02-14 22:05:00 +08:00
|
|
|
|
2002-11-11 03:48:41 +08: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 12:53:51 +08:00
|
|
|
indeksy. Vmesto nego, ispol'zujte indeksy vyrazhenij, kotorye
|
|
|
|
opisyvayutsya v sekcii 4.8.
|
2005-01-04 11:47:03 +08:00
|
|
|
* Vo vremya initdb dolzhna ispol'zovat'sya lokal' po umolchaniyu C,
|
2005-02-11 12:53:51 +08: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
|
2008-08-16 09:14:49 +08:00
|
|
|
rabotaet tol'ko dlya LIKE indeksirovaniya. Dlya poiska slov takzhe
|
|
|
|
mozhno ispol'zovat' polnotekstovyj indeks.
|
2002-08-23 10:53:20 +08:00
|
|
|
|
2005-06-04 02:17:07 +08:00
|
|
|
4.7) Kak posmotret' na to, kak optimizator vypolnyaet moj zapros?
|
|
|
|
|
2002-11-11 03:48:41 +08:00
|
|
|
Smotrite stranicu rukovodstva posvyaschennuyu EXPLAIN.
|
2002-04-12 17:17:10 +08:00
|
|
|
|
2005-06-04 02:17:07 +08: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-11 03:48:41 +08: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 17:17:10 +08:00
|
|
|
|
2002-11-11 03:48:41 +08:00
|
|
|
Nezavisimoe ot registra sravnenie obychno vyrazhaetsya tak:
|
2002-04-12 17:17:10 +08:00
|
|
|
SELECT *
|
|
|
|
FROM tab
|
2002-11-11 03:48:41 +08:00
|
|
|
WHERE lower(col) = 'abc';
|
2002-04-12 17:17:10 +08:00
|
|
|
|
2002-11-11 03:48:41 +08:00
|
|
|
`Eta konstrukciya ne budet ispol'zovat' standartnyj indeks. Odnako,
|
2005-02-11 12:53:51 +08:00
|
|
|
esli vy sozdadite indeks vyrazheniya, on budet ispol'zovan:
|
2002-11-11 03:48:41 +08:00
|
|
|
CREATE INDEX tabindex ON tab (lower(col));
|
2002-04-12 17:17:10 +08:00
|
|
|
|
2005-09-28 19:32:49 +08:00
|
|
|
Esli vysheukazannyj indeks sozdaiotsya kak UNIQUE, to kolonka, dlya
|
|
|
|
kotoroj on sozdaiotsya mozhet hranit' simvoly i v verhnem, i v nizhnem
|
|
|
|
registre, indes ne mozhet imet' identichnyh znachenij, kotorye
|
|
|
|
otlichayutsya tol'ko registrom. CHtoby v kolonke mozhno bylo hranit'
|
|
|
|
simvoly tol'ko v opredelionnom registre, ispol'zujte ogranichenie
|
|
|
|
CHECK ili proverku cherez trigger.
|
|
|
|
|
2008-08-16 09:14:49 +08:00
|
|
|
4.9) Kak mne opredelit', chto znachenie polya v kakom-libo zaprose ravno
|
|
|
|
NULL? Kak mne soedinit' vozmozhnye NULL? Mogu ya sortirovat' polya NULL ili
|
|
|
|
net?
|
2005-06-04 02:17:07 +08:00
|
|
|
|
|
|
|
Vy prosto sravnivaete znachenie s IS NULL i IS NOT NULL, kak zdes':
|
|
|
|
SELECT *
|
|
|
|
FROM tab
|
|
|
|
WHERE col IS NULL;
|
|
|
|
|
2008-08-16 09:14:49 +08:00
|
|
|
CHtoby soedinit' s vozmozhnymi znacheniyami NULL, ispol'zujte
|
|
|
|
COALESCE() kak zdes':
|
|
|
|
SELECT COALESCE(col1, '') || COALESCE(col2, '')
|
|
|
|
FROM tab
|
|
|
|
|
2005-06-04 02:17:07 +08:00
|
|
|
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 12:53:51 +08: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-11 03:48:41 +08:00
|
|
|
Vnutrennee imya vy mozhete uvidet', kogda smotrite sistemnye katalogi
|
|
|
|
i v nekotoryh soobscheniyah ob oshibkah.
|
|
|
|
|
2003-03-07 13:46:51 +08:00
|
|
|
Pervye chetyre tipa yavlyayutsya "varlena" tipami (t.e., pervye
|
2002-11-11 03:48:41 +08:00
|
|
|
chetyre bajta na diske yavlyayutsya dlinnoj, za kotoroj sleduyut
|
|
|
|
dannye). Takim obrazom, fakticheski ispol'zuemoe prostranstvo bol'she,
|
2005-06-04 02:17:07 +08: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 22:05:00 +08: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-11 03:48:41 +08:00
|
|
|
|
|
|
|
CHAR(n) - `eto luchshee reshenie dlya hraneniya strok, kotorye obychno
|
2003-02-14 22:05:00 +08: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 13:46:51 +08:00
|
|
|
znacheniya kotoryh mogut vklyuchat' NULL bajty. Vse tipy opisannye
|
|
|
|
zdes', imeyut shodnye harakteristiki proizvoditel'nosti.
|
2002-11-11 03:48:41 +08:00
|
|
|
|
2005-06-04 02:17:07 +08:00
|
|
|
4.11.1) Kak mne sozdat' pole serial/s-avto-uvelicheniem?
|
|
|
|
|
2002-11-11 03:48:41 +08:00
|
|
|
PostgreSQL podderzhivaet tip dannyh SERIAL. On avtomaticheski sozdaet
|
2003-11-29 04:20:33 +08:00
|
|
|
posledovatel'nost'. Naprimer:
|
2002-04-12 17:17:10 +08:00
|
|
|
CREATE TABLE person (
|
|
|
|
id SERIAL,
|
|
|
|
name TEXT
|
|
|
|
);
|
|
|
|
|
2002-11-11 03:48:41 +08:00
|
|
|
avtomaticheski transliruetsya v:
|
2002-04-12 17:17:10 +08:00
|
|
|
CREATE SEQUENCE person_id_seq;
|
|
|
|
CREATE TABLE person (
|
|
|
|
id INT4 NOT NULL DEFAULT nextval('person_id_seq'),
|
|
|
|
name TEXT
|
|
|
|
);
|
|
|
|
|
2008-08-16 09:14:49 +08:00
|
|
|
Avtomaticheski sozdannaya posledovatel'nost' imeet imya vida
|
|
|
|
<tablica>_<kolonka_serial>_seq, gde tablica i kolonka_serial - `eto
|
|
|
|
sootvetstvenno imena tablicy i kolonki s tipom SERIAL. Smotrite
|
|
|
|
podrobnosti o posledovatel'nostyah na stranice rukovodstva
|
2005-02-11 12:53:51 +08:00
|
|
|
posvyaschennoj create_sequence.
|
2002-11-11 03:48:41 +08:00
|
|
|
|
2005-06-04 02:17:07 +08:00
|
|
|
4.11.2) Kak mne poluchit' znachenie pri vstavke SERIAL?
|
|
|
|
|
2008-08-16 09:14:49 +08:00
|
|
|
Prostejshij sposob poluchit' naznachennoe znachenie SERIAL `eto
|
|
|
|
ispol'zovat' RETURNING. Ispol'zuya dlya primera tablicu v 4.11.1, `eto
|
|
|
|
mozhet vyglyadet' tak:
|
|
|
|
INSERT INTO person (name) VALUES ('Blaise Pascal') RETURNING id;
|
2002-04-12 17:17:10 +08:00
|
|
|
|
2008-08-16 09:14:49 +08:00
|
|
|
Vy takzhe mozhete vyzvat' nextval() i ispol'zovat' `eto znachenie v
|
|
|
|
INSERT ili vyzvat' currval() posle INSERT.
|
|
|
|
|
2005-06-04 02:17:07 +08: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 12:53:51 +08:00
|
|
|
Net. currval() vozvraschaet tekuschee znachenie, naznachennoe vashej
|
|
|
|
sessiej, a ne drugimi sessiyami.
|
2002-11-11 03:48:41 +08:00
|
|
|
|
2005-06-04 02:17:07 +08: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-11 03:48:41 +08: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-04 02:17:07 +08:00
|
|
|
4.12) CHto takoe OID? CHto takoe CTID?
|
|
|
|
|
2008-08-16 09:14:49 +08:00
|
|
|
Esli tablica sozdana s WITH OIDS, to kazhdaya stroka poluchaet
|
|
|
|
unikal'nyj indentifikator OID. OID - `eto avtomaticheski naznachaemoe
|
|
|
|
unikal'noe 4-h bajtovoe celoe chislo, kotoroe unikal'no dlya vsej
|
|
|
|
ustanovlennoj SUBD. Odnako, posle togo kak ego znachenie prevysit 4
|
|
|
|
milliarda, znacheniya OID nachinayut dublirovat'sya. PostgreSQL
|
|
|
|
ispol'zuet OID dlya svyazyvaniya svoih vnutrennih tablic.
|
2005-02-11 12:53:51 +08:00
|
|
|
|
2008-08-16 09:14:49 +08:00
|
|
|
Dlya unikal'nogo znacheniya v strokah tablicy pol'zovatelya, luchshim
|
2005-02-11 12:53:51 +08:00
|
|
|
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 17:17:10 +08:00
|
|
|
|
2005-06-04 02:17:07 +08: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 17:17:10 +08:00
|
|
|
|
2005-06-04 02:17:07 +08:00
|
|
|
4.13) Pochemu ya poluchayu oshibku "ERROR: Memory exhausted in
|
|
|
|
AllocSetAlloc()"?
|
|
|
|
|
2002-11-11 03:48:41 +08:00
|
|
|
Predpolozhitel'no u vas zakonchilas' virtual'naya pamyat' ili chto
|
|
|
|
vashe yadro imeet malen'kij limit na opredelennye resursy. Popytajtes'
|
2008-08-16 09:14:49 +08:00
|
|
|
pered zapuskom servera BD vypolnit' sleduyuschie komandy:
|
2002-04-12 17:17:10 +08:00
|
|
|
ulimit -d 262144
|
|
|
|
limit datasize 256m
|
|
|
|
|
2002-11-11 03:48:41 +08: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-04 02:17:07 +08:00
|
|
|
4.14) Kak mne uznat', kakaya versiya PostgreSQL zapuschena?
|
|
|
|
|
2002-11-11 03:48:41 +08:00
|
|
|
Iz psql, naberite SELECT version();
|
2002-04-12 17:17:10 +08:00
|
|
|
|
2005-06-04 02:17:07 +08:00
|
|
|
4.15) Kak mne sozdat' kolonku kotoraya po umolchaniyu budet soderzhat'
|
|
|
|
tekuschee vremya?
|
|
|
|
|
2002-11-11 03:48:41 +08:00
|
|
|
Ispol'zujte CURRENT_TIMESTAMP:
|
2005-02-11 12:53:51 +08:00
|
|
|
CREATE TABLE test (x int, modtime TIMESTAMP DEFAULT CURRENT_TIMESTAMP );
|
2002-04-12 17:17:10 +08:00
|
|
|
|
2005-06-04 02:17:07 +08:00
|
|
|
4.16) Kak mne vypolnit' vneshnee svyazyvanie?
|
|
|
|
|
2002-11-11 03:48:41 +08:00
|
|
|
PostgreSQL podderzhivaet vneshnee svyazyvanie, ispol'zuya standartnyj
|
|
|
|
sintaksis SQL. Vot dva primera:
|
2002-04-12 17:17:10 +08:00
|
|
|
SELECT *
|
|
|
|
FROM t1 LEFT OUTER JOIN t2 ON (t1.col = t2.col);
|
|
|
|
|
2002-11-11 03:48:41 +08:00
|
|
|
ili
|
2002-04-12 17:17:10 +08:00
|
|
|
SELECT *
|
|
|
|
FROM t1 LEFT OUTER JOIN t2 USING (col);
|
|
|
|
|
2002-11-11 03:48:41 +08:00
|
|
|
`Eto identichnye zaprosy svyazyvaniya t1.col i t2.col, takzhe
|
2005-02-11 12:53:51 +08: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-11 03:48:41 +08:00
|
|
|
neobyazatel'nym i naznachaetsya v LEFT, RIGHT i FULL svyazyvaniyah.
|
|
|
|
Obychnye svyazyvaniya nazyvayutsya INNER svyazyvaniya.
|
|
|
|
|
2005-06-04 02:17:07 +08:00
|
|
|
4.17) Kak vypolnyat' zaprosy, ispol'zuyuschie neskol'ko baz dannyh?
|
|
|
|
|
2002-11-11 03:48:41 +08: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 12:53:51 +08:00
|
|
|
funkcij. Razumeetsya, klient mozhet odnovremenno takzhe ustanavlivat'
|
2002-11-11 03:48:41 +08:00
|
|
|
soedieneniya s razlichnymi bazami dannyh i takih obrazom ob"edinyat'
|
|
|
|
informaciyu iz nih.
|
|
|
|
|
2005-06-04 02:17:07 +08:00
|
|
|
4.18) Kak mne vernut' iz funkcii neskol'ko strok tablicy?
|
|
|
|
|
2005-02-11 12:53:51 +08:00
|
|
|
Vy mozhete legko ispol'zovat' funkcii, vozvraschayuschie spisok,
|
2008-08-16 09:14:49 +08:00
|
|
|
http://wiki.postgresql.org/wiki/Return_more_than_one_row_of_data_from_
|
|
|
|
PL/pgSQL_functions.
|
2002-11-11 03:48:41 +08:00
|
|
|
|
2005-06-04 02:17:07 +08:00
|
|
|
4.19) Pochemu ya poluchayu oshibku "relation with OID #### ne suschestvuet",
|
|
|
|
kogda obraschayuts' k vremennym tablicam v funkciyah PL/PgSQL?
|
|
|
|
|
2008-08-16 09:14:49 +08:00
|
|
|
V PostgreSQL do versii 8.3, PL/PgSQL k`eshiruet scenarii funkcii i
|
|
|
|
odin iz negativnyh `effektov `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.
|
|
|
|
|
|
|
|
V PostgreSQL 8.3 i pozdnee, `etoj problemy net.
|
2002-11-11 03:48:41 +08:00
|
|
|
|
2005-06-04 02:17:07 +08: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
|
2008-08-16 09:14:49 +08:00
|
|
|
yavlyaetsya PGcluster.
|
2005-09-28 19:32:49 +08:00
|
|
|
|
|
|
|
4.21) Pochemu imena tablicy i kolonok ne raspoznayutsya v v moiom zaprose?
|
2008-08-16 09:14:49 +08:00
|
|
|
Pochemu ne sohranyayutsya zaglavnye bukvy?
|
2005-09-28 19:32:49 +08:00
|
|
|
|
2008-08-16 09:14:49 +08:00
|
|
|
Naibolee chasto imena neraspoznayutsya iz-za ispol'zovaniya dvojnyh
|
|
|
|
kavychek v imeni tablicy ili kolonki pri sozdanii tablicy. Pri
|
|
|
|
ispol'zovanii dvojnyh kavychek, imya tablicy i kolonki (kotorye
|
|
|
|
nazyvayut identifikatorami) sohranyayutsya v registro-zavisimom vide;
|
|
|
|
`eto oznachaet, chto vy dolzhny ispol'zovat' dvojnye kavychki, kogda
|
2005-09-28 19:32:49 +08:00
|
|
|
ukazyvaete `eti imena v zaprose. Nekotorye interfejsy, takie kak
|
|
|
|
pgAdmin, vo vremya sozdaniya tablicy dobavlyayut dvojnye kavychki
|
|
|
|
avtomaticheski. Takim obrazom, chtoby identifikatory raspoznavalis' vy
|
|
|
|
dolzhny sledovat' odnomu iz sleduyuschih pravil:
|
|
|
|
* Izbegat' ispol'zovaniya dvojnyh kavychek pri sozdanii tablic
|
|
|
|
* Ispol'zovat' v identifikatorah tol'ko simvoly nizhnego registra
|
|
|
|
* Ispol'zovat' dvojnye kavychki dlya identifikatorov v zaprosah
|