PostgreSQL 기본 클라이언트 psql 사용하기작성자: 신기배(소타) nonun@nate.com
Contents
psql
시작하기
[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=#
일단 시작했으니 절반은 한거다! ㅋㅋ
도움말
\?
한번 해보자.. 많은 명령어가 있다.
\h
한번 해보자.. 많은 명령어가 있다.
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 하면 나옵니다 :)
psql 사용하기
일단 이 문서에서는 SQL과 관련된 내용은 언급하지 않겠다.
많이 사용되는 명령어
\d
테이블, 인덱스, 시퀀스, 뷰의 목록이 표시된다. (\d+ 하면 각 테이블의 코멘트가 표시된다.)
Contents
psql
시작하기
도움말
\?
\h
psql 쉘 옵션
psql 사용하기
많이 사용되는 명령어
Recent Posts
Archive Posts
Tags