PostgreSQL ³£¼ûÎÊÌ⣨FAQ£© ×î½ü¸üУº2005 Äê 06 Ô 02 ÈÕ ÐÇÆÚÎå 22:27:35 CST Ŀǰά»¤ÈËÔ±£ºBruce Momjian (pgman@candle.pha.pa.us) ÖÐÎÄ°æά»¤ÈËÔ±£ºdoudou586 £¨doudou586_2005@yahoo.com.cn£© ±¾ÎĵµµÄ×îа汾¿ÉÒÔÔÚ http://www.postgresql.org/files/documentation/faqs/FAQ.html²é¿´¡£ Óë²Ù×÷ϵͳƽ̨Ïà¹ØµÄÎÊÌâÔÚhttp://www.postgresql.org/docs/faq/Àï»Ø´ð¡£ _________________________________________________________________ ³£¼ûÎÊÌâ 1.1)PostgreSQL ÊÇʲô£¿¸ÃÔõô·¢Òô£¿ 1.2)PostgreSQL µÄ°æȨÊÇʲô£¿ 1.3)PostgreSQL ¿ÉÒÔÔËÐÐÔÚÄÄЩ²Ù×÷ϵͳƽ̨ÉÏ£¿ 1.4)ÎÒ´ÓÄÄÀïÄܵõ½ PostgreSQL£¿ 1.5)ÎÒ´ÓÄÄÀïÄܵõ½¶Ô PostgreSQL µÄÖ§³Ö£¿ 1.6)ÎÒÈçºÎÌá½»Ò»¸öBUG±¨¸æ£¿ 1.7)×îаæµÄPostgreSQL ÊÇʲô£¿ 1.8)Äܹ»»ñÈ¡µÄ×îÐÂÎĵµÓÐÄÄЩ£¿ 1.9)ÎÒÈçºÎÁ˽âÒÑÖªµÄ BUG »òÔÝȱµÄ¹¦ÄÜ£¿ 1.10)ÎÒÓ¦¸ÃÔõÑùѧϰ SQL £¿ 1.11)ÎÒÓ¦¸ÃÔõÑù¼ÓÈ뿪·¢¶ÓÎ飿 1.12)PostgreSQL ºÍÆäËûÊý¾Ý¿âϵͳ±ÈÆðÀ´ÈçºÎ£¿ 1.13)Ë¿ØÖƺ͹ÜÀíPostgreSQL £¿ Óû§¿Í»§¶ËÎÊÌâ 2.1)ÎÒÃÇ¿ÉÒÔÓÃʲôÓïÑÔºÍ PostgreSQL ´ò½»µÀ£¿ 2.2)ÓÐʲô¹¤¾ß¿ÉÒÔ°Ñ PostgreSQL ÓÃÓÚ Web Ò³Ã棿 2.3)PostgreSQL ÓµÓÐͼÐÎÓû§½çÃæÂ𣿠ϵͳ¹ÜÀíÎÊÌâ 3.1)ÎÒÔõÑù²ÅÄÜ°Ñ PostgreSQL ×°ÔÚ /usr/local/pgsql ÒÔÍâµÄµØ·½£¿ 3.2)ÎÒÈçºÎ¿ØÖÆÀ´×ÔÆäËûÖ÷»úµÄÁ¬½Ó£¿ 3.3)ÎÒÔõÑùµ÷ÕûÊý¾Ý¿âÒýÇæÒÔ»ñµÃ¸üºÃµÄÐÔÄÜ£¿ 3.4)PostgreSQL Àï¿ÉÒÔ»ñµÃʲôÑùµÄµ÷ÊÔÌØÐÔ£¿ 3.5)ΪʲôÔÚÊÔͼÁ¬½ÓµÇ¼ʱÊÕµ½¡°Sorry, too many clients¡± ÏûÏ¢£¿ 3.6)ΪʲôҪÔÚÉý¼¶ PostgreSQL Ö÷Òª·¢²¼°æ±¾Ê±×ö dump ºÍ restore £¿ 3.7)(ʹÓÃPostgreSQL)ÎÒÐèҪʹÓÃʲô¼ÆËã»úÓ²¼þ £¿ ²Ù×÷ÎÊÌâ 4.1)ÈçºÎֻѡÔñÒ»¸ö²éѯ½á¹ûµÄÍ·¼¸ÐУ¿»òÊÇËæ»úµÄÒ»ÐУ¿ 4.2)ÈçºÎ²é¿´±í¡¢Ë÷Òý¡¢Êý¾Ý¿âÒÔ¼°Óû§µÄ¶¨Ò壿ÈçºÎ²é¿´psqlÀïÓõ½µÄ²éѯָ Áî²¢ÏÔʾËüÃÇ£¿ 4.3)ÈçºÎ¸ü¸ÄÒ»¸ö×ֶεÄÊý¾ÝÀàÐÍ£¿ 4.4)Ò»ÐмǼ£¬Ò»¸ö±í£¬Ò»¸ö¿âµÄ×î´ó³ß´çÊǶàÉÙ£¿ 4.5)´æ´¢Ò»¸öµäÐ͵ÄÎı¾ÎļþÀïµÄÊý¾ÝÐèÒª¶àÉÙ´ÅÅ̿ռ䣿 4.6)ΪʲôÎҵIJéѯºÜÂý£¿ÎªÊ²Ã´ÕâЩ²éѯûÓÐÀûÓÃË÷Òý£¿ 4.7)ÎÒÈçºÎ²ÅÄÜ¿´µ½²éѯÓÅ»¯Æ÷ÊÇÔõÑùÆÀ¹À´¦ÀíÎҵIJéѯµÄ£¿ 4.8)ÎÒÔõÑù×öÕýÔò±í´ïʽËÑË÷ºÍ´óСдÎ޹صÄÕýÔò±í´ïʽ²éÕÒ£¿ÔõÑùÀûÓÃË÷Òý½ø ÐдóСдÎ޹زéÕÒ£¿ 4.9)ÔÚÒ»¸ö²éѯÀÎÒÔõÑù¼ì²âÒ»¸ö×Ö¶ÎÊÇ·ñΪ NULL£¿ÎÒÈçºÎ²ÅÄÜ׼ȷÅÅÐò¶ø²»ÂÛij×Ö¶ÎÊÇ·ñº¬NULLÖµ£¿ 4.10)¸÷ÖÖ×Ö·ûÀàÐÍÖ®¼äÓÐʲô²»Í¬£¿ 4.11.1)ÎÒÔõÑù´´½¨Ò»¸öÐòÁкÅ/×Ô¶¯µÝÔöµÄ×ֶΣ¿ 4.11.2)ÎÒÈçºÎ»ñµÃÒ»¸ö²åÈëµÄÐòÁкŵÄÖµ£¿ 4.11.3)ʹÓà currval() »áµ¼ÖºÍÆäËûÓû§µÄÎÉÂÒÇé¿ö£¨race condition£©Â𣿠4.11.4)Ϊʲô²»ÔÚÊÂÎñÒì³£ÖÐÖ¹ºóÖØÓÃÐòÁкÅÄØ£¿ÎªÊ²Ã´ÔÚÐòÁкÅ×ֶεÄÈ¡ÖµÖ Ð´æÔÚ¼ä¶ÏÄØ£¿ 4.12)ʲôÊÇ OID£¿Ê²Ã´ÊÇ CTID £¿ 4.13)ΪʲôÎÒÊÕµ½´íÎóÐÅÏ¢¡°ERROR: Memory exhausted in AllocSetAlloc()¡±£¿ 4.14)ÎÒÈçºÎ²ÅÄÜÖªµÀËùÔËÐÐµÄ PostgreSQL µÄ°æ±¾£¿ 4.15)ÎÒÈçºÎ´´½¨Ò»¸öȱʡֵÊǵ±Ç°Ê±¼äµÄ×ֶΣ¿ 4.16)ÈçºÎ½øÐÐ outer join £¨ÍâÁ¬½Ó£©£¿ 4.17)ÈçºÎʹÓÃÉæ¼°¶à¸öÊý¾Ý¿âµÄ²éѯ£¿ 4.18)ÈçºÎÈú¯Êý·µ»Ø¶àÐлò¶àÁУ¿ 4.19)ΪʲôÎÒÔÚʹÓÃPL/PgSQLº¯Êý´æÈ¡ÁÙʱ±íʱ»áÊÕµ½´íÎóÐÅÏ¢¡°relation with OID ##### does not exist¡±£¿ 4.20)Ä¿Ç°ÓÐÄÄЩÊý¾Ý¸´ÖÆ·½°¸¿ÉÓã¿ _________________________________________________________________ ³£¼ûÎÊÌâ 1.1)PostgreSQL ÊÇʲô£¿¸ÃÔõô·¢Òô£¿ PostgreSQL ¶Á×÷ Post-Gres-Q-L£¬ÓÐʱºòÒ²¼ò³ÆΪPostgres ¡£ PostgreSQL ÊÇÃæÏòÄ¿±êµÄ¹ØϵÊý¾Ý¿âϵͳ£¬Ëü¾ßÓд«Í³ÉÌÒµÊý¾Ý¿âϵͳµÄËùÓй¦ÄÜ£¬Í¬Ê±ÓÖ º¬Óн«ÔÚÏÂÒ»´ú DBMS ϵͳµÄʹÓõÄÔöÇ¿ÌØÐÔ¡£ PostgreSQL ÊÇ×ÔÓÉÃâ·ÑµÄ£¬²¢ÇÒËùÓÐÔ´´úÂ붼¿ÉÒÔ»ñµÃ¡£ PostgreSQL µÄ¿ª·¢¶ÓÎéÖ÷ҪΪ־ԸÕߣ¬ËûÃDZ鲼ÊÀ½ç¸÷µØ²¢Í¨¹ý»¥ÁªÍø½øÐÐÁªÏµ£¬ÕâÊÇÒ»¸ö ÉçÇø¿ª·¢ÏîÄ¿£¬Ëü²»±»Èκι«Ë¾¿ØÖÆ¡£ ÈçÏë¼ÓÈ뿪·¢¶ÓÎ飬Çë²Î¼û¿ª·¢ÈËÔ±³£¼ûÎÊÌ⣨FAQ£© http://www.postgresql.org/files/documentation/faqs/FAQ_DEV.html 1.2)PostgreSQL µÄ°æȨÊÇʲô? PostgreSQLµÄ·¢²¼×ñ´Ó¾ µäµÄBSD°æȨ¡£¹ØÓÚÔ´´úÂëµÄÈçºÎʹÓÃûÓÐÈκÎÏÞÖÆ£¬ÎÒÃǺÜϲ»¶ÕâÖÖ·½Ê½²¢ÇÒ» ¹Ã»ÓдòËã¸Ä±äËü¡£ ÏÂÃæ¾ÍÊÇÎÒÃÇʹÓõÄBSD°æȨÄÚÈÝ£º ²¿·Ö°æȨ£¨c£©1996-2005£¬PostgreSQL È«Çò¿ª·¢Ð¡×飬²¿·Ö°æȨ£¨c£©1994-1996 ¼ÓÖÝ´óѧ¶Ê £¨Portions copyright (c) 1996-2005, PostgreSQL Global Development Group Portions Copyright (c) 1994-6 Regents of the University of California£© ÔÊÐíΪÈκÎÄ¿µÄʹÓ㬿½±´£¬Ð޸ĺͷַ¢Õâ¸öÈí¼þºÍËüµÄÎĵµ¶ø²»ÊÕÈ¡ÈκηÑÓà £¬ ²¢ÇÒÎÞÐëÇ©ÊðÒò´Ë¶ø²úÉúµÄÖ¤Ã÷£¬Ç°ÌáÊÇÉÏÃæµÄ°æȨÉùÃ÷ºÍ±¾¶ÎÒÔ¼°ÏÂÃæÁ½¶ÎÎÄ ×Ö³öÏÖÔÚËùÓп½±´ÖС£ £¨Permission to use, copy, modify, and distribute this software and its documentation for any purpose, without fee, and without a written agreement is hereby granted, provided that the above copyright notice and this paragraph and the following two paragraphs appear in all copies.£© ÔÚÈκÎÇé¿öÏ£¬¼ÓÖÝ´óѧ¶¼²»³Ðµ£ÒòʹÓôËÈí¼þ¼°ÆäÎĵµ¶øµ¼ÖµĶÔÈκε±ÊÂÈË µÄÖ±½ÓµÄ£¬ ¼ä½ÓµÄ£¬ÌØÊâµÄ£¬¸½¼ÓµÄ»òÕßÏà°é¶øÉúµÄË𻵣¬°üÀ¨ÀûÒæËðʧµÄÔðÈΣ¬¼´Ê¹¼ÓÖÝ ´óѧÒѾ½¨ÒéÁËÕâЩËðʧµÄ¿ÉÄÜÐÔʱҲÊÇÈç´Ë¡£ £¨IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.£© ¼ÓÖÝ´óѧÃ÷È··ÅÆúÈκα£Ö¤£¬°üÀ¨µ«²»¾ÖÏÞÓÚijһÌض¨ÓÃ;µÄÉÌÒµºÍÀûÒæµÄÒþº¬ ±£Ö¤¡£ ÕâÀïÌṩµÄÕâ·ÝÈí¼þÊÇ»ùÓÚ¡°µ±×÷ÊÇ¡±µÄ»ù´¡µÄ£¬Òò¶ø¼ÓÖÝ´óѧûÓÐÔðÈÎÌṩά »¤£¬Ö§³Ö£¬¸üУ¬ÔöÇ¿»òÕßÐ޸ĵķþÎñ¡£ £¨THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.£© 1.3)PostgreSQL ¿ÉÒÔÔËÐÐÔÚÄÄЩ²Ù×÷ϵͳƽ̨ÉÏ£¿ Ò»°ã˵À´£¬Ò»¸öÏÖ´úµÄ UNIX ¼æÈݵÄƽ̨¶¼ÄÜÔËÐÐ PostgreSQL ¡£ÔÚ°²×°Ö¸ÄÏÀïÁгöÁË·¢²¼Ê±¾¹ýÃ÷È·²âÊÔµÄƽ̨¡£ PostgreSQlÒ²¿ÉÒÔÖ±½ÓÔËÐÐÔÚ»ùÓÚ΢ÈíWindows-NTµÄ²Ù×÷ϵͳ£¬ÈçWin2000£¬Win XP ºÍ Win2003£¬ÒÑÖÆ×÷Íê³ÉµÄ°²×°°ü¿É´Ó http://pgfoundry.org/projects/pginstallerÏÂÔØ£¬»ùÓÚMSDOSµÄWindows²Ù×÷Ï µÍ³ £¨Win95£¬Win98£¬WinMe£©ÐèҪͨ¹ýCygwinÄ£Äâ»·¾³ÔËÐÐPostgreSQL¡£ ͬʱҲÓÐÒ»¸öΪNovell Netware 6¿ª·¢µÄ°æ±¾¿É´Ó http://forge.novell.com »ñÈ¡£¬ÎªOS/2¿ª·¢µÄ°æ±¾¿É´Ó http://hobbes.nmsu.edu/cgi-bin/h-search?sh=1&button=Search&key=postgre SQL&stype=all&sort=type&dir=%2F 1.4)ÎÒ´ÓÄÄÀïÄܵõ½ PostgreSQL£¿ ͨ¹ýä¯ÀÀÆ÷¿É´Óhttp://www.postgresql.org/ftp/ÏÂÔØ£¬Ò²¿Éͨ¹ýFTP£¬´Ó ftp://ftp.PostgreSQL.org/pub/Õ¾µãÏÂÔØ¡£ 1.5)ÎÒ´ÓÄÄÀïÄܵõ½¶Ô PostgreSQL µÄÖ§³Ö£¿ PostgreSQLÉçÇøͨ¹ýÓʼþÁбíΪÆä´ó¶àÊýÓû§Ìṩ°ïÖú£¬¼ÓÈëÓʼþÁбíµÄÖ÷Õ¾µã ÊÇ http://www.postgresql.org/community/lists/£¬Ò»°ãÇé¿öÏ£¬ÏȼÓÈëGeneral »ò BugÓʼþÁбíÊÇÒ»¸ö½ÏºÃµÄ¿ªÊ¼¡£ Ö÷ÒªµÄIRCƵµÀÊÇÔÚFreeNode(irc.freenode.net)µÄ#postgresql£¬ÎªÁËÁ¬ÉÏ´ËƵ µÀ£¬¿ÉÒÔʹÓÃUNIX³ÌÐòirc£¬ÆäÖ¸Áî¸ñʽ£º irc -c '#postgresql' "$USER" irc.freenode.net £¬»òÕßʹÓÃÆäËûIRC¿Í»§¶Ë³ÌÐò¡£ÔÚ´ËÍøÂçÖл¹´æÔÚÒ»¸öPostgreSQLµÄÎ÷°àÑÀƵµ À(#postgersql-es)ºÍ·¨ÓïƵµÀ (#postgresql-fr)¡£Í¬ÑùµØ£¬ÔÚEFNETÉÏÒ²ÓÐÒ»¸öPostgreSQLµÄ½»Á÷ƵµÀ¡£ ÉÌÒµÖ§³Ö¹«Ë¾µÄÁбíÔÚ http://techdocs.postgresql.org/companies.php¡£ 1.6)ÎÒÈçºÎÌá½»Ò»¸öBUG±¨¸æ£¿ ¿É·ÃÎÊ http://www.postgresql.org/support/submitbug£¬ÌîдBugÉϱ¨±í¸ñ¼´¿É¡£ ͬÑùÒ²¿É·ÃÎÊftpÕ¾µãftp://ftp.PostgreSQL.org/pub/ ¼ì²éÓÐÎÞ¸üеÄPostgreSQL°æ±¾»ò²¹¶¡¡£ 1.7)×îаæµÄPostgreSQL ÊÇʲô£¿ PostgreSQL ×îеİ汾ÊÇ°æ±¾ 8.0.2 £¨Òë×¢£ºÏÖ×îа汾Ϊ8.0.3£©¡£ ÎÒÃǼƻ®Ã¿Äê·¢²¼Ò»¸öÖ÷Òª°æ±¾£¬Ã¿¼¸¸öÔ·¢²¼Ò»¸öС°æ±¾¡£ 1.8)Äܹ»»ñÈ¡µÄ×îÐÂÎĵµÓÐÄÄЩ£¿ PostgreSQL°üº¬´óÁ¿µÄÎĵµ£¬Ö÷ÒªÓÐһЩÊֲᣬÊÖ²áÒ³ºÍһЩµÄ²âÊÔÀý×Ó¡£²Î¼û /doc Ŀ¼£¨Òë×¢£ºÓ¦Îª $PGHOME/doc£©¡£ Ä㻹¿ÉÒÔÔÚÏßä¯ÀÀ PostgreSQL µÄÊֲᣬÆäµØÖ·ÊÇ£ºhttp://www.PostgreSQL.org/docs¡£ ÓÐÁ½±¾¹ØÓÚ PostgreSQL µÄÊéÔÚÏßÌṩ£¬ÔÚ http://www.PostgreSQL.org/docs/awbook.html ºÍ http://www.commandprompt.com/ppbook/ ¡£ Ò²ÓдóÁ¿µÄPostgreSQLÊé¼®¿É¹©¹ºÂò£¬ÆäÖÐ×îΪÁ÷ÐеÄÒ»±¾ÊÇÓÉKorry Douglas±àдµÄ¡£ÔÚ http://techdocs.PostgreSQL.org/techdocs/bookreviews.phpÉÏ ÉÏÓдóÁ¿ÓйØPostgreSQLÊé¼®µÄ¼ò½é¡£ ÔÚ http://techdocs.PostgreSQL.org/ÉÏÊÕ¼¯ÁËÓÐ¹Ø PostgreSQL µÄ´óÁ¿¼¼ÊõÎÄÕ¡£ ¿Í»§¶ËµÄÃüÁîÐгÌÐòpsqlÓÐһЩÒÔ \d ¿ªÍ·µÄÃüÁ¿ÉÏÔʾ¹ØÓÚÀàÐÍ£¬²Ù×÷·û£¬º¯Êý£¬»ã×ܵȵÄÐÅÏ¢£¬Ê¹Óà \? ¿ÉÒÔÏÔʾËùÓпÉÓõÄÃüÁî¡£ ÎÒÃÇµÄ web Õ¾µã°üº¬¸ü¶àµÄÎĵµ¡£ 1.9)ÎÒÈçºÎÁ˽âÒÑÖªµÄ BUG »òÔÝȱµÄ¹¦ÄÜ£¿ PostgreSQL Ö§³ÖÒ»¸öÀ©Õ¹Á赀 SQL-92 µÄ×Ó¼¯¡£²ÎÔÄÎÒÃǵÄTODO ÁÐ±í£¬»ñÈ¡Ò»¸öÒÑÖªBug£¬ÔÝȱµÄ¹¦Äܺͽ«À´µÄ¼Æ»®¡£ 1.10)ÎÒÓ¦¸ÃÔõÑùѧϰ SQL £¿ Ê×ÏÈ¿¼ÂÇÉÏÊöÌáµ½µÄÓëPostgreSQLÏà¹ØµÄÊé¼®£¬ÁíÍâÒ»±¾ÊÇTeach Yourself SQL in 21 Days, Second Edition£¬ ÎÒÃǵÄÐí¶àÓû§Ï²»¶The Practical SQL Handbook Bowman, Judith S., et al., Addison-Wesley£¬ÆäËûµÄÔòϲ»¶ The Complete Reference SQL, Groff et al., McGraw-Hill¡£ 1.11)ÎÒÓ¦¸ÃÔõÑù¼ÓÈ뿪·¢¶ÓÎ飿 Ïê¼û Developer's FAQ ¡£ 1.12)PostgreSQL ºÍÆäËûÊý¾Ý¿âϵͳ±ÈÆðÀ´ÈçºÎ£¿ ÆÀ¼ÛÈí¼þÓкü¸ÖÖ·½·¨£ºÌØÐÔ£¬ÐÔÄÜ£¬¿É¿¿ÐÔ£¬Ö§³ÖºÍ¼Û¸ñ¡£ ÌØÐÔ PostgreSQL ÓµÓдóÐÍÉÌÓà DBMS Àï´ó¶àÊýÌØÐÔ£¬ ÀýÈ磺ÊÂÎñ£¬×Ó²éѯ£¬´¥·¢Æ÷£¬ÊÓͼ£¬Íâ¼ü²Î¿¼ÍêÕûÐԺ͸´ÔÓµÄËøµÈ¡£ ÎÒÃÇ»¹ÓÐһЩËüÃÇûÓеÄÌØÐÔ£¬ÈçÓû§¶¨ÒåÀàÐÍ£¬¼Ì³Ð£¬¹æÔòºÍ¶à°æ±¾² ¢ÐпØÖÆÒÔ¼õÉÙËøµÄÕùÓõȡ£ ÐÔÄÜ PostgreSQL ºÍÆäËûÉÌÓúͿªÔ´µÄÊý¾Ý¿â¾ßÓÐÀàËƵÄÐÔÄÜ¡£ ¶ÔijЩ´¦ÀíËü±È½Ï¿ì£¬¶ÔÆäËûһЩ´¦ÀíËü±È½ÏÂý¡£ ÓëÆäËûÊý¾Ý¿âÏà±È£¬ÎÒÃǵÄÐÔÄÜͨ³£ÔÚ +/- 10%Ö®¼ä¡£ ¿É¿¿ÐÔ ÎÒÃÇÖªµÀ DBMS ±ØÐëÊÇ¿É¿¿µÄ£¬·ñÔòËü¾ÍÒ»µãÓö¼Ã»ÓС£ ÎÒÃÇŬÁ¦×öµ½·¢²¼¾ ¹ýÈÏÕæ²âÊԵģ¬Îȶ¨µÄ³ô³æ×îÉٵĴúÂ롣ÿ¸ö°æ±¾ÖÁÉÙÓÐÒ»¸öÔ嵀 beta ²âÊÔʱ¼ä£¬²¢ÇÒÎÒÃǵķ¢²¼ÀúÊ·ÏÔʾÎÒÃÇ¿ÉÒÔÌṩÎȶ¨µÄ£¬Àι̵ģ¬¿ÉÓ ÃÓÚÉú²úʹÓõİ汾¡£ÎÒÃÇÏàÐÅ ÔÚÕâ·½ÃæÎÒÃÇÓëÆäËûµÄÊý¾Ý¿âÈí¼þÊÇÏ൱µÄ¡£ Ö§³Ö ÎÒÃǵÄÓʼþÁбíÌṩһ¸ö·Ç³£´óµÄ¿ª·¢ÈËÔ±ºÍÓû§µÄ×éÒÔ°ïÖú½â¾öËùÅöµ ½µÄÈκÎÎÊÌâ¡£ ÎÒÃDz»Äܱ£Ö¤¿Ï¶¨Äܽâ¾öÎÊÌ⣬Ïà±È֮ϣ¬ÉÌÓà DBMS Ò²²¢²»ÊÇ×ÜÄܹ»Ìṩ½â¾ö·½·¨¡£ Ö±½ÓÓ뿪·¢ÈËÔ±£¬Óû§Èº£¬ÊÖ²áºÍÔ´³ÌÐò½Ó´¥Áî PostgreSQL µÄÖ§³Ö±ÈÆäËû DBMS »¹ÒªºÃ¡£»¹ÓÐһЩÉÌÒµÐÔµÄÔ¤°ü×°µÄÖ§³Ö£¬¿ÉÒÔ¸øÌṩ¸øÄÇЩÐèÒªµÄÈË¡ ££¨²ÎÔÄ FAQ Ìõ¿î 1.5 С½Ú£© ¼Û¸ñ ÎÒÃǶÔÈκÎÓÃ;¶¼Ãâ·Ñ£¬°üÀ¨ÉÌÓúͷÇÉÌÓÃÄ¿µÄ¡£ Äã¿ÉÒÔ²»¼ÓÏÞÖƵØÏòÄãµÄ²úÆ·Àï¼ÓÈëÎÒÃǵĴúÂ룬³ýÁËÄÇЩÎÒÃÇÔÚÉÏÃæµ Ä°æȨÉùÃ÷ÀïÉùÃ÷µÄ BSD ·ç¸ñµÄ°æȨÍâ¡£ 1.13)Ë¿ØÖÆPostgreSQL £¿ Èç¹ûÄãÔÚÑ°ÕÒPostgreSQLµÄÕÆÃÅÈË£¬»òÊÇʲôÖÐÑëίԱ»á£¬»òÊÇʲôËùÊô¹«Ë¾£¬ ÄãÖ»ÄÜ·ÅÆúÁË---ÒòΪһ¸öÒ²²»´æÔÚ£¬µ«ÎÒÃǵÄÈ·ÓÐÒ»¸ö ίԱ»áºÍCVS¹ÜÀí×飬µ«ÕâЩ¹¤×÷×éµÄÉèÁ¢Ö÷ÒªÊÇΪÁ˽øÐйÜÀí¹¤×÷¶ø²»ÊǶÔPos tgreSQL½øÐпØÖÆ£¬PostgreSQLÏîÄ¿ÊÇÓÉÈκÎÈ˾ù ¿É²Î¼ÓµÄ¿ª·¢ÈËÔ±ÉçÇøºÍËùÓÐÓû§¿ØÖƵģ¬ÄãËùÐèÒª×öµÄ¾ÍÊǼÓÈëÓʼþÁÐ±í£¬²Î ÓëÌÖÂÛ¼´¿É£¨Òª²ÎÓëPostgreSQLµÄ¿ª·¢Ïê¼û Developer's FAQ »ñÈ¡ÐÅÏ¢£©¡£ _________________________________________________________________ Óû§¿Í»§¶ËÎÊÌâ 2.1)ÎÒÃÇ¿ÉÒÔÓÃʲôÓïÑÔºÍ PostgreSQL ´ò½»µÀ£¿ PostgreSQL(ȱʡÇé¿ö)Ö»°²×°ÓÐCºÍÄÚǶʽCµÄ½Ó¿Ú£¬ÆäËûµÄ½Ó¿Ú¶¼ÊǶÀÁ¢µÄÏîÄ¿ £¬Äܹ»·Ö±ðÏÂÔØ£¬ÕâЩ½Ó¿ÚÏîÄ¿¶ÀÁ¢µÄºÃ´¦ ÊÇËûÃÇ¿ÉÒÔÓи÷×Եķ¢²¼¼Æ»®ºÍ¸÷×Ô¶ÀÁ¢µÄ¿ª·¢×é¡£ һЩ±à³ÌÓïÑÔÈçPHP¶¼ÓзÃÎÊ PostgreSQL µÄ½Ó¿Ú£¬Perl,TCL,PythonÒÔ¼°ºÜ¶àÆäËûÓïÑԵĽӿÚÔÚ http://gborg.postgresql.org ÉϵÄDrivers/InterfacesС½Ú¿ÉÕÒµ½£¬ ²¢ÇÒͨ¹ýInternetºÜÈÝÒ×ËÑË÷µ½¡£ 2.2)ÓÐʲô¹¤¾ß¿ÉÒÔ°Ñ PostgreSQL ÓÃÓÚ Web Ò³Ã棿 Ò»¸ö½éÉÜÒÔÊý¾Ý¿âΪºǫ́µÄͦ²»´íµÄÕ¾µãÊÇ£ºhttp://www.webreview.com¡£ ¶ÔÓÚ Web ¼¯³É£¬PHP ÊÇÒ»¸ö¼«ºÃµÄ½Ó¿Ú¡£ËüÔÚ£ºhttp://www.php.net/¡£ ¶ÔÓÚ¸´ÔÓµÄÈÎÎñ£¬ºÜ¶àÈ˲ÉÓà Perl ½Ó¿ÚºÍ CGI.pm »ò mod_perl ¡£ 2.3)PostgreSQL ÓµÓÐͼÐÎÓû§½çÃæÂ𣿠Êǵģ¬ÔÚ http://techdocs.postgresql.org/guides/GUIToolsÓÐÒ»¸öÏêϸµÄÁÐ±í¡£ _________________________________________________________________ ϵͳ¹ÜÀíÎÊÌâ 3.1)ÎÒÔõÑùÄÜ°Ñ PostgreSQL ×°ÔÚ /usr/local/pgsql ÒÔÍâµÄµØ·½£¿ ÔÚÔËÐÐ configure ʱ¼ÓÉÏ --prefix Ñ¡Ïî¡£ 3.2)ÎÒÈçºÎ¿ØÖÆÀ´×ÔÆäËûÖ÷»úµÄÁ¬½Ó£¿ ȱʡʱ£¬PostgreSQL Ö»ÔÊÐíͨ¹ý unix ÓòÌ×½Ó×Ö»òTCP/IP·½Ê½ÇÒÀ´×Ô±¾»úµÄÁ¬½Ó¡£ ÄãÖ»ÓÐÔÚÐÞ¸ÄÁËÅäÖÃÎļþpostgresql.confÖеÄlisten_addresses£¬ÇÒÒ²ÔÚÅäÖÃΠļþpg_hba.confÖдò¿ªÁË Ö÷»úΪ»ù´¡£¨ host-based £©µÄÉí·ÝÈÏÖ¤£¬²¢ÖØÐÂÆô¶¯PostgreSQL£¬·ñÔòÆäËû»úÆ÷ÊDz»ÄÜÓëÄãµÄPostgreSQL ·þÎñÆ÷Á¬½ÓµÄ¡£ 3.3)ÎÒÔõÑùµ÷ÕûÊý¾Ý¿âÒýÇæÒÔ»ñµÃ¸üºÃµÄÐÔÄÜ£¿ ÓÐÈý¸öÖ÷Òª·½Ãæ¿ÉÒÔÌáÉýPostgreSQLµÄDZÄÜ¡£ ²éѯ·½Ê½µÄ±ä»¯ ÕâÖ÷ÒªÉæ¼°Ð޸IJéѯ·½Ê½ÒÔ»ñÈ¡¸üºÃµÄÐÔÄÜ: + ´´½¨Ë÷Òý£¬°üÀ¨±í´ïʽºÍ²¿·ÖË÷Òý£» + ʹÓÃCOPYÓï¾ä´úÌæ¶à¸öInsertÓï¾ä£» + ½«¶à¸öSQLÓï¾ä×é³ÉÒ»¸öÊÂÎñÒÔ¼õÉÙÌá½»ÊÂÎñµÄ¿ªÏú£» + ´ÓÒ»¸öË÷ÒýÖÐÌáÈ¡¶àÌõ¼Ç¼ʱʹÓÃCLUSTER£» + ´ÓÒ»¸ö²éѯ½á¹ûÖÐÈ¡³ö²¿·Ö¼Ç¼ʱʹÓÃLIMIT£» + ʹÓÃÔ¤±àÒëʽ²éѯ£¨Prepared Query)£» + ʹÓÃANALYZEÒÔ±£³Ö¾«È·µÄÓÅ»¯Í³¼Æ£» + ¶¨ÆÚʹÓà VACUUM »ò pg_autovacuum + ½øÐдóÁ¿Êý¾Ý¸ü¸ÄʱÏÈɾ³ýË÷Òý£¨È»ºóÖؽ¨Ë÷Òý£© ·þÎñÆ÷µÄÅäÖà ÅäÖÃÎļþpostgres.confÖеĺܶàÉèÖö¼»áÓ°ÏìÐÔÄÜ£¬ËùÓвÎÊýµÄÁбí¿É ¼û£º Administration Guide/Server Run-time Environment/Run-time Configuration£¬ ÓйزÎÊýµÄ½âÊͿɼû£º http://www.varlena.com/varlena/GeneralBits/Tidbits/annotated_co nf_e.html ºÍ http://www.varlena.com/varlena/GeneralBits/Tidbits/perf.html¡£ Ó²¼þµÄÑ¡Ôñ ¼ÆËã»úÓ²¼þ¶ÔÐÔÄܵÄÓ°Ïì¿Éä¯ÀÀ http://candle.pha.pa.us/main/writings/pgsql/hw_performance/inde x.html ºÍ http://www.powerpostgresql.com/PerfList/¡£ 3.4)PostgreSQL Àï¿ÉÒÔ»ñµÃʲôÑùµÄµ÷ÊÔÌØÐÔ£¿ PostgreSQL ÓкܶàÀàËÆ log_* µÄ·þÎñÆ÷ÅäÖñäÁ¿¿ÉÓÃÓÚ²éѯµÄ´òÓ¡ºÍ½ø³Ìͳ¼Æ£¬¶øÕâЩ¹¤×÷¶Ôµ÷ÊÔºÍÐÔÄܲâÊÔ ºÜÓаïÖú¡£ 3.5)ΪʲôÔÚÊÔͼÁ¬½ÓʱÊÕµ½¡°Sorry, too many clients¡±ÏûÏ¢£¿ Õâ±íʾÄãÒѴﵽȱʡ100¸ö²¢·¢ºǫ́½ø³ÌÊýµÄÏÞÖÆ£¬ÄãÐèҪͨ¹ýÐÞ¸Äpostgresql. confÎļþÖеÄmax_connectionsÖµÀ´ Ôö¼ÓpostmasterµÄºǫ́²¢·¢´¦ÀíÊý£¬Ð޸ĺóÐèÖØÐÂÆô¶¯postmaster¡£ 3.6)ΪʲôҪÔÚÉý¼¶ PostgreSQL Ö÷Òª·¢²¼°æ±¾Ê±×ö dump ºÍ restore £¿ PostgreSQL ¿ª·¢×é¶Ôÿ´ÎСµÄÉý¼¶½ö×öÁ˽ÏÉÙµÄÐ޸ģ¬Òò´Ë´Ó 7.4.0 Éý¼¶µ½ 7.4.1 ²»ÐèÒª dump ºÍ restore¡£ µ«ÊÇÖ÷ÒªµÄÉý¼¶£¨ÀýÈç´Ó 7.3 µ½ 7.4£©Í¨³£»áÐÞ¸Äϵͳ±íºÍÊý¾Ý±íµÄÄÚ²¿¸ñʽ¡£ ÕâЩ±ä»¯Ò»°ã±È½Ï¸´ÔÓ£¬Òò´ËÎÒÃDz»Î¬Êý¾ÝÎļþµÄÏòºó¼æÈÝ¡£ dump ½«Êý¾Ý°´ÕÕͨÓõĸñʽÊä³ö£¬Ëæºó¿ÉÒÔ±»ÖØмÓÔز¢Ê¹ÓÃеÄÄÚ²¿¸ñʽ¡£ 3.7)(ʹÓÃPostgreSQL)ÎÒÐèҪʹÓÃʲô¼ÆËã»úÓ²¼þ £¿ ÓÉÓÚ¼ÆËã»úÓ²¼þ´ó¶àÊýÊǼæÈݵģ¬ÈËÃÇ×ÜÊÇÇãÏòÓÚÏàÐÅËùÓмÆËã»úÓ²¼þÖÊÁ¿Ò²ÊÇ ÏàͬµÄ¡£ÊÂʵÉϲ»ÊÇ£¬ ECC RAM£¨´øÆæżУÑéµÄÄڴ棩£¬SCSI £¨Ó²ÅÌ£©ºÍÓÅÖʵÄÖ÷°å±ÈһЩ±ãÒË»õÒª¸ü¼Ó¿É¿¿ÇÒ¾ßÓиüºÃµÄÐÔÄÜ¡£PostgreSQL ¼¸ºõ¿ÉÒÔÔËÐÐÔÚÈκÎÓ²¼þÉÏ£¬ µ«Èç¹û¿É¿¿ÐÔºÍÐÔÄܶÔÄãµÄϵͳºÜÖØÒª£¬Äã¾ÍÐèҪȫÃæµÄÑо¿Ò»ÏÂÄãµÄÓ²¼þÅäÖà ÁË¡£ÔÚÎÒÃǵÄÓʼþÁбíÉÏÒ²ÓйØÓÚ Ó²¼þÅäÖúÍÐԼ۱ȵÄÌÖÂÛ¡£ _________________________________________________________________ ²Ù×÷ÎÊÌâ 4.1)ÈçºÎֻѡÔñÒ»¸ö²éѯ½á¹ûµÄÍ·¼¸ÐУ¿»òÊÇËæ»úµÄÒ»ÐУ¿ Èç¹ûÄãÖ»ÊÇÒªÌáÈ¡¼¸ÐÐÊý¾Ý£¬²¢ÇÒÄãÔÚÖ´ÐвéѯÖÐÖªµÀÈ·ÇеÄÐÐÊý£¬Äã¿ÉÒÔʹÓà LIMIT¹¦ÄÜ¡£ Èç¹ûÓÐÒ»¸öË÷ÒýÓë ORDER BYÖеÄÌõ¼þÆ¥Å䣬PostgreSQL ¿ÉÄܾÍÖ»´¦ÀíÒªÇóµÄÍ·¼¸Ìõ¼Ç¼£¬ £¨·ñÔò½«¶ÔÕû¸ö²éѯ½øÐд¦ÀíÖ±µ½Éú³ÉÐèÒªµÄÐУ©¡£Èç¹ûÔÚÖ´Ðвéѯ¹¦ÄÜʱ²»Öª µÀÈ·ÇеļǼÊý£¬ ¿ÉʹÓÃÓαê(cursor)ºÍFETCH¹¦ÄÜ¡£ ¿ÉʹÓÃÒÔÏ·½·¨ÌáÈ¡Ò»ÐÐËæ»ú¼Ç¼µÄ£º SELECT cols FROM tab ORDER BY random() LIMIT 1 ; 4.2)ÈçºÎ²é¿´±í¡¢Ë÷Òý¡¢Êý¾Ý¿âÒÔ¼°Óû§µÄ¶¨Ò壿ÈçºÎ²é¿´psqlÀïÓõ½µÄ²éѯָÁî²¢Ï ÔʾËüÃÇ£¿ ÔÚpsqlÖÐʹÓà \dt ÃüÁîÀ´ÏÔʾÊý¾Ý±íµÄ¶¨Ò壬ҪÁ˽âpsqlÖеÄÍêÕûÃüÁîÁбí¿ÉʹÓÃ\? £¬ÁíÍ⣬ÄãÒ²¿ÉÒÔÔĶÁ psql µÄÔ´´úÂë Îļþpgsql/src/bin/psql/describe.c£¬Ëü°üÀ¨ÎªÉú³Épsql·´Ð±¸ÜÃüÁîµÄÊä³öµÄË ùÓÐ SQL ÃüÁî¡£Ä㻹¿ÉÒÔ´ø -E Ñ¡ÏîÆô¶¯ psql£¬ ÕâÑùËü½«´òÓ¡³öÖ´ÐÐÄãÔÚpsqlÖÐËù¸ø³öµÄÃüÁîµÄÄÚ²¿Êµ¼ÊʹÓõÄSQL²éѯ¡£Postg reSQLÒ²ÌṩÁËÒ»¸ö¼æÈÝSQLµÄINFORMATION SCHEMA½Ó¿Ú£¬ Äã¿ÉÒÔ´ÓÕâÀï»ñÈ¡¹ØÓÚÊý¾Ý¿âµÄÐÅÏ¢¡£ ÔÚϵͳÖÐÓÐһЩÒÔpg_ ´òÍ·µÄϵͳ±íÒ²ÃèÊöÁ˱íµÄ¶¨Òå¡£ ʹÓà psql -l Ö¸Áî¿ÉÒÔÁгöËùÓеÄÊý¾Ý¿â¡£ Ò²¿ÉÒÔä¯ÀÀһϠpgsql/src/tutorial/syscat.sourceÎļþ£¬ËüÁоÙÁ˺ܶà¿É´ÓÊý¾Ý¿âϵͳ±íÖлñ È¡ÐÅÏ¢µÄSELECTÓï·¨¡£ 4.3)ÈçºÎ¸ü¸ÄÒ»¸ö×ֶεÄÊý¾ÝÀàÐÍ£¿ ÔÚ8.0°æ±¾Àï¸ü¸ÄÒ»¸ö×ֶεÄÊý¾ÝÀàÐͺÜÈÝÒ×£¬¿ÉʹÓà ALTER TABLE ALTER COLUMN TYPE ¡£ ÔÚÒÔÇ°µÄ°æ±¾ÖУ¬¿ÉÒÔÕâÑù×ö£º BEGIN; ALTER TABLE tab ADD COLUMN new_col new_data_type; UPDATE tab SET new_col = CAST(old_col AS new_data_type); ALTER TABLE tab DROP COLUMN old_col; COMMIT; ÄãÈ»ºó¿ÉÒÔʹÓÃVACUUM FULL tab Ö¸ÁîÀ´Ê¹ÏµÍ³ÊÕ»ØÎÞЧÊý¾ÝËùÕ¼ÓõĿռ䡣 4.4)Ò»ÐмǼ£¬Ò»¸ö±í£¬Ò»¸ö¿âµÄ×î´ó³ß´çÊǶàÉÙ£¿ ÏÂÃæÊÇһЩÏÞÖÆ£º Ò»¸öÊý¾Ý¿â×î´ó³ß´ç£¿ ÎÞÏÞÖÆ£¨ÒÑ´æÔÚÓÐ 32TB µÄÊý¾Ý¿â£© Ò»¸ö±íµÄ×î´ó³ß´ç£¿ 32 TB Ò»ÐмǼµÄ×î´ó³ß´ç£¿ 1.6 TB Ò»¸ö×ֶεÄ×î´ó³ß´ç? 1 GB Ò»¸ö±íÀï×î´óÐÐÊý£¿ ÎÞÏÞÖÆ Ò»¸ö±íÀï×î´óÁÐÊý£¿ 250-1600 £¨ÓëÁÐÀàÐÍÓйأ© Ò»¸ö±íÀïµÄ×î´óË÷ÒýÊýÁ¿£¿ ÎÞÏÞÖÆ µ±È»£¬Êµ¼ÊÉÏûÓÐÕæÕýµÄÎÞÏÞÖÆ£¬»¹ÊÇÒªÊÜ¿ÉÓôÅÅ̿ռ䡢¿ÉÓÃÄÚ´æ/½»»»ÇøµÄÖ ÆÔ¼¡£ ÊÂʵÉÏ£¬µ±ÕâЩÊýÖµ±äµÃÒì³£µØ´óʱ£¬ÏµÍ³ÐÔÄÜÒ²»áÊܴܺóÓ°Ïì¡£ ±íµÄ×î´ó³ß´ç 32 TB ²»ÐèÒª²Ù×÷ϵͳ¶Ô´óÎļþµÄÖ§³Ö¡£´ó±íÓöà¸ö 1 GB µÄÎļþ´æ´¢£¬Òò´ËÎļþϵͳ³ß´çµÄÏÞÖÆÊDz»ÖØÒªµÄ¡£ Èç¹ûȱʡµÄ¿é´óСÔö³¤µ½ 32K £¬×î´óµÄ±í³ß´çºÍ×î´óÁÐÊý»¹¿ÉÒÔÔö¼Óµ½Ëı¶¡£ 4.5)´æ´¢Ò»¸öµäÐ͵ÄÎı¾ÎļþÀïµÄÊý¾ÝÐèÒª¶àÉÙ´ÅÅ̿ռ䣿 Ò»¸ö Postgres Êý¾Ý¿â£¨´æ´¢Ò»¸öÎı¾Îļþ£©ËùÕ¼ÓõĿռä×î¶à¿ÉÄÜÐèÒªÏ൱ÓÚÕâ¸öÎı¾Îļþ×Ô Éí´óС5±¶µÄ´ÅÅ̿ռ䡣 ÀýÈ磬¼ÙÉèÓÐÒ»¸ö 100,000 ÐеÄÎļþ£¬Ã¿ÐÐÓÐÒ»¸öÕûÊýºÍÒ»¸öÎı¾ÃèÊö¡£ ¼ÙÉèÎı¾´®µÄƽ¾ù³¤¶ÈΪ20×Ö½Ú¡£Îı¾ÎļþÕ¼Óà 2.8 MB¡£´æ·ÅÕâЩÊý¾ÝµÄ PostgreSQL Êý¾Ý¿âÎļþ´óÔ¼ÊÇ 6.4 MB: 32 ×Ö½Ú: ÿÐеÄÍ·£¨¹À¼ÆÖµ£© 24 ×Ö½Ú: Ò»¸öÕûÊýÐÍ×ֶκÍÒ»¸öÎı¾ÐÍ×ֶΠ+ 4 ×Ö½Ú: Ò³ÃæÄÚÖ¸ÏòÔª×éµÄÖ¸Õë ---------------------------------------- 60 ×Ö½ÚÿÐÐ PostgreSQL Êý¾ÝÒ³µÄ´óСÊÇ 8192 ×Ö½Ú (8 KB)£¬Ôò£º 8192 ×Ö½Úÿҳ ------------------- = 136 ÐÐ/Êý¾ÝÒ³£¨ÏòÏÂÈ¡Õû£© 60 ×Ö½ÚÿÐÐ 100000 Êý¾ÝÐÐ -------------------- = 735 Êý¾ÝÒ³£¨ÏòÉÏÈ¡Õû£© 128 ÐÐÿҳ 735 Êý¾ÝÒ³ * 8192 ×Ö½Ú/Ò³ = 6,021,120 ×Ö½Ú£¨6 MB£© Ë÷Òý²»ÐèÒªÕâô¶àµÄ¶îÍâÏûºÄ£¬µ«Ò²È·Êµ°üÀ¨±»Ë÷ÒýµÄÊý¾Ý£¬Òò´ËËüÃÇÒ²¿ÉÄÜºÜ ´ó¡£ ¿ÕÖµNULL´æ·ÅÔÚλͼÖУ¬Òò´ËÕ¼ÓúÜÉٵĿռ䡣 4.6)ΪʲôÎҵIJéѯºÜÂý£¿ÎªÊ²Ã´ÕâЩ²éѯûÓÐÀûÓÃË÷Òý£¿ ²¢·Çÿ¸ö²éѯ¶¼»á×Ô¶¯Ê¹ÓÃË÷Òý¡£Ö»ÓÐÔÚ±íµÄ´óС³¬¹ýÒ»¸ö×îСֵ£¬²¢ÇÒ²éѯֻ »áÑ¡ÖбíÖнÏС±ÈÀýµÄ¼Ç¼ʱ²Å»á²ÉÓÃË÷Òý¡£ ÕâÊÇÒòΪË÷ÒýɨÃèÒýÆðµÄËæ¼´´ÅÅÌ´æÈ¡¿ÉÄܱÈÖ±½ÓµØ¶ÁÈ¡±í£¨Ë³ÐòɨÃ裩¸üÂý¡£ ΪÁËÅжÏÊÇ·ñʹÓÃË÷Òý£¬PostgreSQL±ØÐë»ñµÃÓйرíµÄͳ¼ÆÖµ¡£ÕâЩͳ¼ÆÖµ¿ÉÒÔ Ê¹Óà VACUUM ANALYZE£¬»ò ANALYZE »ñµÃ¡£ ʹÓÃͳ¼ÆÖµ£¬ÓÅ»¯Æ÷ÖªµÀ±íÖÐÓжàÉÙÐУ¬¾ÍÄܹ»¸üºÃµØÅжÏÊÇ·ñÀûÓÃË÷Òý¡£ ͳ¼ÆÖµ¶ÔÈ·¶¨ÓÅ»¯µÄÁ¬½Ó˳ÐòºÍÁ¬½Ó·½·¨Ò²ºÜÓÐÓá£ÔÚ±íµÄÄÚÈÝ·¢Éú±ä»¯Ê±£¬Ó¦ ¶¨ÆÚ½øÐÐͳ¼ÆÖµµÄ¸üÐÂÊÕ¼¯¡£ Ë÷Òýͨ³£²»ÓÃÓÚ ORDER BY »òÖ´ÐÐÁ¬½Ó¡£¶ÔÒ»¸ö´ó±íµÄÒ»´Î˳ÐòɨÃ裬ÔÙ×öÒ»¸öÏÔʽµÄÅÅÐòͨ³£±ÈË÷ÒýɨÃè Òª¿ì¡£ µ«ÊÇ£¬ÔÚ LIMIT ºÍ ORDER BY ½áºÏʹÓÃʱ¾ ³£»áʹÓÃË÷Òý£¬ÒòΪÕâÖ»»á·µ»Ø±íµÄһС²¿·Ö¡£ ʵ¼ÊÉÏ£¬ËäÈ» MAX() ºÍ MIN() ²¢²»Ê¹ÓÃË÷Òý£¬Í¨¹ý¶Ô ORDER BY ºÍ LLIMIT ʹÓÃË÷ÒýÈ¡µÃ×î´óÖµºÍ×îСֵҲÊÇ¿ÉÒԵģº SELECT col FROM tab ORDER BY col [ DESC ] LIMIT 1; Èç¹ûÄãÈ·ÐÅPostgreSQLµÄÓÅ»¯Æ÷ʹÓÃ˳ÐòɨÃèÊDz»ÕýÈ·µÄ£¬Äã¿ÉÒÔʹÓÃSET enable_seqscan TO 'off'Ö¸Á È»ºóÔÙ´ÎÔËÐвéѯ£¬Äã¾Í¿ÉÒÔ¿´³öʹÓÃÒ»¸öË÷ÒýɨÃèÊÇ·ñȷʵҪ¿ìһЩ¡£ µ±Ê¹ÓÃͨÅä·û²Ù×÷£¬ÀýÈç LIKE »ò ~ ʱ£¬Ë÷ÒýÖ»ÄÜÔÚÌض¨µÄÇé¿öÏÂʹÓ㺠* ×Ö·û´®µÄ¿ªÊ¼²¿·Ö±ØÐëÊÇÆÕͨ×Ö·û´®£¬Ò²¾ÍÊÇ˵£º + LIKE ģʽ²»ÄÜÒÔ % ´òÍ·¡£ + ~ £¨ÕýÔò±í´ïʽ£©Ä£Ê½±ØÐëÒÔ ^ ´òÍ·¡£ * ×Ö·û´®²»ÄÜÒÔÆ¥Åä¶à¸ö×Ö·ûµÄģʽÀà´òÍ·£¬ÀýÈç [a-e]¡£ * ´óСдÎ޹صIJéÕÒ£¬Èç ILIKE ºÍ ~* µÈ²»Ê¹ÓÃË÷Òý£¬µ«¿ÉÒÔÓà 4.8 ½ÚÃèÊöµÄº¯ÊýË÷Òý¡£ * ÔÚ×ö initdb ʱ±ØÐë²ÉÓÃȱʡµÄ±¾µØÉèÖà C locale£¬ÒòΪϵͳ²»¿ÉÄÜÖªµÀÔÚ·ÇC localeÇé¿öʱÏÂÒ»¸ö×î´ó×Ö·ûÊÇʲô¡£ ÔÚÕâÖÖÇé¿öÏ£¬Äã¿ÉÒÔ´´½¨Ò»¸öÌØÊâµÄtext_pattern_opsË÷ÒýÀ´ÓÃÓÚLIKEµÄ Ë÷Òý¡£ ÔÚ8.0֮ǰµÄ°æ±¾ÖУ¬³ý·ÇÒª²éѯµÄÊý¾ÝÀàÐͺÍË÷ÒýµÄÊý¾ÝÀàÐÍÏàÆ¥Å䣬·ñÔòË÷Ò ý¾³£ÊÇδ±»Óõ½£¬ÌرðÊǶÔint2,int8ºÍÊýÖµÐ͵ÄË÷Òý¡£ 4.7)ÎÒÈçºÎ²ÅÄÜ¿´µ½²éѯÓÅ»¯Æ÷ÊÇÔõÑùÆÀ¹À´¦ÀíÎҵIJéѯ£¿ ²Î¿¼ EXPLAIN ÊÖ²áÒ³¡£ 4.8)ÎÒÔõÑù×öÕýÔò±í´ïʽËÑË÷ºÍ´óСдÎ޹صÄÕýÔò±í´ïʽ²éÕÒ£¿ÔõÑùÀûÓÃË÷Òý½øÐдóÐ ¡Ð´Î޹زéÕÒ£¿ ²Ù×÷·û ~ ´¦ÀíÕýÔò±í´ïʽƥÅ䣬¶ø ~* ´¦Àí´óСдÎ޹صÄÕýÔò±í´ïʽƥÅä¡£´óдЩÎÞ¹ØµÄ LIKE ±äÖÖ³ÉΪ ILIKE¡£ ´óСдÎ޹صĵÈʽ±È½Ïͨ³£Ð´×ö£º SELECT * FROM tab WHERE lower(col) = 'abc'; ÕâÑù½«²»»áʹÓñê×¼µÄË÷Òý¡£µ«ÊÇ¿ÉÒÔ´´½¨Ò»¸ö¿É±»ÀûÓõĺ¯ÊýË÷Òý: CREATE INDEX tabindex ON tab (lower(col)); 4.9)ÔÚÒ»¸ö²éѯÀÎÒÔõÑù¼ì²âÒ»¸ö×Ö¶ÎÊÇ·ñΪ NULL £¿ÎÒÈçºÎ²ÅÄÜ׼ȷÅÅÐò¶ø²»ÂÛij×Ö¶ÎÊÇ·ñº¬ NULL Öµ£¿ Óà IS NULL ºÍ IS NOT NULL ²âÊÔÕâ¸ö×ֶΣ¬¾ßÌå·½·¨ÈçÏ£º SELECT * FROM tab WHERE col IS NULL; ΪÁËÄܶԺ¬ NULL×Ö¶ÎÅÅÐò£¬¿ÉÔÚ ORDER BY Ìõ¼þÖÐʹÓà IS NULLºÍ IS NOT NULL ÐÞÊηû£¬Ìõ¼þΪÕæ true ½«±ÈÌõ¼þΪ¼Ùfalse ÅÅÔÚÇ°Ã棬ÏÂÃæµÄÀý×ӾͻὫº¬ NULL µÄ¼Ç¼ÅÅÔÚ½á¹ûµÄÉÏÃ沿·Ö£º SELECT * FROM tab ORDER BY (col IS NOT NULL) 4.10)¸÷ÖÖ×Ö·ûÀàÐÍÖ®¼äÓÐʲô²»Í¬£¿ ÀàÐÍ ÄÚ²¿Ãû³Æ ˵Ã÷ VARCHAR(n) varchar Ö¸¶¨ÁË×î´ó³¤¶È£¬±ä³¤×Ö·û´®£¬²»×㶨Ò峤¶ÈµÄ²¿·Ö²»²¹Æë CHAR(n) bpchar ¶¨³¤×Ö·û´®£¬Êµ¼ÊÊý¾Ý²»×㶨Ò峤¶Èʱ£¬ÒÔ¿Õ¸ñ²¹Æë TEXT text ûÓÐÌرðµÄÉÏÏÞÏÞÖÆ£¨½öÊÜÐеÄ×î´ó³¤¶ÈÏÞÖÆ£© BYTEA bytea ±ä³¤×Ö½ÚÐòÁУ¨Ê¹ÓÃNULLÒ²ÊÇÔÊÐíµÄ£© "char" char Ò»¸ö×Ö·û ÔÚϵͳ±íºÍÔÚһЩ´íÎóÐÅÏ¢ÀïÄ㽫¿´µ½ÄÚ²¿Ãû³Æ¡£ ÉÏÃæËùÁеÄÇ°ËÄÖÖÀàÐÍÊÇ"varlena"£¨±ä³¤£©ÀàÐÍ£¨Ò²¾ÍÊÇ˵£¬¿ªÍ·µÄËĸö×Ö½ÚÊ Ç³¤¶È£¬ºóÃæ²ÅÊÇÊý¾Ý£©¡£ ÓÚÊÇʵ¼ÊÕ¼ÓõĿռä±ÈÉùÃ÷µÄ´óСҪ¶àһЩ¡£ È»¶øÕâЩÀàÐͶ¼¿ÉÒÔ±»Ñ¹Ëõ´æ´¢£¬Ò²¿ÉÒÔÓà TOAST ÍÑ»ú´æ´¢£¬Òò´Ë´ÅÅÌ¿Õ¼äÒ²¿ÉÄܱÈÔ¤ÏëµÄÒªÉÙ¡£ VARCHAR(n) ÔÚ´æ´¢ÏÞÖÆÁË×î´ó³¤¶ÈµÄ±ä³¤×Ö·û´®ÊÇ×îºÃµÄ¡£ TEXT ÊÊÓÃÓÚ´æ´¢×î´ó¿É´ï 1G×óÓÒµ«Î´¶¨ÒåÏÞÖƳ¤¶ÈµÄ×Ö·û´®¡£ CHAR(n) ×îÊʺÏÓÚ´æ´¢³¤¶ÈÏàͬµÄ×Ö·û´®¡£ CHAR(n)»á¸ù¾ÝËù¸ø¶¨µÄ×ֶ㤶ÈÒÔ¿Õ¸ñ²¹×㣨²»×ãµÄ×Ö¶ÎÄÚÈÝ£©£¬ ¶ø VARCHAR(n) Ö»´æ´¢Ëù¸ø¶¨µÄÊý¾ÝÄÚÈÝ¡£ BYTEA ÓÃÓÚ´æ´¢¶þ½øÖÆÊý¾Ý£¬ÓÈÆäÊÇ°üº¬ NULL ×Ö½ÚµÄÖµ¡£ÕâЩÀàÐ;ßÓÐÏàËƵÄÐÔÄÜÌØÐÔ¡£ 4.11.1)ÎÒÔõÑù´´½¨Ò»¸öÐòÁкÅ/×Ô¶¯µÝÔöµÄ×ֶΣ¿ PostgreSQL Ö§³Ö SERIAL Êý¾ÝÀàÐÍ¡£ËüÔÚ×Ö¶ÎÉÏ×Ô¶¯´´½¨Ò»¸öÐòÁкÍË÷Òý¡£ÀýÈ磺 CREATE TABLE person ( id SERIAL, name TEXT ); »á×Ô¶¯×ª»»Îª£º CREATE SEQUENCE person_id_seq; CREATE TABLE person ( id INT4 NOT NULL DEFAULT nextval('person_id_seq'), name TEXT ); ²Î¿¼ create_sequence ÊÖ²áÒ³»ñÈ¡¹ØÓÚÐòÁеĸü¶àÐÅÏ¢¡£ 4.11.2)ÎÒÈçºÎ»ñµÃÒ»¸ö²åÈëµÄÐòÁкŵÄÖµ£¿ Ò»ÖÖ·½·¨ÊÇÔÚ²åÈë֮ǰÏÈÓú¯Êý nextval() ´ÓÐòÁжÔÏóÀï¼ìË÷³öÏÂÒ»¸ö SERIAL Öµ£¬È»ºóÔÙÏÔʽ²åÈ롣ʹÓà 4.11.1 ÀïµÄÀý±í£¬¿ÉÓÃαÂëÕâÑùÃèÊö£º new_id = execute("SELECT nextval('person_id_seq')"); execute("INSERT INTO person (id, name) VALUES (new_id, 'Blaise Pascal')"); ÕâÑù»¹ÄÜÔÚÆäËû²éѯÖÐʹÓôæ·ÅÔÚ new_id ÀïµÄÐÂÖµ£¨ÀýÈ磬×÷Ϊ person ±íµÄÍâ¼ü£©¡£ ×¢Òâ×Ô¶¯´´½¨µÄ SEQUENCE ¶ÔÏóµÄÃû³Æ½«»áÊÇ