psqlコマンドのヘルプ

広告

PostgreSQLへ接続するには、"psql"コマンドを使います。"psql"コマンドは接続パラメータオプションが色々あり、「-?」を付けて実行することでオプションの種類と使い方が表示されます。

まずは、コマンドプロンプトをまず開いて下記のように"psql --help"と入力して下さい。

psqlコマンドオプションの確認

出てくる内容は下記の通りです。ここでは詳しく見ていきませんが、どんなものがあるかだけ見ておいて下さい。

---------------------------------------------------

This is psql 8.1.3, the PostgreSQL interactive terminal.

Usage:
  psql [OPTIONS]... [DBNAME [USERNAME]]

General options:

-d DBNAMEspecify database name to connect to (default: "xxxxx")
-c COMMANDrun only single command (SQL or internal) and exit
-f FILENAMEexecute commands from file, then exit
-llist available databases, then exit
-v NAME=VALUEset psql variable NAME to VALUE
-Xdo not read startup file (~/.psqlrc)
--helpshow this help, then exit
--versionoutput version information, then exit

Input and output options:

-aecho all input from script
-eecho commands sent to server
-Edisplay queries that internal commands generate
-qrun quietly (no messages, only query output)
-o FILENAMEsend query results to file (or |pipe)
-ndisable enhanced command line editing (readline)
-ssingle-step mode (confirm each query)
-Ssingle-line mode (end of line terminates SQL command)
-L FILENAMEsend session log to file

Output format options:

-Aunaligned table output mode (-P format=unaligned)
-HHTML table output mode (-P format=html)
-tprint rows only (-P tuples_only)
-T TEXTset HTML table tag attributes (width, border) (-P tableattr=)
-xturn on expanded table output (-P expanded)
-P VAR[=ARG]set printing option VAR to ARG (see ¥pset command)
-F STRINGset field separator (default: "|") (-P fieldsep=)
-R STRINGset record separator (default: newline) (-P recordsep=)

Connection options:

-h HOSTNAMEdatabase server host or socket directory (default: "local socket")
-p PORTdatabase server port (default: "5432")
-U NAMEdatabase user name (default: "xxxxx")
-Wprompt 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のバージョンを確認できます。

PostgreSQLバージョンの確認

( Written by Tatsuo Ikura )