2019年6月27日木曜日

PostgreSQLのコマンドメモ

(Linux)ユーザ変更方法

・インストールが完了するとユーザ「postgres(=PostgreSQLのスーパーユーザ)」が自動(勝手に?)追加される
※postgresにユーザ変更する場合はsudoあり、postgresから元に戻る時はsudo無し

$ sudo su - postgres
$ su - USER

PostgreSQL接続

$ psql -h [hostname] -U [username] -d [databasename]

PostgreSQL切断

postgres=# \q

バージョン確認方法

(Linux上から)
$ psql —version
(PostgreSQLから)
postgres=# select version(); 

DB一覧の確認

postgres=# \l

DB作成

ownerの指定は省略可能。省略した場合はownerはpostgresとなる。

postgres=# create database [sample] owner [user];

DB変更

postgres=# \connect [databasenanme];

DB削除

postgres=# \drop database [databasenanme];

テーブル一覧の確認

postgres=# \dt

テーブル作成

postgres=# CREATE TABLE STORE (
postgres=#     store_id     char(6),           -- 店舗ID
postgres=#     store_name   varchar(128),      -- 店舗名
postgres=#     car_space    int,               -- 駐車場台数
postgres=#     area         double precision,  -- 敷地面積
postgres=#     open_date    date               -- オープン日
postgres=# );

テーブル削除

postgres=# \drop table [tablenanme];

テーブル定義修正方法

p
ostgres=# \d [tablenanme];

テーブル名変更方法

postgres=# \alter table [before tablenanme] rename to [after tablename];

ファイルのインポート

postgres=# copy [tablename] from '/home/vagrant/shared/data/hoge.csv' with csv header;

0 件のコメント:

コメントを投稿

FX自動トレード_2021年6月実績

      概要 2021年6月が終わり、FX自動トレードによる収益実績を取り纏めましたので振り返ってみたいと思います。 2021年6月結果 2021年6月の実績は、実利利益額:\66,761、実績利益率は1.42%でした。 今月もボラが全く出ず。利益率の連続過去最低記録更新は免...