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?

PostgreSQLのコマンド

2
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/postgresql@18

データベースサーバーを停止
$ pg_ctl stop -D /usr/local/var/postgresql@18

PostgreSQL に接続

デフォルトのデータベースに接続
psql -d postgres

データベースとユーザーを指定して接続
psql -d データベース名 -U ユーザ名

パスワードを入力して接続
psql -U ユーザ名 -d データベース名 -W

接続解除
\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?