2
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-09-27

#PostgreSQLの起動・停止

PostgreSQLのバージョン確認
$ postgres --version

初期化
$ initdb /usr/local/var/postgres -E utf8

データベース・サーバーを起動
$ pg_ctl start -D /usr/local/var/postgres

データベース・サーバーを停止
$ pg_ctl stop -D /usr/local/var/postgres

#PostgreSQLに接続

デフォルトのテーブルに接続
psql -d postgres

テーブルとユーザを指定して接続
psql -d テーブル名 -U ユーザ名

接続解除
\q

#データベース

データベース一覧
\l

データベース選択
\c データベース名;

#テーブル

テーブル一覧の表示(シーケンスも含む)
\d

テーブル一覧の表示(テーブルのみ)
\dt

テーブル構造の表示
\d テーブル名

テーブルのオーナーの変更
alter table テーブル名 owner to オーナー名;

#ユーザー

ユーザー一覧
\du

#スキーマ

スキーマ一覧
\dn

2
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
2
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?