postgres
差分
このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン前のリビジョン次のリビジョン | 前のリビジョン | ||
postgres [2019/11/27 06:56] – [データ使用量を調べる] nullpon | postgres [2020/01/16 02:45] (現在) – nullpon | ||
---|---|---|---|
行 62: | 行 62: | ||
vacuum full schema_name.table_name; | vacuum full schema_name.table_name; | ||
</ | </ | ||
+ | |||
+ | |||
+ | ===== プロセス ===== | ||
+ | |||
+ | ==== 実行中のプロセス一覧 ==== | ||
+ | |||
+ | < | ||
+ | SELECT * FROM pg_stat_activity; | ||
+ | </ | ||
+ | |||
+ | ==== 実行中のプロセスをkillする ==== | ||
+ | |||
+ | 実行中のジョブを検索してpidを調べて、以下を実行 | ||
+ | |||
+ | < | ||
+ | SELECT pg_cancel_backend(< | ||
+ | </ | ||
+ | |||
+ | ===== lastval ===== | ||
+ | |||
+ | mysqlのlast_insert_idに相当 | ||
+ | |||
+ | < | ||
+ | SELECT lastval(); | ||
+ | </ | ||
+ | |||
+ | ===== truncate ===== | ||
+ | |||
+ | truncateがトランザクション内で実行される。 | ||
+ | |||
+ | <code sql> | ||
+ | test=# begin; | ||
+ | BEGIN | ||
+ | test=# select count(1) from xxx.items; | ||
+ | 100 | ||
+ | test=# truncate test.hoge; | ||
+ | test=# select count(1) from xxx.items; | ||
+ | 0 | ||
+ | test=# rollback; | ||
+ | ROLLBACK | ||
+ | test=# select count(1) from xxx.items; | ||
+ | 100 | ||
+ | </ | ||
+ | |||
+ | `delete from xxx;` の代わりに有り難く利用しよう。deleteの場合、データ領域を解放しないが、truncateは解放するので削除後にvacuumする必要がなくなる。 | ||
+ | |||
+ | ===== copy ===== | ||
+ | |||
+ | データをcsvに出力したり、csvから読み込んだりできる。メタコマンド版と通常コマンド版がある | ||
+ | |||
+ | * メタコマンド版: | ||
+ | * コマンド版: | ||
+ | |||
+ | dockerで動かしている場合などは、ホスト側でpsqlを立ち上げて、メタコマンドで実行するとホスト側とやりとりできる | ||
+ |
postgres.1574837788.txt.gz · 最終更新: 2019/11/27 06:56 by nullpon