3
4

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) テーブル情報を取得するSQL 等

Last updated at Posted at 2017-04-25

たまに使う構文・SQLいろいろ

pg_hba.conf の場所を調べる

psql -U postgres -c 'SHOW hba_file;';
SELECT 
        * 
FROM 
        information_schema.columns 
WHERE 
        table_name = 'テーブル名' 
ORDER BY 
        ordinal_position;

クライアントエンコーディングを指定してcsv出力

SET CLIENT_ENCODING TO 'euc_jp';
copy (select * from hoge where ...) to '/tmp/dump.csv' (format csv);

タイムゾーン変換

select current_date at time zone 'Asia/Tokyo'

時間のかかっている実行中クエリーをすべてキャンセル

psql -c "SELECT pg_cancel_backend(pid) FROM pg_stat_activity WHERE state='active' and query_start < current_timestamp - interval '1 minutes';"
3
4
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
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?