psqlコマンドをすぐ忘れる
postgres12.3環境
OSのコマンド
postgresクライアントで接続
# psql -U postgres -W
Password:
psql (12.8)
Type "help" for help.
postgres=#
DB一覧
# psql -l
クライアントのコマンド
DB一覧
postgres=# \l
DBに接続
postgres=# \c db名
データベース"db名"にユーザ"ユーザ名"として接続しました。
同じデータベースで接続ユーザを変える
postgres=# \c - ユーザ名
別データベースに別ユーザで接続
postgres=# \c データベース名 ユーザ名
DB作成
postgres=# createdb --owner オーナー名 db名
DB削除
postgres=# drop database db名
スキーマ作成
postgres=# create schema スキーマ名 AUTHORIZATION オーナー名
スキーマ削除
postgres=# drop schema スキーマ名 CASCADE
スキーマ一覧
postgres=# \dn
カレントのスキーマを確認
postgres=# select current_schema();
カレントのスキーマの切替え
postgres=# set search_path=スキーマ名;
SET
クライアントのカレントディレクトリを移動する
postgres=# \cd パス
(カレントのスキーマに)DDLを流し込む
postgres=# \i sqlファイルのパス
テーブル一覧
postgres=# \z