「PostgreSQL」データベースへの接続方法

環境
Windows 10 64bit
PostgreSQL 9.6.5

書式
psql -h 接続先 -p ポート番号 -U ユーザー名 -d データベース名

操作例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
>psql -h localhost -p 5432 -U postgres -d userdb
ユーザー postgres のパスワード:
psql (14.1、サーバー 9.6.5)
"help"でヘルプを表示します。
userdb=#
>psql -h localhost -p 5432 -U postgres -d userdb ユーザー postgres のパスワード: psql (14.1、サーバー 9.6.5) "help"でヘルプを表示します。 userdb=#
>psql -h localhost -p 5432 -U postgres -d userdb
ユーザー postgres のパスワード:
psql (14.1、サーバー 9.6.5)
"help"でヘルプを表示します。
userdb=#

方法2
書式
psql データベース名 ユーザー名

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
>psql userdb postgres
ユーザー postgres のパスワード: #パスワード入力
psql (14.1、サーバー 9.6.5)
"help"でヘルプを表示します。
userdb=#
>psql userdb postgres ユーザー postgres のパスワード: #パスワード入力 psql (14.1、サーバー 9.6.5) "help"でヘルプを表示します。 userdb=#
>psql userdb postgres
ユーザー postgres のパスワード: #パスワード入力
psql (14.1、サーバー 9.6.5)
"help"でヘルプを表示します。

userdb=#

 

PostgreSQL

Posted by arkgame