LoginSignup
2
2

More than 5 years have passed since last update.

テーブルがUNLOGGEDで作られたものか調べたい - 2016年夏

Last updated at Posted at 2016-08-01

今から4年前に、(UNLOGGED TABLEがサポートされた後だろうか)こんな記事をはてなblogに書いたことがある。
テーブルがUNLOGGEDで作られたものか調べたい

で、そんな記事を書いたことをすっかり忘れていたんだけど、今日、久々にNoboru Saitoさんから『「てゆーか、次のバージョンでPersistent情報を"\d+"とかで表示してくれると嬉しいかも・・・」 状況変わってないですよねー?』
という質問を受けて、改めてPostgreSQL 9.6beta版で調べてみた。

結論から言えば、全然状況は変わってないようです。

test=# \d+
                     List of relations
 Schema |  Name  | Type  | Owner |    Size    | Description 
--------+--------+-------+-------+------------+-------------
 public | test   | table | nuko  | 8192 bytes | 
 public | test_u | table | nuko  | 16 kB      | 
(2 rows)

やっぱり、UNLOGGED TABLEかどうかの情報は出力してくれない。
結局、以前と同じようなVIEWを作るしかないのか。

test=# CREATE VIEW tablelsit_with_persistent AS (SELECT n.nspname as "Schema",
          c.relname as "Name",
          CASE c.relkind 
            WHEN 'r' THEN 'table' 
            WHEN 'v' THEN 'view' 
            WHEN 'i' THEN 'index' 
            WHEN 'S' THEN 'sequence' 
            WHEN 's' THEN 'special' 
            WHEN 'f' THEN 'foreign table' END as "Type",
          pg_catalog.pg_get_userbyid(c.relowner) as "Owner",
          c.relpersistence as "Persistent"
        FROM pg_catalog.pg_class c
             LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
        WHERE c.relkind IN ('r','v','S','f','')
              AND n.nspname <> 'pg_catalog'
              AND n.nspname <> 'information_schema'
              AND n.nspname !~ '^pg_toast'
          AND pg_catalog.pg_table_is_visible(c.oid)
        ORDER BY 1,2);
CREATE VIEW
test=#

で、このVIEWを検索するしかないっぽい。(´・ω・`)

test=# SELECT * FROM tablelsit_with_persistent ;
 Schema |           Name            | Type  | Owner | Persistent 
--------+---------------------------+-------+-------+------------
 public | tablelsit_with_persistent | view  | nuko  | p
 public | test                      | table | nuko  | p
 public | test_u                    | table | nuko  | u
(3 rows)

次バージョンでPersistentを表示するようなパッチの提案をする手もあるかな・・・でも、UNLOGGED使っているユーザってそんなにいないのかな。

2
2
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
2