简体   繁体   English

如何将 postgres pg_class reltablespace 设置为实际值,而不是 0?

[英]How to set postgres pg_class reltablespace to the actual value, not 0?

I need pg_class.reltablespace to be the actual oid of the default tablespace instead of 0. For the existing and future new tables.我需要 pg_class.reltablespace 成为默认表空间的实际 oid 而不是 0。对于现有的和未来的新表。 I know this is per design but I need the actual oid for an automation.我知道这是每个设计,但我需要实际的 oid 来实现自动化。

Ex: This table is on the default namespace例如:此表位于默认命名空间

# select relname,reltablespace from pg_class where relname = '<my table>'   ;
      relname       | reltablespace 
--------------------+---------------
 <my table>         |             0

In my case it need to be "1663":在我的例子中,它需要是“1663”:

# SELECT oid, spcname FROM pg_tablespace where spcname = 'pg_default';
 oid  |  spcname   
------+------------
 1663 | pg_default

Is there a config to change this behavior?是否有配置来更改此行为? Or some modification to the query that gets the tablespace oid或者对获取表空间oid的查询进行一些修改

If the relation's tablespace is 0, that means that the table resides in the default tablespace of the database:如果关系的表空间为 0,则表示该表驻留在数据库的默认表空间中:

SELECT t.oid::regclass,
       CASE WHEN t.reltablespace <> 0
            THEN t.reltablespace
            ELSE d.dattablespace
       END
FROM pg_class AS t
   CROSS JOIN pg_database AS d
WHERE d.datname = current_database()
  AND t.relname = 'mytable';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM