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でよく使うコマンド(随時更新中)

Posted at

ごっちゃになりがちなpsqlで使用するコマンドをまとめました。
自分の忘備録となるので、随時増やしていきます。

テーブルスペース関連

テーブルスペース作成
※前もって、テーブルを作成する場所にはディレクトリを作詞しておく必要がある。

postgres=# CREATE TABLESPACE test_data LOCATION 'D:\bw_data';
CREATE TABLESPACE
postgres=#

テーブルスペースの確認

postgres=# \db
                テーブル空間一覧
       名前        |   所有者    |     場所
-------------------+-------------+--------------
 pg_default        | postgres    |
 pg_global         | postgres    |
 test_data           | postgres    | D:/test_data/
(3 )

テーブルスペースの削除

 drop TABLESPACE <TABLESPACE_NAME>;

スキーマ関連

postgres=# select current_schema;
 current_schema
----------------
 public
(1 )

データベース関連

データベースの選択

\c [データベース名]

データベースから出る

\q

データベースの削除

 drop database <DATABASE_NAME>;

データベースの作成

CREATE database <DATABASE_NAME>;

テーブル関連

テーブルを作成する
※テーブルスペースと紐づかせた記述です。

 CREATE TABLE テーブル名(カラム、データ型) TABLESPACE テーブルスペース名;

テーブルを削除する

DROP TABLE テーブル名;

テーブルの確認

postgres-# \dt
postgres-# \dt (テーブル名をフルで記入);

テーブルカラムの確認

postgres-#\d tablename

                         テーブル"tabelname"
                       |          タイプ          | 照合順序 | Null 値を許容 | デフォルト
-------------------------+--------------------------+----------+---------------+------------
 red                     | bigint                   |          | not null      |
 yellow                  | character varying(10000) |          | not null      |
 blue                    | character varying(10000) |          | not null      |
 green                   | character varying(10000) |          | not null      |
 orange                  | numeric                  |          | not null      |
 black                   | integer                  |          | not null      |
 white                   | character varying(10000) |          | not null      |
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?