ÃÑ ÆäÀÌÁö ¼ö : 3224

Àüü ÇÔ¼ö/¿ë¾î»çÀü
Facebook Joinc ±×·ì   Joinc QA »çÀÌÆ®



joinc´Â Firefox¿Í chrome¿¡¼­ Å×½ºÆ® Çß½À´Ï´Ù. IE¿¡¼­´Â Å×À̺íÀÌ ±úÁö°Å³ª À̹ÌÁö°¡ º¸ÀÌÁö ¾ÊÀ» ¼ö ÀÖ½À´Ï´Ù. ƯÈ÷ ±¸±Û DocsÀ̹ÌÁöÀÇ °æ¿ì ¿¢¹Úó¸®µÉ ¼ö ÀÖ½À´Ï´Ù.
PostgreSQL ±âº» Ŭ¶óÀÌ¾ðÆ® psql »ç¿ëÇϱâ

ÀÛ¼ºÀÚ: ½Å±â¹è(¼ÒŸ) nonun@nate.com

Contents

1 psql
1.1 ½ÃÀÛÇϱâ
1.2 µµ¿ò¸»
1.2.1 \?
1.2.2 \h
2 psql ½© ¿É¼Ç
3 psql »ç¿ëÇϱâ
3.1 ¸¹ÀÌ »ç¿ëµÇ´Â ¸í·É¾î


1 psql

1.1 ½ÃÀÛÇϱâ


[root@linux root]# psql 
psql: FATAL:  database "root" does not exist 
 
  • ÀÌ·± ¿¡·¯°¡ ³ª¿Â´Ù¸é?

[root@linux root]# createdb 
CREATE DATABASE 
[root@linux root]# psql 
Welcome to psql 7.4.1, the PostgreSQL interactive terminal. 
 
Type:  \copyright for distribution terms 
       \h for help with SQL commands 
       \? for help on internal slash commands 
       \g or terminate with semicolon to execute query 
       \q to quit 
 
root=# 
 
  • ÀÏ´Ü ½ÃÀÛÇßÀ¸´Ï Àý¹ÝÀº ÇѰŴÙ! ¤»¤»

1.2 µµ¿ò¸»

1.2.1 \?

  • Çѹø ÇØº¸ÀÚ.. ¸¹Àº ¸í·É¾î°¡ ÀÖ´Ù.

    1.2.2 \h

  • Çѹø ÇØº¸ÀÚ.. ¸¹Àº ¸í·É¾î°¡ ÀÖ´Ù.

  • 2 psql ½© ¿É¼Ç


    [root@linux root]# psql --help 
    This is psql 7.4.1, the PostgreSQL interactive terminal. 
     
    Usage: 
      psql [OPTIONS]... [DBNAME [USERNAME]] 
     
    General options: 
      -d DBNAME       specify database name to connect to (default: "root") 
      -c COMMAND      run only single command (SQL or internal) and exit 
      -f FILENAME     execute commands from file, then exit 
      -l              list available databases, then exit 
      -v NAME=VALUE   set psql variable NAME to VALUE 
      -X              do not read startup file (~/.psqlrc) 
      --help          show this help, then exit 
      --version       output version information, then exit 
     
    Input and output options: 
      -a              echo all input from script 
      -e              echo commands sent to server 
      -E              display queries that internal commands generate 
      -q              run quietly (no messages, only query output) 
      -o FILENAME     send query results to file (or |pipe) 
      -n              disable enhanced command line editing (readline) 
      -s              single-step mode (confirm each query) 
      -S              single-line mode (end of line terminates SQL command) 
     
    Output format options: 
      -A              unaligned table output mode (-P format=unaligned) 
      -H              HTML table output mode (-P format=html) 
      -t              print rows only (-P tuples_only) 
      -T TEXT         set HTML table tag attributes (width, border) (-P tableattr=) 
      -x              turn on expanded table output (-P expanded) 
      -P VAR[=ARG]    set printing option VAR to ARG (see \pset command) 
      -F STRING       set field separator (default: "|") (-P fieldsep=) 
      -R STRING       set record separator (default: newline) (-P recordsep=) 
     
    Connection options: 
      -h HOSTNAME     database server host or socket directory (default: "local socket") 
      -p PORT         database server port (default: "5432") 
      -U NAME         database user name (default: "root") 
      -W              prompt for password (should happen automatically) 
     
    For more information, type "\?" (for internal commands) or "\help" 
    (for SQL commands) from within psql, or consult the psql section in 
    the PostgreSQL documentation. 
     
    Report bugs to <pgsql-bugs@postgresql.org>. 
     
    -d DBNAME »ç¿ëÇÒ DB¸¦ ¼±ÅÃÇÑ´Ù (±âº»ÀûÀ¸·Î »ç¿ëÀÚÀÇ IDÀÌ´Ù. ÀÌ ¹®¼­¿¡¼­´Â root
    -c COMMAND -c "SQL" Çü½ÄÀ¸·Î ÇѰ³ÀÇ Äõ¸®¸¸À» ó¸®ÇÑ ÈÄ Á¾·áÇÑ´Ù.
    -f FILENAME ÆÄÀÏ ³»ÀÇ SQLÀ» ó¸®ÇÑ ÈÄ Á¾·áÇÑ´Ù.
    -l DBÀÇ ¸ñ·ÏÀ» Ç¥½ÃÇÑ ÈÄ Á¾·áÇÑ´Ù. (psql »ç¿ë½Ã \l °ú µ¿ÀÏ)
    -h HOSTNAME ¿ø°Ý È£½ºÆ®·Î Á¢¼ÓÇÑ´Ù. (pg_hba.conf ¿¡ ´ëÇÑ ¹®¼­´Â ³ªÁß¿¡..)
    -p POST pgsql ¼­¹öÀÇ Æ÷Æ®
    -U NAME Á¢±ÙÇÒ »ç¿ëÀÚ À̸§
    • ´ëÃæ ÀÌÁ¤µµ°¡ ±×³ª¸¶ ¸¹ÀÌ »ç¿ëµÇ´Â ¿É¼ÇÀÌ´Ù. ÀÚ¼¼ÇÑ ³»¿ëÀº --help ÇÏ¸é ³ª¿É´Ï´Ù :)

    3 psql »ç¿ëÇϱâ

    • ÀÏ´Ü ÀÌ ¹®¼­¿¡¼­´Â SQL°ú °ü·ÃµÈ ³»¿ëÀº ¾ð±ÞÇÏÁö ¾Ê°Ú´Ù.

    3.1 ¸¹ÀÌ »ç¿ëµÇ´Â ¸í·É¾î

    \d Å×À̺í, À妽º, ½ÃÄö½º, ºäÀÇ ¸ñ·ÏÀÌ Ç¥½ÃµÈ´Ù. (\d+ ÇÏ¸é °¢ Å×À̺íÀÇ ÄÚ¸àÆ®°¡ Ç¥½ÃµÈ´Ù.)
    \dt {TABLENAME} Å×ÀÌºí ¸ñ·ÏÀÌ Ç¥½ÃµÈ´Ù. (\dt+ ÇÏ¸é °¢ Å×À̺í°ú ÇʵåÀÇ ÄÚ¸àÆ®°¡ Ç¥½ÃµÈ´Ù.)
    \di {INDEXNAME} À妽º ¸ñ·ÏÀÌ Ç¥½ÃµÈ´Ù. (\di+ ÇÏ¸é °¢ À妽ºÀÇ ÄÚ¸àÆ®°¡ Ç¥½ÃµÈ´Ù.)
    \ds {SEQUENCENAME} ½ÃÄö½º ¸ñ·ÏÀÌ Ç¥½ÃµÈ´Ù. (\ds+ ÇÏ¸é °¢ ½ÃÄö½ºÀÇ ÄÚ¸àÆ®°¡ Ç¥½ÃµÈ´Ù.)
    \dv {VIEWNAME} ºä ¸ñ·ÏÀÌ Ç¥½ÃµÈ´Ù. (\dv+ ÇÏ¸é °¢ ºä¿Í ÇʵåÀÇ ÄÚ¸àÆ®°¡ Ç¥½ÃµÈ´Ù.)
    \dn {SCHEMANAME} ½ºÅ°¸¶ ¸ñ·ÏÀÌ Ç¥½ÃµÈ´Ù. (ÃÖ±Ù¿¡ Ãß°¡µÈ °³³äÀÌ´Ù. ¿À¶óŬÀÇ ³×ÀÓ½ºÆäÀ̽º¿Í ºñ½ÁÇÏ´Ù.)
    \du {USERNAME} »ç¿ëÀÚ ¸ñ·ÏÀÌ Ç¥½ÃµÈ´Ù.
    \l DB ¸ñ·ÏÀÌ Ç¥½ÃµÈ´Ù. (\l+ ÇÏ¸é °¢ DBÀÇ ÄÚ¸àÆ®°¡ Ç¥½ÃµÈ´Ù.)
    \i FILENAME ÆÄÀÏ ³»ÀÇ SQLÀ» ó¸®ÇÑ´Ù.
    \c DBNAME {USERNAME} ´Ù¸¥ DB¿¡ Á¢¼ÓÇÑ´Ù. »ç¿ëÀÚ À̸§À» ¹Ù²ã Á¢¼Ó ÇÒ ¼ö ÀÖ´Ù.
    \q Á¾·á (Áß¿äÇÏ´Ù. óÀ½¿¡ ¸ô¶ó¼­ ¹ö¹÷´ò´Ù. Âü°í·Î ÄÁÆ®·ÑC ¾È¸Ô´Â´Ù -_-;)
    EmailÀ» ±âÀÔÇϸé, ´ñ±ÛÀÌ ¸ÞÀÏ·Î Àü´ÞµË´Ï´Ù.