0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【初心者】PostgreSQLのコマンド類すぐ忘れる

Last updated at Posted at 2021-11-30

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

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?