- Home ›
- PostgreSQLの使い方 ›
- PostgreSQLへの接続と切断 ›
- HERE
psqlコマンドのヘルプ
PostgreSQLへ接続するには、"psql"コマンドを使います。"psql"コマンドは接続パラメータオプションが色々あり、「-?」を付けて実行することでオプションの種類と使い方が表示されます。
まずは、コマンドプロンプトをまず開いて下記のように"psql --help"と入力して下さい。
出てくる内容は下記の通りです。ここでは詳しく見ていきませんが、どんなものがあるかだけ見ておいて下さい。
---------------------------------------------------
This is psql 8.1.3, the PostgreSQL interactive terminal.
Usage:
psql [OPTIONS]... [DBNAME [USERNAME]]
General options:
| -d DBNAME | specify database name to connect to (default: "xxxxx") |
| -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) |
| -L FILENAME | send session log to file |
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: "xxxxx") |
| -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.
---------------------------------------------------
例えば"psql --version"と入力して頂くとPostgreSQLのバージョンを確認できます。
( Written by Tatsuo Ikura )
DBOnline