LoginSignup
2
1

More than 3 years have passed since last update.

[自分用] PostgreSQLコマンド

Last updated at Posted at 2020-09-08

初心者です。
自分の開発環境用にPostgreSQLコマンドをまとめました。
使うコマンドが増えたら備忘録として随時更新します。

DBの起動

sudo service postgresql start

DBの再起動

sudo service postgresql restart

DBに入る

psql -U <USER_NAME> <DB_NAME>

DB一覧の表示

psql -l
#もしくは
\l

DB切り替え

\c <DB_NAME>

テーブル一覧

\dt

テーブル作成

-- 人間テーブル
create table human_table (
    -- index
    id serial not null primary key,

    -- 姓 文字列型
    first_name varchar(25),

    -- 名 文字列型
    last_name varchar(25),

    -- 年齢 数値型
    age intger,

    -- 作成日時 タイムスタンプ
    create_at timestamp,

    -- 更新日時 タイムスタンプ
    update_at timestamp
);
2
1
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
1