2 PostgreSQL 常è¦åé¡ï¼FAQï¼
4 æè¿æ´æ°ï¼2007 å¹´ 2 æ 8 æ¥ ææäº 22:43:13 EST
5 ä¸æçæè¿æ´æ°ï¼2007 å¹´ 2 æ 12 æ¥ ææä¸ 12:00:04 CST
7 ç¶åç¶è·äººå¡ï¼Bruce Momjian (pgman@candle.pha.pa.us)
8 æ£é«ä¸æçç¶è·äººå¡ï¼éæç(ChaoYi, Kuo)ï¼kuo.chaoyi@gmail.comï¼
11 http://www.postgresql.org/files/documentation/faqs/FAQ.html æ¥çã
13 èä½æ¥ç³»çµ±å¹³å°ç¸éçåé¡å¯å¨ http://www.postgresql.org/docs/faq/
15 _________________________________________________________________
19 1.1)PostgreSQL æ¯ä»éº¼ï¼è©²æ麼ç¼é³ï¼
20 1.2)誰æ§å¶å管çPostgreSQL ï¼
21 1.3)PostgreSQLççæ¬æ¯ä»éº¼ï¼
22 1.4)PostgreSQLå¯ä»¥éè¡å¨åªäºä½æ¥ç³»çµ±å¹³å°ä¸ï¼
23 1.5)æå¾åªè£¡è½å¾å°PostgreSQLï¼
24 1.6)ææ°çç PostgreSQL æ¯ä»éº¼ï¼
25 1.7)æå¾åªè£¡è½å¾å°å° PostgreSQL çæ¯æï¼
26 1.8)æå¦ä½æ交ä¸å BUG å ±åï¼
27 1.9)æå¦ä½ç解已ç¥ç BUG ææ«ç¼ºçåè½ï¼
28 1.10)è½å¤ ç²åçææ°ææªæåªäºï¼
29 1.11)ææ該æ樣å¸ç¿ SQL ï¼
30 1.12)å¦ä½æ交è£ä¸ææ¯å å¥éç¼éä¼ï¼
31 1.13)PostgreSQL åå¶ä»è³æ庫系統æ¯èµ·ä¾å¦ä½ï¼
32 1.14)PostgreSQL å¯ä»¥èçæè¿ååå家å¤æå¶çè®ååï¼
36 2.1)æåå¯ä»¥ç¨ä»éº¼èªè¨å PostgreSQL é²è¡æºéï¼
37 2.2)æä»éº¼å·¥å·å¯ä»¥æ PostgreSQL ç¨æ¼ Web é é¢ï¼
38 2.3)PostgreSQL ææåå½¢ç¨æ¶çé¢(GUI)åï¼
42 3.1)ææ樣æè½æ PostgreSQL è£å¨ /usr/local/pgsql 以å¤çå°æ¹ï¼
43 3.2)æå¦ä½æ§å¶ä¾èªå¶ä»é»è¦çé£æ¥ï¼
44 3.3)ææ樣調æ´è³æ庫伺æå¨ä»¥ç²å¾æ´å¥½çæ§è½ï¼
45 3.4)PostgreSQL 裡å¯ä»¥ç²å¾ä»éº¼æ¨£ç調試ç¹æ§ï¼
46 3.5)çºä»éº¼å¨è©¦åé£æ¥ç»éææ¶å°ãSorry, too many clientsã è¨æ¯ï¼
47 3.6)PostgreSQL çåç´éç¨æåªäºå§å®¹ï¼
48 3.7)(ä½¿ç¨ PostgreSQL )æéè¦ä½¿ç¨ä»éº¼é»è¦ç¡¬é«ï¼
52 4.1) å¦ä½åªé¸æä¸åæ¥è©¢çµæçé å¹¾è¡ï¼ææ¯é¨æ©çä¸è¡ï¼
53 4.2) å¦ä½æ¥ç表ãç´¢å¼ãè³æ庫以åç¨æ¶çå®ç¾©ï¼å¦ä½æ¥ç psql
54 裡ç¨å°çæ¥è©¢æ令並顯示å®åï¼
55 4.3) å¦ä½æ´æ¹ä¸åæ¬ä½çè³æé¡åï¼
56 4.4) å®çè¨éï¼å®ä¸è¡¨ï¼ä¸åè³æ庫çæ大éå¶æ¯å¤å°ï¼
57 4.5) åå²ä¸åå¸åçææ¬æ件裡çè³æéè¦å¤å°ç£ç¢ç©ºéï¼
58 4.6) çºä»éº¼æçæ¥è©¢å¾æ¢ï¼çºä»éº¼éäºæ¥è©¢æ²æå©ç¨ç´¢å¼ï¼
59 4.7) æå¦ä½æè½çå°æ¥è©¢åªåå¨æ¯æ樣è©ä¼°èçæçæ¥è©¢çï¼
60 4.8) ææ樣åæ£å表éå¼æç´¢å大å°å¯«ç¡éçæ
61 £å表éå¼æ¥æ¾ï¼æ樣å©ç¨ç´¢å¼é²è¡å¤§å°å¯«ç¡éæ¥æ¾ï¼
62 4.9) å¨ä¸åæ¥è©¢è£¡ï¼ææ樣檢測ä¸åæ¬ä½æ¯å¦çº
63 NULLï¼æå¦ä½æè½æºç¢ºæåºèä¸è«ææ¬ä½æ¯å¦å«NULLå¼ï¼
64 4.10) å種å符é¡åä¹éæä»éº¼ä¸åï¼
65 4.11.1) ææ樣åµå»ºä¸ååºåèåææ¯èªåéå¢çæ¬ä½ï¼
66 4.11.2) æå¦ä½ç²å¾ä¸åæå¥çåºåèçå¼ï¼
67 4.11.3) åæä½¿ç¨ currval() æå°è´åå¶ä»ç¨æ¶çè¡çªææ³åï¼
68 4.11.4) çºä»éº¼ä¸å¨äºåç°å¸¸ä¸æ¢å¾éç¨åºåèå¢ï¼çºä»éº¼å¨åºåèæ¬ä½çåå¼ä¸
70 4.12) ä»éº¼æ¯ OIDï¼ä»éº¼æ¯ CTID ï¼
71 4.13) çºä»éº¼ææ¶å°é¯èª¤è³è¨ãERROR: Memory exhausted in
73 4.14) æå¦ä½æè½ç¥éæéè¡ç PostgreSQL ççæ¬ï¼
74 4.15) æå¦ä½åµå»ºä¸åé è¨å¼æ¯ç¶åæéçæ¬ä½ï¼
75 4.16) å¦ä½å·è¡å¤é£æ¥ï¼outer joinï¼æ¥è©¢ï¼
76 4.17) å¦ä½å·è¡æ¶åå¤åè³æ庫çæ¥è©¢ï¼
77 4.18) å¦ä½è®å½æ¸è¿åå¤è¡æå¤åè³æï¼
78 4.19) çºä»éº¼æå¨ä½¿ç¨ PL/PgSQL å½æ¸ååè¨æ表æææ¶å°é¯èª¤è³è¨ãrelation
79 with OID ##### does not existãï¼
80 4.20) ç®åæåªäºè³æè¤å¯«(replication)æ¹æ¡å¯ç¨ï¼
81 4.21) çºä½æ¥è©¢çµæ顯示ç表åææ¬åèæçæ¥è©¢èªå¥ä¸
82 çä¸åï¼çºä½å¤§å¯«çæä¸è½ä¿çï¼
83 _________________________________________________________________
87 1.1) PostgreSQL æ¯ä»éº¼ï¼è©²æ麼ç¼é³ï¼
89 PostgreSQL è®ä½ Post-Gres-Q-Lï¼ææåä¹ç°¡ç¨±çºPostgres
90 ãæ³è½ä¸ä¸å¶ç¼é³ç人å¡å¯å¾é裡ä¸è¼è²é³æä»¶ï¼ MP3 æ ¼å¼ ã
92 PostgreSQL æ¯é¢åç®æ¨çéä¿è³æ庫系統ï¼å®å·æå³çµ±åæ¥
93 è³æ庫系統çææåè½ï¼åæåå«æå°å¨ä¸ä¸ä»£ DBMS
94 系統ç使ç¨çå¢å¼·ç¹æ§ãPostgreSQL
95 æ¯èªç±åè²»çï¼ä¸¦ä¸æææºä»£ç¢¼é½å¯ä»¥ç²å¾ã
98 çéç¼éä¼ä¸»è¦çºå¿é¡èï¼ä»åéä½ä¸çåå°ä¸¦ééäºè¯ç¶²é²è¡è¯ç¹«ï¼éæ¯ä¸å社åéç¼é
99 ç®ï¼å®ä¸è¢«ä»»ä½å¬å¸æ§å¶ã
100 å¦æ³å å¥éç¼éä¼ï¼è«åè¦éç¼äººå¡å¸¸è¦åé¡ï¼FAQï¼
101 http://www.postgresql.org/files/documentation/faqs/FAQ_DEV.html
103 1.2) 誰æ§å¶ PostgreSQL ï¼
105 å¦æä½ å¨å°æ¾PostgreSQLçæé人ï¼ææ¯ä»éº¼ä¸
106 央å§å¡æï¼ææ¯ä»éº¼æ屬å¬å¸ï¼ä½ åªè½æ¾æ£äº---å çºä¸åä¹ä¸å
107 å¨ï¼ä½æåç確æä¸å æ ¸å¿å§å¡æåCVS管ççµï¼ä½éäºå·¥ä½çµçè¨
108 ç«ä¸»è¦æ¯çºäºé²è¡ç®¡çå·¥ä½èä¸æ¯å°PostgreSQLé²è¡ç¨ä½å¼æ§å¶ï¼PostgreSQLé
110 å¯åå çéç¼äººå¡ç¤¾ååææç¨æ¶æ§å¶çï¼ä½ æéè¦åçå°±æ¯è¨é±éµä»¶å表ï¼åèè¨è«å³å
111 ¯ï¼è¦åèPostgreSQLçéç¼è©³è¦ éç¼äººå¡å¸¸åé¡ (Developer's FAQ) ç²åè³è¨ï¼ã
113 1.3) PostgreSQL ççæ¬æ¯ä»éº¼?
115 PostgreSQLçç¼å¸éµå¾ç¶å¸ç BSD çæ¬ãå®å許ç¨æ¶ä¸éç®çå°ä½¿ç¨
116 PostgreSQLï¼çè³ä½ å¯ä»¥é·å® PostgreSQL
117 èä¸å«æºä»£ç¢¼ä¹å¯ä»¥ï¼å¯ä¸çéå¶å°±æ¯ä½ ä¸è½å è»é«èªèº«åé¡èåæå追訴æ³å¾
118 責任ï¼å¦å¤å°±æ¯è¦æ±ææçè»é«æ·è²ä¸é åæ¬ä»¥ä¸çæ¬è²æã
119 ä¸é¢å°±æ¯æåæ使ç¨çBSDçæ¬è²æå§å®¹ï¼
121 PostgreSQL è³æ庫管ç系統
123 é¨åçæ¬ï¼cï¼1996-2005ï¼PostgreSQL å¨çéç¼å°çµï¼é¨åçæ¬ï¼cï¼1994-1996
126 ï¼Portions copyright (c) 1996-2005,PostgreSQL Global Development Group
127 Portions Copyright (c) 1994-6 Regents of the University of
130 å許çºä»»ä½ç®ç使ç¨ï¼æ·è²ï¼ä¿®æ¹ååç¼éåè»é«åå®çææªèä¸æ¶åä»»ä½è²»ç¨ï¼
131 並ä¸ç¡é 簽署å æ¤èç¢ççèæï¼åææ¯ä¸é¢ççæ¬è²æåæ¬æ®µä»¥åä¸é¢å©æ®µæå
134 ï¼Permission to use, copy, modify, and distribute this software and
135 its documentation for any purpose, without fee, and without a written
136 agreement is hereby granted, provided that the above copyright notice
137 and this paragraph and the following two paragraphs appear in all
140 å¨ä»»ä½ææ³ä¸ï¼å å·å¤§å¸é½ä¸æ¿æå 使ç¨æ
141 ¤è»é«åå¶ææªèå°è´çå°ä»»ä½ç¶äºäººçç´æ¥çï¼
142 éæ¥çï¼ç¹æ®çï¼éå çæèç¸ä¼´èççæå£ï¼åæ¬å©çæ失ç責任ï¼å³ä½¿å å·å¤§å
143 ¸å·²ç¶å»ºè°äºéäºæ失çå¯è½æ§æä¹æ¯å¦æ¤ã
145 ï¼IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY
146 PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
147 DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS
148 SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA
149 HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.ï¼
151 å å·å¤§å¸æ確æ¾æ£ä»»ä½ä¿èï¼åæ¬ä½ä¸å±éæ¼æä¸ç¹å®ç¨éçåæ¥åå©ççé±å«ä¿èã
152 é裡æä¾çé份è»é«æ¯åºæ¼ãç¶ä½æ¯ãçåºç¤çï¼å èå å·å¤§å¸æ²æ責任æä¾ç¶
153 è·ï¼æ¯æï¼æ´æ°ï¼å¢å¼·æèä¿®æ¹çæåã
155 ï¼THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
156 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
157 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
158 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
159 CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
160 UPDATES, ENHANCEMENTS, OR MODIFICATIONS.ï¼
162 1.4) PostgreSQL å¯ä»¥éè¡å¨åªäºä½æ¥ç³»çµ±å¹³å°ä¸ï¼
164 ä¸è¬èªªä¾ï¼ä»»ä½ç¾å¨å° UNIX ç¸å®¹çä½æ¥ç³»çµ±ä¹ä¸é½è½éè¡ PostgreSQL
165 ãå¨å®è£æå裡ååºäºç¼ä½æç¶éæ確測試çå¹³å°ã
167 PostgreSQL ä¹å¯ä»¥ç´æ¥éè¡å¨åºæ¼å¾®è» Windows-NT çä½æ¥ç³»çµ±ï¼å¦
168 Win2000 SP4ï¼WinXP å Win2003ï¼å·²è£½ä½å®æçå®è£åå¯å¾
169 http://pgfoundry.org/projects/pginstallerä¸è¼ï¼åºæ¼MSDOSçWindowsä½æ¥
170 系統 ï¼Win95ï¼Win98ï¼WinMeï¼éè¦ééCygwin模æ¬ç°å¢éè¡PostgreSQLã
172 åæä¹æä¸åçº Novell Netware 6 éç¼ççæ¬å¯å¾ http://forge.novell.com
173 ç²åï¼çºOS/2(eComStation)éç¼ççæ¬å¯å¾
174 http://hobbes.nmsu.edu/cgi-bin/h-search?sh=1&button=Search&key=postgre
175 SQL&stype=all&sort=type&dir=%2F ä¸è¼ã
177 1.5) æå¾åªè£¡è½å¾å° PostgreSQLï¼
179 ééç覽å¨å¯å¾ http://www.postgresql.org/ftp/ ä¸è¼ï¼ä¹å¯ééFTPï¼å¾
180 ftp://ftp.PostgreSQL.org/pub/ ç«é»ä¸è¼ã
182 1.6) ææ°çç PostgreSQL æ¯ä»éº¼ï¼
184 PostgreSQL ææ°ççæ¬æ¯çæ¬ 8.2.3 ã
186 æåè¨åæ¯å¹´ç¼ä½ä¸å主è¦åç´çæ¬ï¼æ¯å¹¾åæç¼ä½ä¸åå°çæ¬ã
188 1.7) æå¾åªè£¡è½å¾å°å° PostgreSQL çæ¯æï¼
190 PostgreSQL社åéééµä»¶å表çºå¶å¤§å¤æ¸ç¨æ¶æä¾å¹«å©ï¼è¨é±éµä»¶å表ç主ç«é
192 http://www.postgresql.org/community/lists/ï¼ä¸è¬ææ³ä¸ï¼åå å¥General æ
193 Bugéµä»¶å表æ¯ä¸åè¼å¥½çéå§ã
195 主è¦çIRCé »éæ¯å¨FreeNode(irc.freenode.net)ç#postgresqlï¼çºäºé£ä¸æ
196 ¤é »éï¼å¯ä»¥ä½¿ç¨ UNIX ç¨åº ircï¼å¶æä»¤æ ¼å¼ï¼ irc -c '#postgresql'
197 "$USER" irc.freenode.net ï¼æè使ç¨å¶ä»IRC客æ¶ç«¯ç¨åºãå¨æ¤ç¶²çµ¡ä¸éå
198 å¨ä¸å PostgreSQL ç西ççé »é(#postgersql-es)åæ³èªé »é
199 (#postgresql-fr)ãå樣å°ï¼å¨ EFNET ä¸ä¹æä¸å PostgreSQL ç交æµé »éã
201 å¯æä¾åæ¥æ¯æçå¬å¸å表å¯å¨ http://techdocs.postgresql.org/companies.php
204 1.8) æå¦ä½æ交ä¸å BUG å ±åï¼
206 å¯è¨ªå http://www.postgresql.org/support/submitbugï¼å¡«å¯« Bug
207 ä¸å ±è¡¨æ ¼å³å¯ï¼å樣ä¹å¯è¨ªå ftp ç«é» ftp://ftp.PostgreSQL.org/pub/
208 檢æ¥æç¡æ´æ°çPostgreSQL çæ¬æè£ä¸ã
210 ééä½¿ç¨ Bug æäº¤è¡¨æ ¼ææ¯ç¼å¾ PostgreSQL éµä»¶å表ç Bug
212 * ææ交å§å®¹ä¸æ¯ä¸å Bug åå¶ä¸æ¯ Bug çåå ã
213 * ææ交å§å®¹æ¯ä¸åå·²ç¥ç Bug 並ä¸å·²ç¶å å¥ TODO å¾èçä»»åå表ã
214 * ææ交ç Bug å·²å¨ç¶åçæ¬ä¸è¢«ä¿®æ£ã
215 * ææ交ç Bug 已修æ£ä½å°æªå°è£ä¸å å¥ç¾å¨çç¼å¸è»é«åã
216 * è«æ±æ交èæä¾æ´è©³ç´°çè³è¨ï¼
219 + å¯éç¾ Bug ç測試æ¡ä¾
222 * ææ交å§å®¹æ¯ä¸åæ° Bugï¼å°å·è¡ä»¥ä¸å·¥ä½ï¼
223 + åµå»ºä¸åæ°è£ä¸ä¸¦å°å¶å å¥ä¸ä¸å主è¦çæ¬ææ¯å°çæ¹é²çæ¬ä¸ã
224 + æ¤ Bug æ«æä¸è½ä¿®æ£ï¼å°è¢«å è³ TODO å¾èçä»»åå表ã
226 1.9) æå¦ä½ç解已ç¥ç BUG ææ«ç¼ºçåè½ï¼
228 PostgreSQL æ¯æä¸åæ´å±ç SQL:2003 çåéãåé±æåç TODO å表ï¼çè§£å·²ç¥ Bug
229 å表ãæ«ç¼ºçåè½åå°ä¾çéç¼è¨åã
231 è¦æ±å¢å æ°åè½çç³è«é常ææ¶å°ä»¥ä¸ä¹ä¸çåè¦ï¼
232 * 該åè½å·²å å¥ TODO å¾èçä»»åå表ã
233 * 該åè½ä¸æ¯å¿é çï¼å çºï¼
234 + å®æ¯ç¾æçä¸ç¬¦å SQL æ¨æºçæåè½çéè¤ã
235 + 該åè½æ§æ大大å¢å 代碼çè¤éç¨åºï¼è帶ä¾ç好èæ¯å¾®ä¸è¶³éçã
236 + 該åè½æ¯ä¸å®å¨ææ¯ä¸å¯é çã
237 * 該åè½å°è¢«å å¥ TODO å¾èçä»»åå表ã
239 PostgreSQL ä¸ä½¿ç¨ Bug è·è¹¤ç³»çµ±ï¼å çºæåç¼ç¾å¨éµä»¶å表ä¸
241 ä»»åå表總æ¯èæ¼ææ°çæçæ¹å¼å·¥ä½æçææ´é«ä¸äºãäºå¯¦ä¸ï¼Bugä¸æå¨æåçè»é«ä¸
242 åå¨å¾é·æéï¼ å°å½±é¿å¾å¤ç¨æ¶çBugä¹ç¸½æ¯å¾å¿«æ被修æ
243 £ãå¯ä¸è½æ¾å°æææ¹é²ãæé«åä¿®æ£çå°æ¹æ¯ CVS
244 çæ¥èªè³è¨ï¼å³ä½¿æ¯å¨è»é«æ°çæ¬çç¼å¸è³è¨ä¸ä¹ä¸æååºæ¯ä¸èçè»é«æ´æ°ã
246 1.10) è½å¤ ç²åçææ°ææªæåªäºï¼
248 PostgreSQL åå«å¤§éçææªï¼ä¸»è¦æ詳細çåèæåï¼æåé åä¸äºç測試ä¾åãåè¦
249 /doc ç®éï¼è¯è¨»ï¼æçº $PGHOME/docï¼ã ä½ éå¯ä»¥å¨ç·ç覽 PostgreSQL
250 çæåï¼å¶ç¶²åæ¯ï¼http://www.PostgreSQL.org/docsã
252 æå©æ¬éæ¼PostgreSQLçæ¸å¨ç·æä¾ï¼å¨
253 http://www.postgresql.org/docs/books/awbook.html å
254 http://www.commandprompt.com/ppbook/ ã ä¹æ大éç PostgreSQL
255 æ¸ç±å¯ä¾è³¼è²·ï¼å¶ä¸æçºæµè¡çä¸æ¬æ¯ç± Korry Douglas 編寫çãå¨
256 http://techdocs.PostgreSQL.org/techdocs/bookreviews.phpä¸ ä¸æ大éæé
257 PostgreSQL æ¸ç±çç°¡ä»ã å¨ http://techdocs.PostgreSQL.org/ ä¸æ¶éäºæé
258 PostgreSQL ç大éæè¡æç« ã
260 客æ¶ç«¯çå½ä»¤è¡ç¨åºpsqlæä¸äºä»¥ \d éé
261 çå½ä»¤ï¼å¯é¡¯ç¤ºéæ¼é¡åï¼æä½ç¬¦ï¼å½æ¸ï¼èåçè³è¨ï¼ä½¿ç¨ \?
262 å¯ä»¥é¡¯ç¤ºææå¯ç¨çå½ä»¤ã
264 æåç web ç«é»åå«æ´å¤çææªã
266 1.11) ææ該æ樣å¸ç¿ SQL ï¼
268 é¦åèæ®ä¸è¿°æå°çèPostgreSQLç¸éçæ¸ç±ï¼å¦å¤ä¸æ¬æ¯ Teach Yourself SQL in
269 21 Days, Second Editionï¼å¶è©³ç´°ä»ç´¹ç網åæ¯
270 http://members.tripod.com/er4ebus/sql/index.htmï¼ æåç許å¤ç¨æ¶åæ¡The
271 Practical SQL Handbookï¼ Bowman, Judith S.
272 編寫ï¼Addison-Wesleyå¬å¸åºçï¼å¶ä»çååæ¡ The Complete Reference SQL,
273 Groff 編寫ï¼McGraw-Hill å¬å¸åºçã
275 å¨ä¸å網åä¸ä¹æå¾å¥½çæç¨ï¼ä»åæ¯
276 * http://www.intermedia.net/support/sql/sqltut.shtm
277 * http://sqlcourse.com.
278 * http://www.w3schools.com/sql/default.asp
279 * http://mysite.verizon.net/Graeme_Birchall/id1.html
281 1.12)å¦ä½æ交è£ä¸ææ¯å å¥éç¼éä¼ï¼
283 è©³è¦ éç¼äººå¡å¸¸è¦åé¡ (Developer's FAQ) ã
285 1.13) PostgreSQL åå¶ä»è³æ庫系統æ¯èµ·ä¾å¦ä½ï¼
287 è©å¹è»é«æ好幾種æ¹æ³ï¼åè½ï¼æ§è½ï¼å¯é æ§ï¼æ¯æåå¹æ ¼ã
290 PostgreSQL ææ大ååç¨è³æ庫æå¤çåè½ï¼ä¾å¦ï¼äºåï¼å
291 æ¥è©¢ï¼è§¸ç¼å¨ï¼è¦åï¼å¤éµåèå®æ´æ§åè¤éçéå®çã
292 æåéæä¸äºå®åæ²æçç¹æ§ï¼å¦ç¨æ¶å®ç¾©é¡åï¼ç¹¼æ¿ï¼è¦ååå¤çæ¬ä¸¦è¡æ§å¶ä
296 PostgreSQLåå¶ä»åç¨åéæºçè³æ庫å·æé¡ä¼¼çæ§è½ãå°æäºèçå®æ¯è¼å¿«ï¼å°
297 å¶ä»ä¸äºèçå®æ¯è¼æ¢ã èå¶ä»è³æ庫ç¸æ¯ï¼æåçæ§è½åªå£éå¸¸å¨ +/-
301 æåé½ç¥éè³æ庫å¿é æ¯å¯é çï¼å¦åå®å°±ä¸é»ç¨é½æ²æãæååªååå°ç¼ä½ç¶éèª
302 ç測試çï¼ç¼ºé·æå°çç©©å®ä»£ç¢¼ãæ¯åçæ¬è³å°æä¸åæç beta
303 測試æéï¼ä¸¦ä¸æåçç¼å¸æ
304 ·å²é¡¯ç¤ºæåå¯ä»¥æä¾ç©©å®çï¼ç¢åºçï¼å¯ç¨æ¼çç¢ä½¿ç¨ççæ¬ãæåç¸ä¿¡å¨é
305 æ¹é¢æåèå¶ä»çè³æ庫è»é«æ¯ç¸ç¶çã
308 æåçéµä»¶å表æä¾ä¸åé常大çéç¼äººå¡åç¨æ¶ççµä»¥å¹«å©è§£æ±ºæ碰å°ç
310 總æ¯è½è§£æ±ºåé¡ï¼ç¸æ¯ä¹ä¸ï¼åç¨è³æ庫è»é«ä¹ä¸¦ä¸æ¯ç¸½è½å¤ æä¾è§
312 ç´æ¥èéç¼äººå¡ï¼ç¨æ¶ç¾¤ï¼æååæºç¨åºæ¥è§¸ä½¿PostgreSQLçæ¯ææ¯å¶ä»è³
313 æ庫éè¦å¥½ãéæä¸äºåæ¥
314 æ§çå¨é¢æè¡æ¯æï¼å¯ä»¥çµ¦æä¾çµ¦é£äºéè¦ç人ãï¼åé±1.7 å°ç¯ï¼
317 æåå°ä»»ä½ç¨éé½åè²»ï¼åæ¬åç¨åéåç¨ç®çã
318 ä½ å¯ä»¥ä¸å éå¶å°åä½ çç¢å裡å å¥æåç代碼ï¼é¤äºé£äºæåå¨ä¸é¢ççæ¬
319 è²æ裡è²æç BSDçæ¬ä¹å¤çå§å®¹ã
321 1.14) PostgreSQL å¯ä»¥èçæè¿ååå家å¤æå¶çè®åå?
323 PostgreSQL 8.0ä¹åççæ¬æ¯ä½¿ç¨ä½æ¥ç³»çµ±ä¸çæåè³æ庫ä¾èçå¤æå¶çè³è¨ï¼èª
324 8.0 çå以å¾ççæ¬ PostgreSQL æèªèº«å«æææ°çæåè³è¨ã
325 _________________________________________________________________
329 2.1) æåå¯ä»¥ç¨ä»éº¼èªè¨å PostgreSQL é²è¡æºéï¼
331 PostgreSQL (é è¨ææ³)åªå®è£æ C åå§åµå¼ C
332 çæ¥å£ï¼å¶ä»çæ¥å£é½æ¯ç¨ç«çé ç®ï¼è½å¤ åå¥ä¸è¼ï¼éäºæ¥å£é ç®ç¨ç«ç好è
333 æ¯ä»åå¯ä»¥æåèªçç¼å¸è¨åååèªç¨ç«çéç¼çµã
335 ä¸äºç·¨ç¨èªè¨å¦ PHP é½æ訪å PostgreSQL çæ¥å£ï¼PerlãTCLãPython
336 以åå¾å¤å¶ä»èªè¨çæ¥å£å¨ http://gborg.postgresql.org 網ç«ä¸ç
337 Drivers/Interfaces å°ç¯å¯æ¾å°ï¼ 並ä¸éé Internet å¾å®¹ææç´¢å°ã
339 2.2) æä»éº¼å·¥å·å¯ä»¥æ PostgreSQL ç¨æ¼ Web é é¢ï¼
341 ä¸åä»ç´¹ä»¥è³æ庫çºå¾å°çæºä¸é¯çç«é»æ¯ï¼http://www.webreview.comã
343 å°æ¼ Web éæï¼PHP æ¯ä¸å極好çæ¥å£ãå®å¨ http://www.php.net/ã
345 å°æ¼è¤éçä»»åï¼å¾å¤äººæ¡ç¨ Perl æ¥å£å ä½¿ç¨ CGI.pm ç DBD::Pg æ mod_perl
348 2.3)PostgreSQL ææåå½¢ç¨æ¶çé¢åï¼
350 åæ¥ç¨æ¶ææ¯éæºéç¼äººå¡è½æ¾å°å¾å¤çæé PostgreSQLçGUI å形工å·è»é«ï¼å¨
351 PostgreSQL社åææª æä¸å詳細çå表ã
352 _________________________________________________________________
356 3.1)ææ樣è½æ PostgreSQL è£å¨ /usr/local/pgsql 以å¤çå°æ¹ï¼
358 å¨éè¡ configure æå ä¸ --prefix é¸é ã
360 3.2) æå¦ä½æ§å¶ä¾èªå¶ä»é»è¦çé£æ¥ï¼
362 é è¨ææ³ä¸ï¼PostgreSQL åªå許ä¾èªæ¬æ©ä¸éé unix åå¥æ¥åæ TCP/IP
363 æ¹å¼çé£æ¥ã ä½ åªæå¨ä¿®æ¹äºéç½®æ件 postgresql.conf ä¸ç
364 listen_addressesï¼ä¸ä¹å¨éç½®æ件 $PGDATA/pg_hba.conf ä¸æéäº
365 åºæ¼é ç¨é»è¦ï¼ host-based ï¼ç身份èªèï¼ä¸¦éæ°åå
366 PostgreSQLï¼å¦åå¶ä»é»è¦æ¯ä¸è½èä½ ç PostgreSQL 伺æå¨é²è¡é£æ¥çã
368 3.3) ææ樣調æ´è³æ庫å¼æ以ç²å¾æ´å¥½çæ§è½ï¼
370 æä¸å主è¦æ¹é¢å¯ä»¥æå PostgreSQL çæ½è½ã
373 é主è¦æ¶åä¿®æ¹æ¥è©¢æ¹å¼ä»¥ç²åæ´å¥½çæ§è½:
375 + åµå»ºç´¢å¼ï¼åæ¬è¡¨éå¼åé¨åç´¢å¼ï¼
376 + ä½¿ç¨ COPY èªå¥ä»£æ¿å¤å Insert èªå¥ï¼
377 + å°å¤åSQLèªå¥çµæä¸åäºå以æ¸å°æ交äºåçéé·ï¼
378 + å¾ä¸åç´¢å¼ä¸æåå¤æ¢è¨éæä½¿ç¨ CLUSTERï¼
379 + å¾ä¸åæ¥è©¢çµæä¸ååºé¨åè¨éæä½¿ç¨ LIMITï¼
380 + 使ç¨é ç·¨è¯å¼æ¥è©¢ï¼Prepared Query)ï¼
381 + ä½¿ç¨ ANALYZE 以ä¿æ精確çåªåçµ±è¨ï¼
382 + å®æä½¿ç¨ VACUUM æ pg_autovacuum
383 + é²è¡å¤§éè³ææ´æ¹æååªé¤ç´¢å¼ï¼ç¶å¾é建索å¼ï¼
386 éç½®æ件 postgres.conf ä¸çå¾å¤è¨
387 ç½®é½æå½±é¿æ§è½ï¼ææåæ¸çå表å¯è¦ï¼
388 管çå¡æå/è³æ庫伺æå¨éè¡ç°å¢/è³æ庫伺æå¨éè¡éç½®ï¼
389 æéåæ¸ç解éå¯è¦ï¼http://www.varlena.com/varlena/GeneralBits/Tidb
390 its/annotated_conf_e.html å
391 http://www.varlena.com/varlena/GeneralBits/Tidbits/perf.htmlã
394 é»è¦ç¡¬é«å°æ§è½çå½±é¿å¯ç覽
395 http://candle.pha.pa.us/main/writings/pgsql/hw_performance/inde
396 x.html å http://www.powerpostgresql.com/PerfList/ã
398 3.4)PostgreSQL 裡å¯ä»¥ç²å¾ä»éº¼æ¨£ç調試ç¹æ§ï¼
400 PostgreSQL æå¾å¤é¡ä¼¼ log_*
401 ç伺æå¨éç½®è®éå¯ç¨æ¼æ¥è©¢çåå°åé²ç¨çµ±è¨ï¼èéäºå·¥ä½å°èª¿è©¦åæ§è½æ¸¬è©¦å
404 3.5) çºä»éº¼å¨è©¦åé£æ¥ææ¶å°ãSorry, too many
405 clientsï¼å·²æ太å¤ç¨æ¶é£æ¥ï¼ãæ¶æ¯ï¼
407 éè¡¨ç¤ºä½ å·²éå°é è¨ 100 å並ç¼(åä½)å¾å°é²ç¨æ¸çéå¶ï¼ä½ éè¦ééä¿®æ¹
408 postgresql.conf æ件ä¸ç max_connections å¼ä¾ å¢å postmaster
409 çå¾å°ä½µç¼èçæ¸ï¼ä¿®æ¹å¾ééæ°åå postmasterã
411 3.6)PostgreSQL çåç´éç¨æåªäºå§å®¹ ï¼
413 PostgreSQL éç¼çµå°æ¯æ¬¡å°çæ¬çåç´ä¸»è¦åªåäºä¸äº Bug ä¿®æ£å·¥ä½ï¼å æ¤å¾
414 7.4.8 åç´å° 7.4.9 ä¸éè¦ dump å restoreï¼åéè¦åæ
415 ¢è³æ庫伺æå¨ï¼å®è£æ´æ°å¾çè»é«åï¼ç¶å¾éå伺æå¨å³å¯ã
417 ææPostgreSQLçç¨æ¶æ該å¨ææ¥è¿ï¼ä½ æ使ç¨ç主çæ¬ï¼çå°æ¹é²çæ¬ç¼ä½ç¡å¿«åç´
418 ãå管æ¯æ¬¡åç´å¯è½é½æä¸é»é¢¨éªï¼PostgreSQLçå°æ¹ é²çååæ¯è¨è¨ç¨ä¾ä¿®æ
420 çï¼ç¨å¼ç¢¼æ¹åè¼å°ï¼æ以風éªéæ¯å¾å°çãPostgreSQL社åèªçºä¸è¬ææ³ä¸ä¸åç´ç
423 主çæ¬çåç´ï¼ä¾å¦å¾ 7.3 å° 7.4ï¼é常æä¿®æ¹ç³»çµ±è¡¨åè³æ表çå§é¨æ ¼å¼ã
424 éäºæ¹è®ä¸è¬æ¯è¼è¤éï¼å æ¤æåä¸ç¶æè³ææ件çåå¾å¼å®¹æ§ãå æ¤å¾èçæ¬ä¸
425 é²è¡è³æå°åºï¼dumpï¼/ç¶å¾å¨æ°çæ¬ä¸
426 é²è¡è³æå°å¥ï¼reloadï¼å°ä¸»çæ¬çåç´æ¯å¿é çã
428 3.7)(ä½¿ç¨ PostgreSQL )æéè¦ä½¿ç¨ä»éº¼é»è¦ç¡¬é« ï¼
430 ç±æ¼é»è¦ç¡¬é«å¤§å¤æ¸æ¯ç¸å®¹çï¼äººå總æ¯å¾åæ¼ç¸ä¿¡ææé»è¦ç¡¬é«è³ªéä¹æ¯ç¸
431 åçãäºå¯¦ä¸ä¸æ¯ï¼ ECC RAMï¼å¸¶å¥å¶æ ¡é©çè¨æ¶é«ï¼ï¼SCSI
432 ï¼ç¡¬ç¢ï¼ååªè³ªç主æ©æ¿æ¯ä¸äºä¾¿å®è²¨è¦æ´å å¯é ä¸å·ææ´å¥½çæ§è½ã
433 PostgreSQL å¹¾ä¹å¯ä»¥éè¡å¨ä»»ä½ç¡¬é«ä¸ï¼
434 ä½å¦æå¯é æ§åæ§è½å°ä½ ç系統å¾éè¦ï¼ä½ å°±éè¦å¨é¢çç 究ä¸ä¸ä½ ç硬é«çµæ
435 äºãå¨æåçéµä»¶å表ä¸ä¹æéæ¼ ç¡¬é«éç½®åæ§å¹æ¯çè¨è«ã
436 _________________________________________________________________
440 4.1) å¦ä½åªé¸æä¸åæ¥è©¢çµæçé å¹¾è¡ï¼ææ¯é¨æ©çä¸è¡ï¼
442 å¦æä½ åªæ¯è¦æåå¹¾è¡è³æï¼ä¸¦ä¸ä½ å¨å·è¡æ¥è©¢ä¸
443 ç¥é確åçè¡æ¸ï¼ä½ å¯ä»¥ä½¿ç¨ LIMIT åè½ã å¦ææä¸åç´¢å¼è ORDER BY ä¸
444 çæ¢ä»¶å¹éï¼PostgreSQL å¯è½å°±åªèçè¦æ±çé å¹¾æ¢è¨éï¼
445 ï¼å¦åå°å°æ´åæ¥è©¢é²è¡èçç´å°çæéè¦çè¡ï¼ãå¦æå¨å·è¡æ¥è©¢åè½æä¸ç¥é確åçè¨éæ
446 ¸ï¼ å¯ä½¿ç¨æ¸¸æ¨(cursor)åFETCHåè½ã
448 å¯ä½¿ç¨ä»¥ä¸æ¹æ³æåä¸è¡é¨æ©è¨éçï¼
455 å¦ä½æ¥ç表ãç´¢å¼ãè³æ庫以åç¨æ¶çå®ç¾©ï¼å¦ä½æ¥çpsql裡ç¨å°çæ¥è©¢æ令並顯示å
458 å¨psqlä¸ä½¿ç¨ \dt å½ä»¤ä¾é¡¯ç¤ºè³æ表çå®ç¾©ï¼è¦ç解 psql ä¸
459 çå®æ´å½ä»¤å表å¯ä½¿ç¨ \? ï¼å¦å¤ï¼ä½ ä¹å¯ä»¥é±è® psql çæºä»£ç¢¼ æ件
460 pgsql/src/bin/psql/describe.cï¼å®åæ¬çºçæ psql åææ§å½ä»¤ç輸åºçææ SQL
461 å½ä»¤ãä½ éå¯ä»¥å¸¶ -E é¸é åå psqlï¼ é樣å®å°åå°åºä½ å¨ psql ä¸
462 æ給åºçå½ä»¤å·è¡æçå§é¨å¯¦é使ç¨ç SQL
463 æ¥è©¢èªå¥ãPostgreSQLä¹æä¾äºä¸åå¼å®¹ SQLç INFORMATION SCHEMA æ¥å£ï¼
464 ä½ å¯ä»¥å¾é裡ç²åéæ¼è³æ庫çè³è¨ã
466 å¨ç³»çµ±ä¸ä¹æä¸äºä»¥ pg_ æé ç系統表ä¹æè¿°äºè¡¨çå®ç¾©ã
468 ä½¿ç¨ psql -l æ令å¯ä»¥ååºææçè³æ庫ã
470 ä¹å¯ä»¥ç覽ä¸ä¸ pgsql/src/tutorial/syscat.source
471 æ件ï¼å®åèäºå¾å¤å¯å¾è³æ庫系統表ä¸ç²åè³è¨çSELECTèªæ³ã
473 4.3) å¦ä½æ´æ¹ä¸åæ¬ä½çè³æé¡åï¼
475 å¨8.0çæ¬è£¡æ´æ¹ä¸åæ¬ä½çè³æé¡åå¾å®¹æï¼å¯ä½¿ç¨ ALTER TABLE ALTER COLUMN
478 å¨ä»¥åççæ¬ä¸ï¼å¯ä»¥é樣åï¼
480 ALTER TABLE tab ADD COLUMN new_col new_data_type;
481 UPDATE tab SET new_col = CAST(old_col AS new_data_type);
482 ALTER TABLE tab DROP COLUMN old_col;
485 ä½ ç¶å¾å¯ä»¥ä½¿ç¨ VACUUM FULL tab æ令ä¾ä½¿ç³»çµ±æ¶åç¡æè³ææä½ç¨ç空éã
487 4.4) å®æ¢è¨éï¼å®å表ï¼å®åè³æ庫çæ大éå¶æ¯å¤å°ï¼
491 å®åè³æ庫æå¤§å°ºå¯¸ï¼ ç¡éå¶ï¼å·²åå¨æ 32TB çè³æ庫ï¼
492 å®å表çæå¤§å°ºå¯¸ï¼ 32 TB
493 ä¸è¡è¨éçæå¤§å°ºå¯¸ï¼ 1.6 TB
494 ä¸åæ¬ä½çæ大尺寸? 1 GB
495 ä¸å表裡æ大åæ¸ï¼ ç¡éå¶
496 ä¸å表裡æ大æ¬ä½æ¸ï¼ 250-1600 ï¼èåé¡åæéï¼
497 ä¸å表裡çæ大索å¼æ¸éï¼ ç¡éå¶
499 ç¶ç¶ï¼å¯¦éä¸æ²æçæ£çç¡éå¶ï¼éæ¯è¦åå¯ç¨ç£ç¤ç©ºéãå¯ç¨è¨æ¶é«/交æåçå¶ç´ã
500 äºå¯¦ä¸ï¼ç¶ä¸è¿°éäºæ¸å¼è®å¾ç°å¸¸å°å¤§æï¼ç³»çµ±æ§è½ä¹æåå¾å¤§å½±é¿ã
502 å®è¡¨çæå¤§å¤§å° 32 TB ä¸éè¦ä½æ¥
503 系統å°å®åæ件ä¹éé麼大çæ¯æã大表ç¨å¤å 1 GB çæ件åå²ï¼å æ
504 ¤æ件系統大å°çéå¶æ¯ä¸éè¦çã
506 å¦æé è¨çå¡å¤§å°å¢é·å° 32K ï¼æ大çå®è¡¨å¤§å°åæ大åæ¸éå¯ä»¥å¢å å°ååã
508 æä¸åéå¶å°±æ¯ä¸è½å°å¤§å°å¤æ¼2000å
509 ç¯çååµå»ºç´¢å¼ã幸éå°æ¯é樣çç´¢å¼å¾å°ç¨å°ãééå°å¤å
510 ç¯åçå§å®¹é²è¡MD5åç¨éç®çµæé²è¡å½æ¸ç´¢å¼å¯å°åçå¯ä¸æ§å¾å°ä¿èï¼
511 並ä¸å¨æ檢索å許å°åä¸çå®è©é²è¡æç´¢ã
513 4.5) åå²ä¸åå¸åçææ¬æ件裡çè³æéè¦å¤å°ç£ç¤ç©ºéï¼
515 ä¸å Postgres è³æ庫ï¼å
516 å²ä¸åææ¬æ件ï¼æä½ç¨ç空éæå¤å¯è½éè¦ç¸ç¶æ¼éåææ¬æ件èªèº«å¤§å°5åçç£ç¤ç©ºé
519 ä¾å¦ï¼åè¨æä¸å 100,000 è¡çæ件ï¼æ¯è¡æä¸åæ´æ¸åä¸åææ¬æè¿°ã åè¨
520 ææ¬ä¸²çå¹³åé·åº¦çº20ä½åçµ(Byte)ãææ¬æ件ä½ç¨ 2.8 MBãå
521 æ¾éäºè³æçPostgreSQLè³æ庫æ件大ç´æ¯ 5.2 MB:
522 24 ååçµ: æ¯è¡çé ï¼å¤§ç´å¼ï¼
523 24 ååçµç¯: ä¸åæ´æ¸åæ¬ä½åä¸åææ¬åæ¬ä½
524 + 4 ååçµç¯: é é¢å§æååçµçæé
525 ----------------------------------------
528 PostgreSQL è³æé ç大å°æ¯ 8192 ä½åçµ (8 KB)ï¼åï¼
531 ------------------- = 158 è¡/è³æé ï¼åä¸åæ´ï¼
535 -------------------- = 633 è³æé ï¼åä¸åæ´ï¼
538 633 è³æé * 8192 åç¯/é = 5,185,536 åç¯ï¼5.2 MBï¼
540 ç´¢å¼ä¸éè¦é麼å¤çé¡å¤æ¶èï¼ä½ä¹ç¢ºå¯¦åæ¬è¢«ç´¢å¼çè³æï¼å æ
543 ç©ºå¼ NULL åæ¾å¨ä½åä¸ï¼å æ¤ä½ç¨å¾å°ç空éã
545 4.6) çºä»éº¼æçæ¥è©¢å¾æ¢ï¼çºä»éº¼éäºæ¥è©¢æ²æå©ç¨ç´¢å¼ï¼
547 並éæ¯åæ¥è©¢é½æèªå使ç¨ç´¢å¼ãåªæå¨è¡¨ç大å°è¶éä¸åæå°å¼ï¼ä¸¦ä¸æ¥è©¢åªæé
548 ¸ä¸è¡¨ä¸è¼å°æ¯ä¾çè¨éææææ¡ç¨ç´¢å¼ã éæ¯å çºç´¢å¼æçå¼èµ·çé¨å³ç£ç¤å
549 åå¯è½æ¯ç´æ¥å°è®å表ï¼é åºæçï¼æ´æ¢ã
551 çºäºå¤æ·æ¯å¦ä½¿ç¨ç´¢å¼ï¼PostgreSQL
552 å¿é ç²å¾æé表ççµ±è¨å¼ãéäºçµ±è¨å¼å¯ä»¥ä½¿ç¨ VACUUM ANALYZEï¼æ ANALYZE
553 ç²å¾ã 使ç¨çµ±è¨å¼ï¼åªåå¨ç¥é表ä¸
554 æå¤å°è¡ï¼å°±è½å¤ æ´å¥½å°å¤æ·æ¯å¦å©ç¨ç´¢å¼ã
555 çµ±è¨å¼å°ç¢ºå®åªåçé£æ¥é åºåé£æ¥æ¹æ³ä¹å¾æç¨ãå¨è¡¨çå§å®¹ç¼çè®åæï¼æå®æé²è
558 ç´¢å¼é常ä¸ç¨æ¼ ORDER BY
559 æå·è¡é£æ¥ãå°ä¸å大表çä¸æ¬¡é åºæçååä¸æ¬¡æåºé常æ¯ç´¢å¼æçè¦å¿«ãç¶èï¼å¦æ
561 çµåå¨ä¸èµ·ä½¿ç¨ç話ï¼é常å°æ使ç¨ç´¢å¼ï¼å çºéæåè¿å表ä¸çä¸å°é¨åè¨éã
563 å¦æä½ ç¢ºä¿¡PostgreSQLçåªåå¨ä½¿ç¨é åºæçæ¯ä¸æ£ç¢ºçï¼ä½ å¯ä»¥ä½¿ç¨SET
564 enable_seqscan TO 'off'æ令ä¾ééé åºæçï¼
565 ç¶å¾å次éè¡æ¥è©¢ï¼ä½ å°±å¯ä»¥çåºä½¿ç¨ä¸åç´¢å¼æçæ¯å¦ç¢ºå¯¦è¦å¿«ä¸äºã
567 ç¶ä½¿ç¨éé符æä½ï¼ä¾å¦ LIKE æ ~ æï¼ç´¢å¼åªè½å¨ç¹å®çææ³ä¸ä½¿ç¨ï¼
568 * å符串çéå§é¨åå¿é æ¯æ®éå符串ï¼ä¹å°±æ¯èªªï¼
569 + LIKE 模å¼ä¸è½ä»¥ % æé ã
570 + ~ ï¼æ£å表éå¼ï¼æ¨¡å¼å¿é 以 ^ æé ã
571 * å符串ä¸è½ä»¥å¹éå¤åå符ç模å¼é¡æé ï¼ä¾å¦ [a-e]ã
572 * 大å°å¯«ç¡éçæ¥æ¾ï¼å¦ ILIKE å ~* çä¸ä½¿ç¨ç´¢å¼ï¼ä½å¯ä»¥ç¨ 4.8
574 * å¨å initdb æå¿é æ¡ç¨é è¨çæ¬å°è¨ç½® C
575 localeï¼å çºç³»çµ±ä¸å¯è½ç¥éå¨é C locale ææ³æä¸ä¸åæ大å符æ¯ä»éº¼ã
576 å¨é種ææ³ä¸ï¼ä½ å¯ä»¥åµå»ºä¸åç¹æ®ç text_pattern_ops ç´¢å¼ä¾ç¨æ¼
580 ï¼é¤éè¦æ¥è©¢çè³æé¡ååç´¢å¼çè³æé¡åç¸å¹éï¼å¦åç´¢å¼ç¶å¸¸æ¯æªè¢«ç¨å°ï¼ç¹å¥æ
581 ¯å° int2, int8 åæ¸å¼åçç´¢å¼ã
583 4.7) æå¦ä½æè½çå°æ¥è©¢åªåå¨æ¯æ樣è©ä¼°èçæçæ¥è©¢ï¼
587 4.8) ææ樣åæ£å表éå¼æç´¢å大å°å¯«ç¡éçæ
588 £å表éå¼æ¥æ¾ï¼æ樣å©ç¨ç´¢å¼é²è¡å¤§å°å¯«ç¡éæ¥æ¾ï¼
590 æä½ç¬¦ ~ èçæ£å表éå¼å¹éï¼è ~* èç大å°å¯«ç¡éçæ£å表éå¼å¹éã大å°å¯«ç¡éç
593 大å°å¯«ç¡éççå¼æ¯è¼é常寫åï¼
596 WHERE lower(col) = 'abc';
598 é樣å°ä¸æ使ç¨æ¨æºçç´¢å¼ãä½æ¯å¯ä»¥åµå»ºä¸åå¨é種ææ³ä¸ä½¿ç¨ç表éå¼ç´¢å¼
600 CREATE INDEX tabindex ON tab (lower(col));
602 å¦æä¸è¿°ç´¢å¼å¨åµå»ºæå å¥ UNIQUE ç´æï¼éç¶ç´¢å¼æ¬ä½èªèº«å§å®¹å¯ä»¥å
603 å²å¤§å°å¯«ä¸éçå§å®¹ï¼ä½å¦ææ UNIQUE
604 ç´æå¾ï¼éäºå§å®¹ä¸è½ååæ¯å¤§å°å¯«ä¸åï¼å¦åæé æè¡çªï¼ãçºäºä¿è
605 ä¸ç¼çé種ææ³ï¼å¯ä»¥ä½¿ç¨ CHECK ç´ææ¢ä»¶ææ¯è§¸ç¼å¨å¨éå¥æé²è¡éå¶ã
607 4.9) å¨ä¸åæ¥è©¢è£¡ï¼ææ樣檢測ä¸åæ¬ä½æ¯å¦çº NULL
608 ï¼æå¦ä½æè½æºç¢ºæåºèä¸è«ææ¬ä½æ¯å¦å« NULL å¼ï¼
610 ç¨ IS NULL å IS NOT NULL 測試éåæ¬ä½ï¼å·é«æ¹æ³å¦ä¸ï¼
615 çºäºè½å°å« NULL æ¬ä½æåºï¼å¯å¨ ORDER BY æ¢ä»¶ä¸ä½¿ç¨ IS NULL å IS NOT
616 NULL 修飾符ï¼æ¢ä»¶çºç true å°æ¯æ¢ä»¶çºå false æå¨åé¢ï¼ä¸é¢çä¾å
617 å°±æå°å« NULL çè¨éæå¨çµæçä¸é¢é¨åï¼
620 ORDER BY (col IS NOT NULL)
622 4.10) å種å符é¡åä¹éæä»éº¼ä¸åï¼
625 VARCHAR(n) varchar æå®äºæ大é·åº¦ï¼è®é·å
626 符串ï¼ä¸è¶³å®ç¾©é·åº¦çé¨åä¸è£é½
627 CHAR(n) bpchar å®é·å符串ï¼å¯¦éè³æä¸è¶³å®ç¾©é·åº¦æï¼ä»¥ç©ºæ ¼è£é½
628 TEXT text æ²æç¹å¥çä¸ééå¶ï¼ååè¡çæ大é·åº¦éå¶ï¼
629 BYTEA bytea è®é·åç¯åºåï¼ä½¿ç¨NULLå符ä¹æ¯å許çï¼
632 å¨ç³»çµ±è¡¨åå¨ä¸äºé¯èª¤è³è¨è£¡ä½ å°çå°å§é¨å稱ã
634 ä¸é¢æåçåå種é¡åæ¯ "varlena"ï¼è®é·ï¼é¡åï¼ä¹å°±æ¯èªªï¼éé çååå
635 ç¯æ¯é·åº¦ï¼å¾é¢ææ¯è³æï¼ã æ¼æ¯å¯¦éä½ç¨ç空éæ¯è²æç大å°è¦å¤ä¸äºã
636 ç¶èéäºé¡åå¦å®ç¾©å¾é·æé½å¯ä»¥è¢«å£ç¸®åå²ï¼å æ
637 ¤ç£ç¤ç©ºéä¹å¯è½æ¯é æ³çè¦å°ã
639 VARCHAR(n) å¨åå²éå¶äºæ大é·åº¦çè®é·å符串æ¯æ好çã TEXT é©ç¨æ¼å
640 å²æ大å¯é 1G å·¦å³ä½æªå®ç¾©éå¶é·åº¦çå符串ã
642 CHAR(n) æé©åæ¼åå²é·åº¦ç¸åçå符串ã
643 CHAR(n)ææ ¹ææ給å®çæ¬ä½é·åº¦ä»¥ç©ºæ ¼è£è¶³ï¼ä¸è¶³çæ¬ä½å§å®¹ï¼ï¼ è
644 VARCHAR(n) åªåå²æ給å®çè³æå§å®¹ã BYTEA ç¨æ¼åå²äºé²å¶è³æï¼å°¤å¶æ¯åå«
645 NULL åç¯çå¼ãéäºé¡åå·æå·®ä¸å¤çæ§è½ã
647 4.11.1) ææ樣åµå»ºä¸ååºåèææ¯èªåéå¢çæ¬ä½ï¼
649 PostgreSQL æ¯æ SERIAL
650 è³æé¡åãï¼æ¬ä½å®ç¾©çºSERIALå¾ï¼å°èªååµå»ºä¸ååºåçæå¨ï¼ä¾å¦ï¼
651 CREATE TABLE person (
656 æèªåè½æçºä»¥ä¸SQLèªå¥ï¼
657 CREATE SEQUENCE person_id_seq;
658 CREATE TABLE person (
659 id INT4 NOT NULL DEFAULT nextval('person_id_seq'),
663 åè create_sequence æåé ç²åéæ¼åºåçæå¨çæ´å¤è³è¨ã
665 4.11.2) æå¦ä½ç²å¾ä¸åæå¥çåºåèçå¼ï¼
667 ä¸ç¨®æ¹æ³æ¯å¨æå¥ä¹ååç¨å½æ¸ nextval() å¾åºåå°è±¡è£¡æª¢ç´¢åºä¸ä¸å SERIAL
668 å¼ï¼ç¶å¾åç¨æ¤å¼ç²¾ç¢ºå°æå¥ãä½¿ç¨ 4.11.1 裡çä¾è¡¨ï¼å¯ç¨å½ç¢¼é樣æè¿°ï¼
669 new_id = execute("SELECT nextval('person_id_seq')");
670 execute("INSERT INTO person (id, name) VALUES (new_id, 'Blaise Pascal')");
672 é樣éè½å¨å¶ä»æ¥è©¢ä¸ä½¿ç¨åæ¾å¨ new_id 裡çæ°å¼ï¼ä¾å¦ï¼ä½çºåç§ person
673 表çå¤éµï¼ã 注æèªååµå»ºç SEQUENCE å°è±¡çå稱å°ææ¯
674 <table>_<serialcolumn>_seqï¼ é裡 table å serialcolumn
675 åå¥æ¯ä½ ç表çå稱åä½ ç SERIAL æ¬ä½çå稱ã
677 é¡ä¼¼çï¼å¨ SERIAL å°è±¡é è¨æå¥å¾ä½ å¯ä»¥ç¨å½æ¸ currval() 檢索å賦å¼ç
679 execute("INSERT INTO person (name) VALUES ('Blaise Pascal')");
680 new_id = execute("SELECT currval('person_id_seq')");
682 4.11.3) åæä½¿ç¨ currval() æå°è´åå¶ä»ç¨æ¶çè¡çªææ³åï¼
684 ä¸æãcurrval() è¿åçæ¯ä½ æ¬æ¬¡æ話é²ç¨æ賦çå¼èä¸æ¯ææç¨æ¶çç¶åå¼ã
686 4.11.4) çºä»éº¼ä¸å¨äºåç°å¸¸ä¸æ¢å¾éç¨åºåèå¢ï¼çºä»éº¼å¨åºåèæ¬ä½çåå¼ä¸åå¨éæ·å¢ï¼
688 çºäºæé«ä½µç¼æ§ï¼åºåèå¨éè¦çæå賦äºæ
689 £å¨éè¡çäºåï¼ä¸¦ä¸å¨äºåçµæä¹åä¸é²è¡éå®ï¼ éå°±æå°è´ç°å¸¸ä¸
690 æ¢çäºåå¾ï¼åºåèæåºç¾ééã
692 4.12) ä»éº¼æ¯ OID ï¼ä»éº¼æ¯ CTID ï¼
694 PostgreSQL 裡åµå»ºçæ¯ä¸è¡è¨éé½æç²å¾ä¸åå¯ä¸ç OIDï¼é¤éå¨åµå»ºè¡¨æ使ç¨
695 WITHOUT OIDS é¸é ã OID åµå»ºææèªåçæä¸å 4ä½åçµçæ´æ¸ï¼ææ OID å¨ç¸æ
696 PostgreSQL 伺æå¨ä¸åæ¯å¯ä¸çã ç¶èï¼å®å¨è¶é 40åæå°æº¢åºï¼ OID æ
697 ¤å¾æåºç¾éè¤ãPostgreSQL å¨å®çå§é¨ç³»çµ±è¡¨è£¡ä½¿ç¨ OID
700 å¨ç¨æ¶çè³æ表ä¸ï¼æ好æ¯ä½¿ç¨ SERIAl ä¾ä»£æ¿ OID å çº SERIAL åªè¦ä¿è
701 å¨å®å表ä¸çæ¸å¼æ¯å¯ä¸çå°±å¯ä»¥äºï¼é樣å®æº¢åºçå¯è½æ§å°±é常å°äºï¼
702 SERIAL8 å¯ç¨ä¾ä¿å8ååçµçåºåæ¸å¼ã
704 CTID ç¨æ¼æ¨è帶èè³æå¡ï¼å°åï¼åï¼å¡å§ï¼å移çç¹å®çç©çè¡ã CTID
705 å¨è¨é被æ´æ¹æéè¼å¾ç¼çæ¹è®ãç´¢å¼è³æ使ç¨å®åæåç©çè¡ã
707 4.13) çºä»éº¼ææ¶å°é¯èª¤è³è¨ãERROR: Memory exhausted in AllocSetAlloc()ãï¼
709 éå¾å¯è½æ¯ç³»çµ±çèæ¬å§åç¨åäºï¼æèå§æ ¸å°æäºè³æºæè¼ä½çéå¶å¼ãå¨åå
710 postmaster ä¹å試試ä¸é¢çå½ä»¤ï¼
715 shellï¼ä¸é¢å½ä»¤åªæä¸æ¢è½æåï¼ä½æ¯å®å°æä½ çé²ç¨è³æ段éå¶è¨å¾æ¯è¼é«ï¼
716 å èä¹è¨±è½è®æ¥è©¢å®æãéæ¢å½ä»¤æç¨æ¼ç¶åé²ç¨ï¼ä»¥åææå¨éæ¢å½ä»¤éè¡å¾åµå»ºç
718 å¦æä½ æ¯å¨éè¡SQL客æ¶ç«¯æå çºå¾å°è¿åäºå¤ªå¤çè³æèåºç¾åé¡ï¼è«å¨éè¡å®¢æ¶ç
721 4.14) æå¦ä½æè½ç¥éæéè¡çPostgreSQLççæ¬ï¼
723 å¾ psql 裡ï¼è¼¸å¥ SELECT version();æ令ã
725 4.15) æå¦ä½åµå»ºä¸åé è¨å¼æ¯ç¶åæéçæ¬ä½ï¼
727 ä½¿ç¨ CURRENT_TIMESTAMPï¼
728 CREATE TABLE test (x int, modtime TIMESTAMP DEFAULT CURRENT_TIMESTAMP );
730 4.16) ææ樣é²è¡ outer join ï¼å¤é£æ¥ï¼ï¼
732 PostgreSQL æ¡ç¨æ¨æºç SQL èªæ³æ¯æå¤é£æ¥ãé裡æ¯å©åä¾åï¼
734 FROM t1 LEFT OUTER JOIN t2 ON (t1.col = t2.col);
738 FROM t1 LEFT OUTER JOIN t2 USING (col);
740 éå©åçå¹çæ¥è©¢å¨ t1.col å t2.col ä¸åé£æ¥ï¼ä¸¦ä¸è¿å t1 ä¸
741 æææªé£æ¥çè¡ï¼é£äºå¨ t2 ä¸æ²æå¹éçè¡ï¼ã å³[å¤]é£æ¥ï¼RIGHT OUTER
742 JOINï¼å°è¿å t2 ä¸æªé£æ¥çè¡ã å®å¨å¤é£æ¥ï¼FULL OUTER JOINï¼å°è¿å t1 å t2
743 ä¸æªé£æ¥çè¡ã ééµå OUTER å¨å·¦[å¤]é£æ¥ãå³[å¤]é£æ¥åå®å¨[å¤]é£æ¥ä¸
744 æ¯å¯é¸çï¼æ®éé£æ¥è¢«ç¨±çºå§é£æ¥ï¼INNER JOINï¼ã
746 4.17) å¦ä½ä½¿ç¨æ¶åå¤åè³æ庫çæ¥è©¢ï¼
748 æ²æ辦æ³æ¥è©¢ç¶åè³æ庫ä¹å¤çè³æ庫ã
749 å çºPostgreSQLè¦å è¼èè³æ庫ç¸éç系統ç®éï¼ç³»çµ±è¡¨ï¼ï¼å æ
750 ¤è·¨è³æ庫çæ¥è©¢å¦ä½å·è¡æ¯ä¸å®çã
752 éå å¢å¼æ¨¡å¡ contrib/dblink
753 å許æ¡ç¨å½æ¸èª¿ç¨å¯¦ç¾è·¨åº«æ¥è©¢ãç¶ç¶ç¨æ¶ä¹å¯ä»¥åæé£æ¥å°ä¸åçè³æ庫å·è
754 ¡æ¥è©¢ç¶å¾å¨å®¢æ¶ç«¯åä½µçµæã
756 4.18) å¦ä½è®å½æ¸è¿åå¤è¡æå¤åè³æï¼
758 å¨å½æ¸ä¸è¿åè³æè¨ééçåè½æ¯å¾å®¹æ使ç¨çï¼è©³æåè¦ï¼
759 http://techdocs.postgresql.org/guides/SetReturningFunctions
761 4.19) çºä»éº¼æå¨ä½¿ç¨ PL/PgSQL å½æ¸ååè¨æ表æææ¶å°é¯èª¤è³è¨ãrelation with OID
762 ##### does not existãï¼
764 PL/PgSQL æç·©åå½æ¸çè³æ¬å§å®¹ï¼ç±æ¤å¸¶ä¾çä¸åä¸å¥½çå¯ä½ç¨æ¯è¥ä¸å
766 å½æ¸è¨ªåäºä¸åè¨æ表ï¼ç¶å¾è©²è¡¨è¢«åªé¤ä¸¦é建äºï¼åå次調ç¨è©²å½æ¸å°å¤
767 ±æï¼ å çºç·©åçå½æ¸å§å®¹ä»ç¶æåèçè¨æ表ã解決çæ¹æ³æ¯å¨ PL/PgSQL ä¸
768 ç¨EXECUTE å°è¨æ表é²è¡è¨ªåãé樣æä¿èæ¥è©¢å¨å·è¡å總æ被éæ°è§£æã
770 4.20) ç®åæåªäºè³æè¤å¯«(replication)æ¹æ¡å¯ç¨ï¼
772 ãè¤å¯«ãåªæ¯ä¸åè¡èªï¼æ好幾種è¤å¯«æè¡å¯ç¨ï¼æ¯ç¨®é½æåªé»å缺é»ï¼
774 主/å¾å¼è¤å¯«æ¹å¼æ¯å許ä¸å主伺æå¨æ¥åè®/寫çç³è«ï¼èå¤åå¾ä¼ºæå¨åªè½æ¥å
775 è®/SELECTæ¥è©¢çç³è«ï¼ ç®åææµè¡ä¸åè²»ç主/å¾PostgreSQLè¤å¯«æ¹æ¡æ¯
778 å¤å主伺æå¨çè¤å¯«æ¹å¼å許å°è®/寫çç³è«ç¼é給å¤å°ç主æ©ï¼é種æ¹å¼ç±æ¼é
779 è¦å¨å¤å°ä¼ºæå¨ä¹éåæ¥è³æè®å å¯è½æ帶ä¾è¼å´éçæ§è½æ失ï¼Pgcluster
780 æ¯ç®åé種æ¹æ¡ä¸æ好çï¼ä¸¦ä¸éå¯ä»¥åè²»ä¸è¼ã
782 ä¹æä¸äºåæ¥éä»è²»ååºæ¼ç¡¬é«çè³æè¤å¯«æ¹æ¡ï¼æ¯æä¸è¿°å種è¤å¯«æ¨¡åã
784 4.21) çºä½æ¥è©¢çµæ顯示ç表åææ¬åèæçæ¥è©¢èªå¥ä¸çä¸åï¼çºä½å¤§å¯«çæä¸è½ä¿çï¼
786 æ常è¦çåå æ¯å¨åµå»ºè¡¨æå°è¡¨åææ¯æ¬å使ç¨äºéå¼è( ' '
787 )ï¼ç¶ä½¿ç¨äºéå¼èå¾ï¼è¡¨åææ¬åï¼ç¨±çºæ¨è符ï¼åå²ææ¯åå 大å°å¯«çï¼
788 éæè¬èä½ å¨æ¥è©¢æ表åææ¬åä¹æ使ç¨éå¼èï¼ä¸äºå·¥å·è»é«ï¼å pgAdmin
789 æå¨ç¼åºåµå»ºè¡¨çæ令æèªåå°å¨æ¯åæ¨è符ä¸å éå¼èã å æ¤ï¼çºäºæ¨è
791 * å¨åµå»ºè¡¨æé¿åå°æ¨è符使ç¨éå¼èå¼èµ·ä¾ã
792 * å¨æ¨è符ä¸åªä½¿ç¨å°å¯«åæ¯ã
793 * ï¼çºäºèå·²åå¨çæ¨è符ç¸åï¼å¨æ¥è©¢ä¸ä½¿ç¨éå¼èå°æ¨è符å¼èµ·ä¾ã