什么看起来像在postgresql表分区内的表?我如何调查?

什么看起来像在postgresql表分区内的表?我如何调查?

问题描述:

我试图调查一个数据库膨胀问题,我发现了一个表不完整的问题,我不明白,也找不到调查的方法。如果我错过了显而易见的信息,我很抱歉,我对数据库的知识和经验很少。什么看起来像在postgresql表分区内的表?我如何调查?

PostgreSQL的9.0

我有一个跟踪有关DHCP分配的历史信息的数据库,它有四个表:日志,租赁,池,消息。

每个表都按天分成分区,因此我们可以在30天后删除分区。其中一些分区每天增加> 4M行。

综观大部分分区的给我我所期待的:

dhcplog=> \d+ leases 
               Table "public.leases" 
    Column |   Type   |      Modifiers      | Storage | Description 
------------+--------------------------+-----------------------------------------------------+---------+------------- 
id   | bigint     | not null default nextval('leases_id_seq'::regclass) | plain | 
ip   | inet      |              | main | 
mac  | macaddr     |              | plain | 
start  | timestamp with time zone |              | plain | 
stop  | timestamp with time zone |              | plain | 
switchport | integer     |              | plain | 
Foreign-key constraints: 
    "leases_switchport_fkey" FOREIGN KEY (switchport) REFERENCES switchports(id) 
Child tables: partitions.leases_2014_08_02, 
       partitions.leases_2014_08_03, 
       partitions.leases_2014_08_04, 
       partitions.leases_2014_08_05, 
       partitions.leases_2014_08_06, ... 

但在表中我有什么样子的分区列表中的一部分(另外两个表的引用信息和原木):

dhcplog=> \d+ log 
               Table "public.log" 
Column |   Type   |     Modifiers      | Storage | Description 
---------+--------------------------+--------------------------------------------------+----------+------------- 
id  | bigint     | not null default nextval('log_id_seq'::regclass) | plain | 
date | timestamp with time zone |             | plain | 
host | character varying(30) |             | extended | 
message | character varying(255) |             | extended | 
Child tables: messages, 
       partitions.log_2014_10_01, 
       partitions.log_2014_10_02, ... 
       partitions.log_2014_11_07, 
       pools 

我不能得到一个行数或从这些分区虽然任何信息:

dhcplog=> SELECT count(*) FROM partitions.messages; 
ERROR: relation "partitions.messages" does not exist 
LINE 1: SELECT count(*) FROM partitions.messages; 
          ^

但伯爵对所有其他人都适用。

任何建议/建议?

谢谢。 -sjs

+0

表名是'public.messages'。只需使用'select count(*)from public.messages;'其他表('log_xxx')位于模式'partitions'中。 – 2014-10-31 19:17:48

如果仔细观察\ d + log的输出,您应该注意到子表消息被列为消息而不是partitions.messages。所以查询表partitions.messages是行不通的。

下面应该工作:

SELECT count(*) FROM messages; 
+0

谢谢你注意到这一点。为什么它会出现在表格日志的列表中?这是它自己的表与分区。我不愿意统计整个表格,因为一天有830万条记录。 – 2014-10-31 20:50:09

+0

@SeanSchluntz:“*为什么它会出现在列表中的日志*” - 因为有人像这样创建它:'create table messages(..)inherits(log);' – 2014-10-31 22:46:45

+0

感谢您的帮助。 – 2014-10-31 22:53:02