· KLDP.org · KLDP.net · KLDP Wiki · KLDP BBS ·
Linuxdoc Sgml/JServ_PgSQL-KLDP

postgreSQLÀÇ JDBC È°¿ëÇϱâ

postgreSQLÀÇ JDBC È°¿ëÇϱâ

ÁÖÈ¿½Ä nogadax@kldp.org

2000³â 6¿ù 15ÀÏ
ÀÌ ¹®¼­´Â "Apache-JServ ¿¡ postgreSQL ¿¬µ¿Çϱâ"¶ó´Â Á¦¸ñÀÇ ¹®¼­¸¦ ´ëÆø ¼öÁ¤, º¸¿ÏÇÑ °ÍÀÌ´Ù. ¶ÇÇÑ ¼­¹ö Ŭ¶óÀ̾ðÆ®¿¡¼­ JDBC¸¦ ¼³Á¤ÇÏ´Â »çÇ×µµ Ãß°¡ÇÏ¿´´Ù. ÀÌ ¹®¼­´Â Æ÷½ºÆ®±×·¹½ºÀÇ JDBC¸¦ È°¿ëÇÏ´Â ¹æ¹ýÀ» Å©°Ô µÎ°¡Áö·Î ³ª´©¾î ¼³¸íÇÑ´Ù. ù ¹ø °´Â postgreSQLÀ» DB ¼­¹ö·Î ÇÏ°í À©µµ¿ì( Window 98 )¸¦ Ŭ¶óÀ̾ðÆ®·Î ÇÒ¶§ JDBCÀÇ ¼³Á¤»çÇ׿¡ ´ëÇØ ¼³¸íÇÑ´Ù. µÎ ¹ø°´Â Jserv¸¦ Ãß°¡ÇÑ Apache¿¡ DB ¼­¹ö·Î¼­ postgreSQL À» ¿¬µ¿Çϱâ À§ÇØ JDBCÀÇ ¼³Á¤ »çÇ׵ ´ëÇØ ¼³¸íÇÑ´Ù.

1. Áغñ »çÇ×

¼³Á¤ ¹× Å×½ºÆ®¿¡ ¾Õ¼­ ±âº»ÀûÀ¸·Î ÁغñµÇ¾î¾ß ÇÒ »çÇ×ÀÌ ÀÖ´Ù. ÀÌ¿¡ ´ëÇÑ »çÇ×Àº http://www.kldp.org ¸¦ ÂüÁ¶Çϰųª ±âŸ ¹®¼­¸¦ ÂüÁ¶Çϱ⠹ٶõ´Ù. ´ÙÀ½Àº ¹Ì¸® ÁغñµÇ¾î ¾ß ÇÒ »çÇ×ÀÌ´Ù.

  • ¾ÆÆÄÄ¡
  • JServ
  • JDK1.1.x ÀÌ»ó
  • JSDK2.0 ÀÌ»ó
  • postgreSQL
  • Window 98 (Ŭ¶óÀ̾ðÆ®)

ÀÌ¹Ì Å×½ºÆ®¸¦ ¸¶Ä£ ÇÊÀÚÀÇ È¯°æÀº ´ÙÀ½°ú °°´Ù.

  • ¾×¼¿ ¸®´ª½º 6.1
  • ¾ÆÆÄÄ¡ 1.3.9
  • JServ 1.0
  • JDK 1.2.2
  • JSDK 2.0
  • postgresql 6.5.3 ¹× postgresql 7.0.x
  • Window 98 (Ŭ¶óÀ̾ðÆ®)

±âŸ Âü°í¸¦ À§ÇÑ »çÀÌÆ®´Â ´ÙÀ½°ú °°´Ù.

±âŸ ¾à°£ÀÇ Æ÷½ºÆ®±×·¹½º ¹®¼­¿Í Apache-JServ, Æ÷½ºÆ®±×·¹½º ¿¬µ¿ °ü·ÃÀÇ ¼Ò½º ¿¹Á¦°¡ ÇÊÀÚÀÇ È¨ÆäÀÌÁö¿¡ ( http://user.chollian.net/~nogadax) ÀÖÀ¸´Ï ÂüÁ¶Çϱ⠹ٶõ´Ù.

2. Æ÷½ºÆ®±×·¹½º JDBC µå¶óÀ̹ö ¸¸µé±â

Æ÷½ºÆ®±×·¹½º´Â Type 4ÀÇ JDBC µå¶óÀ̹ö¸¦ Á¦°øÇÑ´Ù. Type 4´Â ¼ø¼ö ÀÚ¹Ù·Î ÀÛ¼ºµÇ¾ú°í µ¥ÀÌÅͺ£À̽º ÀÚüÀÇ Åë½Å ÇÁ·ÎÅäÄÝ·Î Åë½ÅÇÑ´Ù. À̴ Ŭ¶óÀ̾ðÆ®ÃøÀÌ JDBC¸¦ ÅëÇØ DBMS ¼­¹ö¿ÍÀÇ Á÷Á¢ÀûÀÎ Åë½ÅÀÌ °¡´ÉÇÔÀ» ÀǹÌÇÑ´Ù. ³×Æ®¿öÅ©»ó¿¡¼­ JDBC µå¶óÀ̹ö¸¦ ÅëÇØ °£Æí ÇÏ°Ô Æ÷½ºÆ®±×·¹½º DB ¼­¹ö¿Í ¿¬°áÇÒ ¼ö ÀÖÀ¸¸ç À̸¦ ÀÀ¿ëÇÏ·Á´Â °³¹ßÀÚ´Â DB ÀÇ ±â´É¿¡ ¸¸ ÁýÁßÇϸç ÀÛ¾÷À» ÇÒ ¼ö ÀÖ´Ù.

¶ÇÇÑ Æ÷½ºÆ®±×·¹½º JDBC µå¶óÀ̹ö´Â Ç÷§Æû¿¡ ºñÁ¾¼ÓÀûÀ̹ǷΠÇѹø ÄÄÆÄÀÏµÈ µå¶óÀ̹ö´Â ¾î¶² Ç÷§Æû¿¡¼­µµ »ç¿ë °¡´ÉÇÏ´Ù. ¿¹¸¦ µé¾î, ÄÄÆÄÀÏ µÇ¾î »ý¼ºµÈ Æ÷½ºÆ®±×·¹½º JDBC µå ¶óÀ̹ö´Â À©µµ¿ì³ª ¸®´ª½º¿¡¼­ ¾î¶°ÇÑ ¼öÁ¤¾øÀÌ ¹Ù·Î »ç¿ë °¡´ÉÇÏ´Ù.

2.1 JDBC ´Ù¿î¹Þ±â

Æ÷½ºÆ®±×·¹½º¸¦ Á÷Á¢ ¼³Ä¡ÇÏÁö ¾Ê¾Æ Æ÷½ºÆ®±×·¹½ºÀÇ ¼Ò½º°¡ ¾øÀ» °æ¿ì Æ÷½ºÆ®±×·¹½º »çÀÌÆ® ( http://www.postgresql.org) ¿¡¼­ RPM ÇüÅÂÀÇ JDBC µå¶óÀ̹ö¸¦ ´Ù¿î¹ÞÀ» ¼ö ÀÖ´Ù. ±×¿Ü¿¡ http://www.retep.org.uk ¿¡¼­ ´Ù¿î ¹ÞÀ» ¼ö ÀÖ´Ù.

´Ù¿î¹ÞÀ» ¶§ ÁÖÀÇÇÒ Á¡ÀÌ Àִµ¥ ¸¸¾à "JDK1.1.x" ¸¦ °¡Áö°í ÀÖ´Ù¸é "JDBC 1" µå¶óÀ̹ö¸¦ ´Ù¿î¹Þ¾Æ¾ß ÇÏ°í "JDK1.2" ÀÌ»óÀ» °¡Áö°í ÀÖ´Ù¸é "JDBC 2" µå¶óÀ̹ö¸¦ ´Ù¿î¹ÞÀ¸¸é µÈ´Ù.

2.2 JDBC ¸¸µé±â

JDBC µå¶óÀ̹ö°¡ ¾ø´Ù¸é À̸¦ ¸¸µé¾î¾ß ÇÑ´Ù. ¸¸¾à, Æ÷½ºÆ®±×·¹½ºÀÇ ¼Ò½º¸¦ ´Ù¿î¹Þ¾Æ Á÷Á¢ ¼³Ä¡¸¦ ÇÑ °æ¿ìÀ̸é Æ÷½ºÆ®±×·¹½º ¼Ò½º µð·ºÅ丮³»ÀÇ interfaces µð·ºÅ丮¿¡ JDBC µå¶óÀ̹ö ¼Ò½º°¡ À־ ÄÄÆÄÀÏÀ» ÇÏ¸é µÈ´Ù.

JDBC µå¶óÀ̹öÀÇ ÄÄÆÄÀϽà "JDK1.1.x" ÇÏ¿¡¼­ JDBC µå¶óÀ̹ö¸¦ ¸¸µé¸é "JDBC 1" µå¶óÀÌ ¹öÀÌ´Ù. JDK1.2 ¹öÁ¯¿¡¼­ ¸¸µé¾îÁø JDBC µå¶óÀ̹ö´Â "JDBC 2" µå¶óÀ̹öÀÌ´Ù.

ÀÌ ¹®¼­¿¡¼­´Â Æ÷½ºÆ®±×·¹½ºÀÇ ¼Ò½º µð·ºÅ丮´Â "/usr/local/src/pgsql_¹öÁ¯" ÀÌ¶ó °¡Á¤ÇÏ°í Æ÷½ºÆ®±×·¹½º°¡ ÄÄÆÄÀÏµÇ¾î ¼³Ä¡µÉ µð·ºÅ丮¸¦ "/usr/local/pgsql" À̶ó°í °¡Á¤ÇÑ´Ù. ±âŸ, Æ÷ ½ºÆ®±×·¹½º "6.5.x" ¹öÀü´ëÀÇ ÄÄÆÄÀÏ ¹æ¹ý°ú Æ÷½ºÆ®±×·¹½º "7.0.x" ¹öÀü´ëÀÇ JDBC µå¶óÀ̹ö ÀÇ ÄÄÆÄÀÏ ¹æ¹ýÀÌ ´Ù¸£¹Ç·Î ÁÖÀÇÇÏ¿©¾ß ÇÑ´Ù. ÀÌÁ¦ JDBC µå¶óÀ̹ö¸¦ ¸¸µé¾îº¸ÀÚ.

postgreSQL 6.5.x µå¶óÀ̹ö ¸¸µé±â

postgreSQL 6.5.x ÀÇ °æ¿ì´Â ´ÙÀ½°ú °°´Ù.

/usr/local/src/pgsql6.5.3/src/interfaces/jdbc]$ make

´ÜÁö À§ÀÇ µð·ºÅ丮·Î °¡¼­ "make"¸¸ ÇØÁÖ¸é µÈ´Ù. "make" ¿Ï·á ÈÄ¿¡ ÄÄÆÄÀÏ µÈ µå¶óÀ̹ö ¸¦ È®ÀÎÇØ º¸ÀÚ. µå¶óÀ̹öÀÇ À̸§Àº "postgresql.jar" ÀÌ´Ù. ÀÌÁ¦´Â "/usr/local/pgsql" ¿¡ jdbc ¶ó´Â µð·ºÅ丮¸¦ ¸¸µé°í "postgresql.jar" ¸¦ º¹»çÇÏÀÚ. JDBC µå¶óÀ̹ö¸¦ ÀúÀåÇÒ µð·ºÅ丮´Â ÀÚ½ÅÀÌ ¿øÇÏ´Â ´ë·Î ¹Ù²Ù¾îµµ ÁÁ´Ù.

/usr/local/pgsql]$ mkdir  jdbc

/usr/local/pgsql]$ cp  ../src/pgsql6.5.3/src/interfaces/postgresql.jar  ./jdbc/

postgreSQL 7.0.x µå¶óÀ̹ö ¸¸µé±â

"postgreSQL 7.0.x" ÀÇ °æ¿ì´Â "6.5.x" ¿Í´Â Á» ´Ù¸£´Ù. ¸¸¾à, "6.5.x" ó·³ "make" ¸¸ ÀÔ·Â ÇÏ¸é ¸Þ½ÃÁö°¡ ³ª¿À´Âµ¥ ±× ³»¿ëÀº "JDK1.1.x" À̸é "make jdbc1 jar"À» ÀÔ·ÂÇÏ°í "JDK1.2.x" À̸é "make jdbc2 jar"¸¦ ÀÔ·ÂÇ϶ó´Â ¸Þ½ÃÁö°¡ ³ª¿Â´Ù. ¿©±â¼­´Â "JDK1.2.x" ·Î °¡Á¤ÇÏ°í ÄÄÆÄÀÏ Çغ¸ÀÚ.

/usr/local/src/pgsql7.0.2/src/interfaces/jdbc]$ make    jdbc2    jar

ÀÌÁ¦ ÄÄÆÄÀÏ µÈ µå¶óÀ̹ö¸¦ È®ÀÎÇØ º¸ÀÚ. µå¶óÀ̹öÀÇ À̸§Àº "postgresql.jar" ÀÌ´Ù. »ý¼ºµÈ JDBC µå¶óÀ̹ö´Â "/usr/local/pgsql" ¿¡ jdbc ¶ó´Â µð·ºÅ丮¸¦ ¸¸µé°í JDBC µå¶óÀ̹ö¸¦ º¹ »çÇØ ³õÀ¸¸é µÈ´Ù.

/usr/local/pgsql]$ mkdir  jdbc

/usr/local/pgsql]$ cp  ../src/pgsql7.0.2/src/interfaces/postgresql.jar  ./jdbc/

2.3 JDBC µå¶óÀ̹ö Å×½ºÆ®Çϱâ

¸®´ª½º¿¡¼­ ÄÄÆÄÀÏµÇ¾î »ý¼ºµÈ JDBC µå¶óÀ̹ö¸¦ Å×½ºÆ®ÇÏ·Á°í ÇÏ´Â °æ¿ì "JDK"¸¦ À§ÇØ CLASSPATH ¸¦ ¼³Á¤ÇÏ¿©¾ß ÇÑ´Ù. CLASSPATHÀÇ ¼³Á¤ ¿¹´Â ´ÙÀ½°ú °°´Ù.

export   CLASSPATH="$CLASSPATH:/usr/local/pgsql/jdbc/postgresql.jar:."

À§ÀÇ export ¸í·ÉÀ» ÀÏ¹Ý ½©»ó¿¡¼­ ½ÇÇàÇÏ¿©µµ µÇ³ª ÀÌ´Â ÀÏȸ¼ºÀ̹ǷΠ¸Å¹ø ºÎÆà ¶§¸¶´Ù export ¸í·ÉÀ» ½ÇÇàÇØÁÖ¾î¾ß ÇÑ´Ù. ÀÏȸ¼ºÀÌ ¾Æ´Ñ ¿µ±¸ÀûÀ¸·Î ¼³Á¤Çϱâ À§ÇØ ¸®´ª½ºÀÇ ºÎÆà ½Ã ·Î±ä °ü·Ã ¼³Á¤ ÆÄÀÏÀÎ "/etc/profile" À̳ª "/root/.bash_profile" µî¿¡ À§ÀÇ CLASSPATH ¼³Á¤ ¿¹¸¦ Ãß°¡ÇÏ¸é µÈ´Ù.

¼³Á¤ÀÌ ³¡³ª¸é ºÎÆà ÈÄ ¼³Á¤ »çÇ× ¹× JDBC µå¶óÀ̹öÀÇ È®ÀÎÀ» À§ÇØ Å×½ºÆ®¸¦ Çغ¸ÀÚ. JDBC µå¶óÀ̹öÀÇ Å×½ºÆ®¸¦ À§ÇØ "/usr/local/src/pgsql653/src/interfaces/jdbc/example" µð·º Å丮ÀÇ ¿¹Á¦ ¼Ò½º¸¦ ÄÄÆÄÀÏÇغ»´Ù. ´ÙÀ½Àº Å×½ºÆ®¸¦ À§ÇØ example µð·ºÅ丮ÀÇ basic.java¸¦ ÄÄÆÄÀÏÇÏ´Â ¿¹ÀÌ´Ù.

/usr/local/src/pgsql653/src/interfaces/jdbc/example]$ javac  basic.java

3. ¼­¹ö Ŭ¶óÀ̾ðÆ® (À©µµ¿ì) ¼³Á¤

¸®´ª½º¿¡ Æ÷½ºÆ®±×·¹½º¸¦ ¼³Ä¡ÇÑ ÈÄ Æ÷½ºÆ®±×·¹½º¸¦ DB¼­¹ö·Î ÇÏ°í Ŭ¶óÀ̾ðÆ®ÃøÀÎ À©µµ¿ì ¿¡¼­ JDBC¸¦ ÅëÇØ Æ÷½ºÆ®±×·¹½º¸¦ ÀÌ¿ëÇÏ·Á ÇÑ´Ù°í °¡Á¤ÇÏÀÚ. ±âŸ À©µµ¿ìÀÇ IP ÁÖ¼Ò´Â 210.110.144.169 ÀÌ¶ó °¡Á¤ÇÑ´Ù.

JDBC µå¶óÀ̹öÀÇ ¼³Á¤ ¼ø¼­´Â ´ÙÀ½°ú °°´Ù.

  1. Æ÷½ºÆ®±×·¹½º JDBC µå¶óÀ̹ö¸¦ À©µµ¿ìÀÇ Àû´çÇÑ µð·ºÅ丮¿¡ º¹»çÇÑ´Ù.

  2. À©µµ¿ìÀÇ AUTOEXEC.BAT ÆÄÀÏ¿¡ JDBC µå¶óÀ̹ö °æ·Î¸¦ CLASSPATH¿¡ µî·ÏÇÑ´Ù.

    ¾Æ·¡´Â AUTOEXEC.BAT ÆÄÀÏ¿¡¼­ÀÇ ¼³Á¤¿¹ÀÌ´Ù.

    set  classpath=.;c:\postgres\jdbc_drv\postgresql.jar

  3. À©µµ¿ì¸¦ ¸®ºÎÆÃÇÑ´Ù.

  4. À©µµ¿ì¿¡¼­ DB¼­¹ö·ÎÀÇ ¿øÇÒÇÑ Á¢±ÙÀ» Çã¿ëÇϱâ À§ÇØ ¸®´ª½º¿¡ ¼³Ä¡µÈ Æ÷½ºÆ®±×·¹½ºÀÇ "pg_hba.conf" ÆÄÀÏÀ» ¼öÁ¤ÇÑ´Ù.

    ¸¸¾à Æ÷½ºÆ®±×·¹½ºÀÇ °æ·Î°¡ "/usr/local/pgsql" À̸é pg_hba.conf ÆÄÀÏÀº "/usr/local/pgsql/data" µð·ºÅ丮¿¡ ÀÖ´Ù.

    ¾Æ·¡´Â ¼³Á¤ ¿¹·Î¼­ Àڽſ¡ ȯ°æ¿¡ ¸Â°Ô ¼öÁ¤ÇÑ ´ÙÀ½ pg_hba.conf ÆÄÀÏÀÇ ¸¶Áö¸· ¶óÀο¡ Ãß °¡ÇÏ¸é µÈ´Ù.

    host   all   210.110.144.169   255.255.255.255   trust

À§ÀÇ ¿¹¿¡ ´ëÇÑ ¼³¸íÀº ´ÙÀ½°ú °°´Ù.

host ´Â ¿¹¾à¾î·Î¼­ Internet Domain ¹æ½ÄÀ» ÀǹÌÇÑ´Ù. all Àº ¸ðµç µ¥ÀÌÅͺ£À̽º¸¦ ÀǹÌÇÏ ¸ç ¸¸¾à ƯÁ¤ DB·Î ¼³Á¤ÇÏ°íÀÚ ÇÑ´Ù¸é DB À̸§À» ÀûÀ¸¸é µÈ´Ù. ¿¹¸¦ µé¾î Á¢±ÙÇÏ·Á´Â µ¥ ÀÌÅͺ£À̽º¸íÀÌ "nogadax" À̸é À§ÀÇ ¿¹¿¡¼­ "all" ´ë½Å "nogadax"¸¦ ÀûÀ¸¸é µÈ´Ù. 210.110.144.169´Â Æ÷½ºÆ®±×·¹½º¿¡ Á¢±ÙÇÏ·Á´Â Ŭ¶óÀ̾ðÆ®ÀÇ IPÁּҷμ­ ¿©±â¼­´Â À©µµ¿ìÀÇ IP ÁÖ¼ÒÀÌ´Ù. 255.255.255.255 ´Â Net Mask ÀÌ´Ù. trust ´Â Ŭ¶óÀ̾ðÆ®ÀÇ Á¢±Ù¿¡ ´ëÇÑ ÀÎÁõ ¸Þ¼Òµå·Î¼­ trust´Â º°´Ù¸¥ ÀÎÁõ ÀýÂ÷¾øÀÌ access °¡ °¡´ÉÇÏ´Ù. ¸¸¾à crypt À̸é ID ¿Í ÆÐ ½º¿öµå°¡ ÇÊ¿äÇÏ´Ù. ÀÌ¿¡ ´ëÇÑ ÀÚ¼¼ÇÑ ³»¿ëÀº "pg_hba.conf" ¼³¸íÀ» ÂüÁ¶¹Ù¶ó¸ç ÀÌ¿¡ ´ëÇÑ °ÍÀº http://www.kldp.org ¿¡ ÀÖÀ¸´Ï ÂüÁ¶Çϱ⠹ٶõ´Ù.

Å×½ºÆ®

Å×½ºÆ®¸¦ À§ÇØ Æ÷½ºÆ®±×·¹½ºÀÇ JDBC ¿¹Á¦ ÇÁ·Î±×·¥ ¼Ò½º¸¦ À©µµ¿ì¿¡ Àû´çÈ÷ º¹»çÇÑ ÈÄ ÄÄÆÄÀÏ ÇÑ´Ù. ÄÄÆÄÀÏ ¿¹´Â ´ÙÀ½°ú °°´Ù.

javac  Basic.java

4. Apache-Jserv¿¡ ¿¬µ¿Çϱâ

ÀÌ ºÎºÐÀ» ½ÃÀÛÇϱâ Àü¿¡ JDK¸¦ À§ÇÑ CLASSPATH°¡ ¸ÕÀú ¼³Á¤µÇ¾î ÀÖ¾î¾ß ÇÑ´Ù. À̸¦ À§ÇØ ¾Õ¿¡¼­ ¼³¸íÇÑ "JDBC µå¶óÀ̹ö Å×½ºÆ®Çϱâ"¸¦ ÂüÁ¶Çϱâ¹Ù¶õ´Ù.

Apache-JServ °¡ ÀÌ¹Ì ¼³Ä¡µÇ¾î ÀÖ´Ù¸é JServ ȯ°æÆÄÀÏÀÎ "jserv.properties" °¡ ÀÖÀ» °ÍÀÌ ´Ù. ÀÌ È­Àϳ»¿¡ postgresql.jarÀÇ °æ·Î¸¦ Æ÷ÇÔ½ÃÄÑÁÖ¸é µÈ´Ù. ÇÊÀÚÀÇ Apache-JServÀÇ È¯°æ ÆÄÀÏ ±¸¼ºÀº ´ÙÀ½°ú °°´Ù.

 /usr/local/apache/conf]$ ls
    access.conf  
    httpd.conf    
    srm.conf   
    jserv.conf   
    jserv.properties 
    servlets.properties 

Æ÷½ºÆ®±×·¹½ºÀÇ JDBC µå¶óÀ̹ö°¡ "jserv.proeprties" ¿¡ µî·ÏÀÌ µÇ¸é Apache-JServ ¸¦ À§ÇÑ È¯°æ ¼³Á¤Àº ³¡ÀÌ´Ù. "jserv.properties" ¿¡ ´ÙÀ½Ã³·³ Ãß°¡ÇØÁÖ¸é µÈ´Ù.

wrapper.classpath=/usr/local/pgsql/jdbc/postgresql.jar

À§Ã³·³ Ãß°¡¸¦ ÇÏ¿´´Ù¸é Apache-JServ ÀÇ È¯°æ¼³Á¤ ºÎºÐÀº ³¡³µ´Ù.

ÀÌÁ¦´Â "¼­¹ö Ŭ¶óÀ̾ðÆ® (À©µµ¿ì) ¼³Á¤" ºÎºÐ¿¡¼­ ¾ð±ÞµÇ¾ú´ø "pg_hba.conf" ÆÄÀÏÀ» ¼öÁ¤ÇÏ ¸é µÈ´Ù. ¿©±â¼­´Â Apache °¡ ¼³Ä¡µÈ °÷ÀÇ IP ÁÖ¼Ò¸¦ 210.110.144.168 ¶ó°í °¡Á¤ÇÏÀÚ. ¶ÇÇÑ, Æ÷½ºÆ®±×·¹½ºÀÇ °æ·Î°¡ "/usr/local/pgsql" À̸é pg_hba.conf ÆÄÀÏÀº "/usr/local/pgsql/data" µð·ºÅ丮¿¡ ÀÖ´Ù.

¾Æ·¡´Â ¼³Á¤ ¿¹·Î¼­ Àڽſ¡ ȯ°æ¿¡ ¸Â°Ô ¼öÁ¤ÇÑ ´ÙÀ½ pg_hba.conf ÆÄÀÏÀÇ ¸¶Áö¸· ¶óÀο¡ Ãß °¡ÇÏ¸é µÈ´Ù.

host  all  210.110.144.168  255.255.255.255  trust 

À§ÀÇ ¿¹¿¡ ´ëÇÑ ¼³¸íÀº ´ÙÀ½°ú °°´Ù.

host ´Â ¿¹¾à¾î·Î¼­ Internet Domain ¹æ½ÄÀ» ÀǹÌÇÑ´Ù. Internet Domain Àº ÇÁ·Î¼¼½ºÀÇ Åë ½ÅÀÌ ³×Æ®¿öÅ©°£ÀÇ ÇÁ·ÎÅäÄÝÀ» ÅëÇØ ÀÌ·ç¾îÁö°Ô ÇÏ´Â ¸ÞÄ«´ÏÁòÀ¸·Î¼­ ÇÁ¸£ÅäÄÝÀ» ÅëÇØ DB ¼­¹ö¿¡ Á¢±ÙÇÏ·Á´Â Host ÀÇ Á¢±ÙÀ» Á¦¾îÇÑ´Ù. all Àº ¸ðµç µ¥ÀÌÅͺ£À̽º¸¦ ÀǹÌÇÏ¸ç ¸¸¾à Ư Á¤ DB·Î ¼³Á¤ÇÏ°íÀÚ ÇÑ´Ù¸é DB À̸§À» ÀûÀ¸¸é µÈ´Ù. ¿¹¸¦ µé¾î Á¢±ÙÇÏ·Á´Â µ¥ÀÌÅͺ£À̽º ¸íÀÌ "nogadax" À̸é À§ÀÇ ¿¹¿¡¼­ "all" ´ë½Å "nogadax"¸¦ ÀûÀ¸¸é µÈ´Ù. "210.110.144.168" ´Â Æ÷½ºÆ®±×·¹½º¿¡ Á¢±ÙÇÏ·Á´Â Ŭ¶óÀ̾ðÆ®ÀÇ IPÁÖ¼ÒÀÌ´Ù. ¿©±â¼­´Â Apache-Jserv°¡ ¼³Ä¡µÈ °÷ÀÇ IP ÁÖ¼ÒÀÌ´Ù. 255.255.255.255 ´Â Net Mask ÀÌ´Ù. trust ´Â Ŭ¶óÀ̾ðÆ®ÀÇ Á¢±Ù¿¡ ´ëÇÑ ÀÎÁõ ¸Þ¼Òµå·Î¼­ trust´Â º°´Ù¸¥ ÀÎÁõ ÀýÂ÷¾øÀÌ access °¡ °¡´ÉÇÏ´Ù. ¸¸¾à crypt À̸é ID ¿Í Æнº¿öµå°¡ ÇÊ¿äÇÏ¸ç ´õ¿í ÀÚ¼¼ÇÑ ³»¿ëÀº pg_hba.conf ÆÄÀÏÀ» ¼³¸íÇÑ ¹®¼­¸¦ ÂüÁ¶Çϱ⠹ٶõ´Ù.

5. Æ÷½ºÆ®±×·¹½º JDBC ±âÃÊ

5.1 JDBC¸¦ À§ÇÑ Áغñ»çÇ×

JDBC µå¶óÀ̹ö·Î Æ÷½ºÆ®±×·¹½º¸¦ ÀÀ¿ëÇÑ ÇÁ·Î±×·¥À» Å×½ºÆ®Çϱâ Àü¿¡ Æ÷½ºÆ®±×·¹½º µð¸ó ÀÌ È°¼ºÈ­ µÇ¾î ÀÖ¾î¾ß ÇÏ¸ç µ¥¸óÀº ´ÙÀ½ÀÇ ¿É¼Ç(i)¿¡ ÀÇÇØ ±âµ¿µÇ¾îÁ®¾ß ÇÑ´Ù.

postmaster   -i &

ÀÌ°ÍÀº ³×Æ®¿öÅ©¸¦ ÅëÇØ ¿¬°áÇÏ·Á´Â JDBC¸¦ À§ÇØ Çʼö »çÇ×ÀÌ´Ù. ¶ÇÇÑ pg_hba.conf ÆÄÀÏÀ» È®ÀÎÇϵµ·Ï ÇÑ´Ù. ¸¸¾à, ÀϹÝÀûÀÎ IPÁÖ¼Ò°¡ ¾Æ´Ñ localhost(127.0.0.1)À» »ç¿ëÇÏ·ÁÇÑ´Ù¸é ÀÌ ÁÖ ¼Ò(127.0.0.1)¿¡ ´ëÇÏ¿© pg_hba.conf ¿¡ ¼³Á¤ÇÏ¿©¾ß ÇÑ´Ù. ´ÙÀ½Àº localhost ¼³Á¤ ¿¹ÀÌ´Ù.

host  all  127.0.0.1  255.255.255.255  trust

5.2 µå¶óÀ̹ö ·Îµù

JDBC µå¶óÀ̹öÀÇ ·Îµù ¹æ¹ýÀº Class.forName() ¸¦ »ç¿ëÇÏ¸é µÈ´Ù. ÁÖÀÇÇÒ Á¡ÀÌ Àִµ¥ Æ÷ ½ºÆ®±×·¹½º 6.5.x ¹öÀü°ú 7.0.x ¹öÀü´ë¿¡¼­ ¾à°£ÀÇ Â÷ÀÌ°¡ »ý°å´Ù. ÇÊÀÚ°¡ Å×½ºÆ®¸¦ ¸ñÀûÀ¸ ·Î ÀÌÀü¿¡ ¸¸µé¾î ³õ¾Ò´ø ÇÁ·Î±×·¥À¸·Î 7.0.x ¹öÀü´ëÀÇ JDBC µå¶óÀ̹ö¸¦ Å×½ºÆ®¸¦ Çغ» °á °ú ¿¡·¯°¡ ¹ß»ýÇÏ¿´´Ù. ¿¡·¯¸¦ ÇØ°áÇϱâ À§ÇØ 7.0.x ¹öÀüÀÇ ¹®¼­¸¦ ã¾Æº» °á°ú ¾Æ¹«·± º¯µ¿ ÀÌ ¾ø¾úÁö¸¸ example µð·ºÅ丮ÀÇ ¿¹Á¦ ¼Ò½º¸¦ º¸°í ¿øÀÎÀ» ¹ß°ßÇÏ¿´´Ù.

Æ÷½ºÆ®±×·¹½º 6.5.x ¹öÀüÀÇ JDBC µå¶óÀ̹ö´Â Class.forName("postgresql.jar"); ÇÏ¸é µÇÁö¸¸ 7.0.x ¹öÀüÀÇ JDBC µå¶óÀ̹ö´Â Class.forName("org.postgresql.jar");¸¦ ÇÏ¿©¾ß ÇÑ´Ù. ÀÌ·¯ÇÑ Â÷À̸¦ ÁÖÀÇÇϱ⠹ٶõ´Ù. ´ÙÀ½Àº Æ÷½ºÆ®±×·¹½º ¹öÀü´ëº°·Î Class.forName()¸¦ »ç¿ëÇÑ ¿¹ÀÌ ´Ù. ±âŸ ¿¹¿Ü 󸮸¦ À§ÇØ ClassNotFoundExceptionÀ» »ç¿ëÇÑ´Ù.

postgresql 6.5.X ¿¡¼­ÀÇ Class.forName() ÀÇ ¿¹

public void  test()
throws ClassNotFoundException, FileNotFoundException,
       IOException, SQLException
{ 
   String url = "jdbc:postgresql:nogadax";  
   String usr = "postgres";  
   String pwd = "";

   Class.forName("postgresql.Driver");

   Connection db = DriverManager.getConnection(url, usr, pwd);
   ........
   ........
}

postgresql 7.0.X ¿¡¼­ÀÇ Class.forName() ÀÇ ¿¹

public void  test()
throws ClassNotFoundException, FileNotFoundException,
       IOException, SQLException
{ 
   String url = "jdbc:postgresql:nogadax";  
   String usr = "postgres";  
   String pwd = "";

   Class.forName("org.postgresql.Driver");

   Connection db = DriverManager.getConnection(url, usr, pwd);
   ........
   ........
}

5.3 Connection to the Database

Æ÷½ºÆ®±×·¹½ºÀÇ µ¥ÀÌÅͺ£À̽º·ÎÀÇ ¿¬°áÀ» À§ÇÑ ¿¹´Â ´ÙÀ½°ú °°´Ù.

 jdbc:postgresql:database_name 
 jdbc:postgresql://host/database_name 
 jdbc:postgresql://host:port/database_name 

host

Æ÷½ºÆ®±×·¹½º DB ¼­¹öÀÇ È£½ºÆ® ³×ÀÓÀÌ´Ù. IP¸¦ Á־ µÈ´Ù. ¸¸¾à ÀÌ ºÎºÐÀÌ »ý·«µÇ¸é µðÆúÆ®´Â localhost(127.0.0.1) ÀÌ´Ù.

port

Æ÷½ºÆ®±×·¹½ºÀÇ µðÆúÆ® Æ÷Æ®´Â 5432 ÀÌ¸ç »ý·« °¡´ÉÇÏ´Ù.

database_name

µ¥ÀÌŸº£À̽º¸í

±âŸ »çÇ×

ÄÁ³ØÆ®Çϱâ À§ÇØ JDBC ·ÎºÎÅÍ Connection ÀνºÅϽº¸¦ ¾ò¾î¾ß ÇÑ´Ù. À̸¦ À§ÇØ DriverManager.getConnection() ¸Þ¼Òµå¸¦ »ç¿ëÇØ¾ß ÇÑ´Ù.

Connection  db = DriverManager.getConnection(url,user,pwd);

±âŸ Æ÷½ºÆ®±×·¹½º´Â ÇϳªÀÇ ·¹ÄÚµåÀÇ Å©±â°¡ 8K ¹ÙÀÌÆ®·Î Á¦ÇѵǾî ÀÖ´Ù. ¸¸¾à ÇϳªÀÇ ·¹ Äڵ尡 8K ¹ÙÀÌÆ®¸¦ ³Ñ¾î¾ß ÇÑ´Ù¸é "Large Object" ¶ó´Â ¹æ¹ýÀ» »ç¿ëÇÏ¿©¾ß ÇÑ´Ù. ÀÌ¿¡ ´ë Çؼ­´Â Æ÷½ºÆ®±×·¹½º ÇÁ·Î±×·¡¸Ó °¡À̵åÀÇ JDBC ºÎºÐÀ» ÂüÁ¶Çϱ⠹ٶõ´Ù. ¶ÇÇÑ, JDBC ¸¦ À§ÇÑ ³ª¸ÓÁö ÀÚ¼¼ÇÑ ºÎºÐÀº ÀÏ¹Ý JDBC ¹®¼­µéÀ» ÂüÁ¶Çϱ⠹ٶõ´Ù.

5.4 Jserv Å×½ºÆ®¿ë ¼Ò½º

´ÙÀ½Àº Apache-Jserv ¿Í postgreSQLÀÌ ¿¬µ¿µÇ¾úÀ» ¶§ Å×½ºÆ®¸¦ À§ÇÑ ¼Ò½ºÀÌ´Ù. ´ÙÀ½ÀÇ ¼Ò½º´Â Æ÷½ºÆ®±×·¹½ºÀÇ ¿¹Á¦ ¼Ò½º·Î¼­ ´ÜÁö servlet ·Î ¹Ù²Ù¾î web »ó¿¡¼­ ½ÇÇàÀÌ µÇ°Ô²û ÇØÁØ °ÍÀÌ´Ù.

´ÙÀ½ ¿¹Á¦¸¦ ÄÄÆÄÀÏÇÏ°í ½ÇÇàÇϱ⿡ ¾Õ¼­ Æ÷½ºÆ®±×·¹½º¿¡ µ¥ÀÌŸº£À̽º¸¦ ¸¸µé¾î¾ß ÇÑ´Ù. ¿©±â¼­´Â µ¥ÀÌŸº£À̽º À̸§ÀÌ nogadax ÀÌ´Ù. À̸¦ ÀûÀýÈ÷ ¹Ù²Ù±â ¹Ù¶õ´Ù. ¶ÇÇÑ Æ÷½ºÆ®±×·¹ ½ºÀÇ À¯Àú¸íÀº postgres ÀÌ°í Æнº¿öµå´Â ¾ø´Ù. ÀÌ°÷ÀÇ ¼Ò½º¿¡¼­ÀÇ url, usr, pwd ÀÇ ¼³Á¤Àº ´ÙÀ½°ú °°´Ù. À̸¦ ÂüÁ¶ÇÏ¿© ÀÚ½ÅÀÇ È¯°æ¿¡ ¸Â°Ô ¹Ù²Ù±â ¹Ù¶õ´Ù.

 String url = "jdbc:postgresql:nogadax";  
 String usr = "postgres";  
 String pwd = "";

ÇÊÀÚÀÇ Å×½ºÆ® ȯ°æÀº ÇÑ´ëÀÇ PC ¿¡ Æ÷½ºÆ®±×·¹½º¿Í ¾ÆÆÄÄ¡°¡ °°ÀÌ ¼³Ä¡µÇ¾î ÀÖ´Ù. ¸¸¾à Å×½ºÆ®ÇÏ·Á°í Çϴ ȯ°æÀÌ DB¼­¹ö¿Í WEB¼­¹ö°¡ ¼­·Î ´Ù¸¥ °÷¿¡ ¼³Ä¡µÇ¾î ÀÖ´Ù¸é, Áï, 3-Tier ȯ°æÀ̸é URL Àº À§¿Í´Â ´Ù¸£°Ô µÇ¾îÁ®¾ß ÇÑ´Ù.

ÀÚ½ÅÀÇ È¯°æÀ» Àû¿ëÇϱâ À§ÇØ ´ÙÀ½ÀÇ ¿¹¸¦ ÂüÁ¶Çϱ⠹ٶõ´Ù. Âü°í·Î IP ÁÖ¼Ò 210.110.144.162 ´Â Æ÷½ºÆ®±×·¹½º DB ¼­¹öÀÇ IPÁÖ¼ÒÀ̸ç Æ÷Æ® ¹øÈ£°¡ »ý·«µÇ¾úÀ¸¹Ç·Î µðÆúÆ® ¹øÈ£ "5432"·Î ÀÚµ¿ ¼ÂÆÃµÈ »óÅÂÀÌ´Ù.

  String  url= "jdbc:postgresql://210.110.144.162/nogadax";

±âŸ Class.forName()À» ¹öÀü¿¡ µû¶ó ÀûÀýÈ÷ ¼öÁ¤Çϱ⠹ٶõ´Ù. ¾Æ·¡ÀÇ Å×½ºÆ®¿ëÀÇ ¼Ò½º´Â Æ÷½ºÆ®±×·¹½º 6.5.3 ÀÇ JDBC µå¶óÀ̹ö¸¦ ±âÁØÀ¸·Î ÀÛ¼ºµÇ¾úÀ¸¹Ç·Î Class.forName()ÀÌ ¾Æ·¡ ¿Í °°´Ù.

Class.forName("postgresql.Driver");

±×·¯¹Ç·Î 7.0.x ÀÇ JDBC µå¶óÀ̹ö¿¡¼­ Å×½ºÆ®¸¦ ÇÏ·Á¸é "org.postgresql.Driver" ·Î ¼öÁ¤ÇÏ ¸é µÈ´Ù.

¶ÇÇÑ ÄÄÆÄÀÏµÈ ¼­ºí¸´Àº ¸®Æ÷ÁöÅ丮¿¡ ÀÖ¾î¾ß ÇÑ´Ù. ¸®Æ÷ÁöÅ͸®´Â ¼­ºí¸´À» À§ÇÑ ³í¸®ÀûÀÎ µð·ºÅ丮ÀÌ´Ù. ÀÌ°ÍÀº zone ¿Í ¿¬°áµÇ¾îÁö´Âµ¥ zoneÀº URL¿¡ ÷°¡µÇ¾îÁø´Ù. ¸¸¾à zone ÀÇ À̸§ÀÌ servlet ÀÌ°í ¾Æ·¡ÀÇ ¿¹Á¦¼Ò½º¸¦ ÄÄÆÄÀÏ ÈÄ ÁöÁ¤µÈ ¸®Æ÷ÁöÅ͸®¿¡ ÀÖ´Ù¸é ½ÇÇàÀ» À§ÇØ ºê¶ó¿ìÁ®ÀÇ URL â¿¡ ´ÙÀ½Ã³·³ ÀÔ·ÂÇØÁÖ¸é µÇ´Âµ¥ Àڽſ¡°Ô ¸Â°Ô ¹Ù²Ù¾îÁÖ¸é µÈ´Ù.

http://localhost/servlet/Hello

ȤÀº

http://210.110.144.162/servlet/Hello

ȤÀº

http://nogadax.tit.ac.kr/servlet/Hello

´ÙÀ½Àº "Hello.java" ¶ó´Â Å×½ºÆ®¿ëÀÇ ¼Ò½ºÀÌ´Ù.

-------------------------------
import java.io.*;
import javax.servlet.*;
import java.sql.*;
import java.text.*;
import javax.servlet.http.*;

public class Hello extends HttpServlet
{ 
  Connection db;  
  Statement  st;
  PrintWriter out;

  public void doGet (HttpServletRequest request,
                     HttpServletResponse response) 
  throws ServletException, IOException  
  {   
   String title = "Example Apache JServ Servlet";
   response.setContentType("text/html");
   out = response.getWriter();
   out.println("<HTML><HEAD><TITLE>");
   out.println(title);
   out.println("</TITLE></HEAD><BODY bgcolor=\"#FFFFFF\">");
   out.println("<H1>" + title + "</H1>");
   out.println("<H2>Congratulations, Apache JServ is working!</H2>");
   try {
        test();
       } catch(Exception ex){
          out.println("<h2>DB error!</h2>");
         }
   out.println("</BODY></HTML>");
   out.close();
   }

   public void cleanup()
   {  
     try {
         st.executeUpdate("drop table basic");
       } catch(Exception ex) {  }
   }
         
   public void doexample() throws SQLException
   {
     out.println("<br><h2>Running tests:</h2>");
     st.executeUpdate("create table basic (a int2, b int2)");
     st.executeUpdate("insert into basic values (1,1)");
     st.executeUpdate("insert into basic values (2,1)");
     st.executeUpdate("insert into basic values (3,1)");
     st.executeUpdate("update basic set b=8");
     out.println("<h2>Updated "+st.getUpdateCount()+" rows</h2>");
     PreparedStatement ps = db.prepareStatement("insert into
                                               basic values (?,?)");
     for(int i=2;i<5;i++) {
            ps.setInt(1,4);             // "column a" = 5
            ps.setInt(2,i);             // "column b" = i
            ps.executeUpdate(); 
      }
     ps.close();                
     out.println("<h2>performing a query</h2>");
     ResultSet rs = st.executeQuery("select a, b from basic");
     if(rs!=null) {
         while(rs.next()) {
               int a = rs.getInt("a");
               int b = rs.getInt(2); 
               out.println("<h2>  a="+a+" b="+b+"</h2>");
          }
         rs.close(); 
     }
   }

   public void  test()
   throws ClassNotFoundException, FileNotFoundException,
                                 IOException,SQLException
   { 
    String url = "jdbc:postgresql:nogadax";  
    String usr = "postgres";  
    String pwd = "";
    Class.forName("postgresql.Driver");
    db = DriverManager.getConnection(url, usr, pwd);
    out.println("<h2>Connecting to Database URL = " + url +"</h2>");
    out.println("<h2>Connected...Now creating a statement</h2>");
    st = db.createStatement();
    cleanup();    
    doexample();    
    cleanup();
    out.println("<h2>Now closing the connection</h2>");
    st.close();   
    db.close();
   }//end test
 }

½ÇÇà °á°ú

½ÇÇà °á°ú´Â ´ÙÀ½°ú °°´Ù. ¾Æ·¡¿¡¼­ º¸¿©Áö´Â URLÀÌ ´Ù¸¦ ¼ö ÀÖ´Ù.

Example Apache JServ Servlet
Congratulations, Apache JServ is working!
Connecting to Database URL = jdbc:postgresql:nogadax
Connected...Now creating a statement

Running tests:

Updated 3 rows
performing a query
a=1 b=8
a=2 b=8
a=3 b=8
a=4 b=2
a=4 b=3
a=4 b=4

Now closing the connection

6. Æ÷½ºÆ®±×·¹½º À¯Àú ¸¸µé±â

JDBC ·Î ¿¬°áÀ» ÇÒ ¶§ »õ·Î¿î À¯Àú¸í°ú Æнº¿öµå¸¦ ÁÖ°í ½ÍÀ» ¶§°¡ ÀÖÀ» °ÍÀÌ´Ù. À̸¦ À§ÇØ Æ÷½ºÆ®±×·¹½ºÀÇ À¯Àú¿Í À¯Àú¿¡ ´ëÇÑ Æнº¿öµå¸¦ ¸¸µå´Â ¹æ¹ýÀ» °£´ÜÈ÷ ¼Ò°³ ÇÏ°Ú´Ù.

¸ÕÀú Æ÷½ºÆ®±×·¹½ºÀÇ ½´ÆÛ °èÁ¤(DBA)¸¦ "postgres" ¶ó°í °¡Á¤ÇÏÀÚ.

¿©±â¼­´Â µ¥ÀÌÅͺ£À̽ºÀÇ »õ·Î¿î À¯Àú¸¦ »ý¼ºÇÏ°í ±× À¯ÀúÀÇ µ¥ÀÌÅͺ£À̽º¸¦ »ý¼ºÇÒ °ÍÀÌ´Ù. ¼ø¼­´Â ´ÙÀ½°ú °°´Ù.

1. postgres °èÁ¤¿¡ Æнº¿öµå¸¦ »ý¼ºÇÑ´Ù. À̸¦ À§ÇØ Æ÷½ºÆ®±×·¹½ºÀÇ Æ¯º°ÇÑ µ¥ÀÌÅͺ£À̽ºÀÎ "template1" ¿¡ Á¢¼ÓÇÑ´Ù. Æнº¿öµå¸¦ "123qwe" ¶ó°í °¡Á¤ÇÑ´Ù.

postgres]$ psql template1
.......
template1=>alter user postgres with password '123qwe';
ALTER USER
template1=>\q
postgres]$ 

2. "pg_hba.conf" ÆÄÀÏÀ» ¼öÁ¤ÇÑ´Ù. ¸¸¾à, DB ¼­¹ö·Î Á¢¼ÓÇÏ·Á´Â ÀÚ½ÅÀÇ Host ÀÇ IP °¡ "210.110.144.169" ÀÌ¸é ´ÙÀ½Ã³·³ ¼öÁ¤ÇÑ´Ù.

 local  all                                     crypt 
 host   all   127.0.0.1        255.255.255.255  crypt
 host   all   210.110.144.169  255.255.255.255  crypt

Âü°í·Î host ·Î ½ÃÀÛÇÏ´Â ¶óÀÎÀº DB ¼­¹ö¿¡ Á¢±ÙÇÏ·Á´Â Ŭ¶óÀ̾ðÆ®¸¦ Á¦¾îÇÏ·Á ÇÑ´Ù. ±×·¯ ¹Ç·Î DB ¼­¹öÀÇ IP ¸¦ ÁÖ´Â °ÍÀÌ ¾Æ´ÔÀ» ÁÖÀÇÇϱ⠹ٶõ´Ù. ¶ÇÇÑ "crypt"´Â DB ¼­¹ö·ÎÀÇ Á¢ ±Ù Á¦¾î ¸Þ¼ÒµåÀ̹ǷΠ"crypt"¸¦ Àû¿ëÇÑ ÈĺÎÅÍ´Â DB¼­¹ö·ÎÀÇ Á¢¼ÓÀ» À§ÇØ °èÁ¤°ú Æнº¿ö µå°¡ ÇÊ¿äÇÏ´Ù.

3. ´Ù½Ã Æ÷½ºÆ®±×·¹½º ½´ÆÛ°èÁ¤À¸·Î "template1" µ¥ÀÌÅͺ£À̽º¿¡ Á¢¼ÓÇÑ ÈÄ »õ·Î¿î µ¥ÀÌÅͺ£ À̽º À¯Àú¸¦ »ý¼ºÇÑ´Ù. »õ·Î »ý¼ºÇÒ À¯Àú¸¦ "nogadax" ¶ó°í °¡Á¤Çϸç ÀÌ À¯Àú¿¡°Ô µ¥ÀÌÅͺ£ À̽º¸¦ »ý¼ºÇÒ ¼ö ÀÖ´Â ±ÇÇÑÀ» ÁÙ °ÍÀ̸ç ÀÌ ¿É¼ÇÀº "createdb" ÀÌ´Ù. ±âŸ "createuser" ¶ó ´Â ¿É¼Çµµ Àִµ¥ ÀÌ ¿É¼ÇÀº ´Ù¸¥ À¯Àú¸¦ »ý¼ºÇÒ ¼ö ÀÖ´Â ±ÇÇÑÀ» ÁØ´Ù. ¶ÇÇÑ, "template1" ¿¡ Á¢¼ÓÀ» À§ÇÑ ¿É¼Ç "-u"¸¦ ÁÖ¾î¾ß ÇÏ¸ç ¿É¼ÇÀ» ÁØ ÈĺÎÅÍ´Â °èÁ¤°ú Æнº¿öµå¸¦ ¹¯´Â´Ù. ÀÌ ¿É¼ÇÀ» ÁÖ´Â ÀÌÀ¯´Â pg_hba.conf ¿¡ "crypt" Á¢±Ù Á¦¾î ¸Þ¼Òµå¸¦ ÁÖ¾ú±â ¶§¹®ÀÌ´Ù.

postgres]$ psql -u template1
Username : postgres
Password :
.........
template1=> create user nogadax with password 'qwert' createdb ;
CREATE  USER
template1=>\q
postgres]$

4. »ý¼ºµÈ nogadax À¯Àú·Î template1 µ¥ÀÌÅͺ£À̽º¿¡ Á¢¼ÓÇÑ µÚ "nogadax"ÀÇ µ¥ÀÌÅͺ£À̽º ¸¦ »ý¼ºÇÏÀÚ. µ¥ÀÌÅͺ£À̽º¸íÀº "test" ¶ó°í °¡Á¤ÇÑ´Ù.

postgres]$ psql -u template1
Username : nogadax 
Password :
..............
template1=>create database test;
CREATE DATABASE 
template1=>\q
postgres]$ psql -u test
Username : nogadax 
Password :
................
test=> \q
postgres]$


ID
Password
Join
Generosity and perfection are your everlasting goals.


sponsored by andamiro
sponsored by cdnetworks
sponsored by HP

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2003-08-10 11:52:30
Processing time 0.0029 sec