Firebird获取表行数及物理文件体积表示

表的行数

获取Firebird所有表及每个表中记录的总行数
通过sql获取,直接在FlameRobin中的查询窗口运行

set term !! ;
EXECUTE BLOCK 
returns ( stm varchar(60), cnt integer )
as
BEGIN
for select cast('select count(*) from "'||trim(r.RDB$RELATION_NAME)||'"' as varchar(60))
from RDB$RELATIONS r
where (r.RDB$SYSTEM_FLAG is null or r.RDB$SYSTEM_FLAG = 0) and r.RDB$VIEW_BLR is null
order by 1
into :stm
DO
BEGIN
execute statement :stm into :cnt;
suspend;
END
END

表的物理大小

没有找到数据字典,不能通过简单的sql语句获取相应的信息。
可以通过Firebird server版自带的 gstat 命令获取data pages,只能估算表的大小,不精确。
如果有其它方式,请留言涨姿势~
windows 7下gstat使用范例

  1. 进到firebird安装目录的bin文件夹下,应该可以找到gstat.exe
    bin
  2. shift + left click 打开cmd窗口
  3. 运行命令
    gstat c:\sample.GDB -u sysdba -p masterkey -d > statics_data.gst 
    
  4. 在bin目录下可以得到文件 statics_database.gst
  5. 文件示例
Database "c:\sample.GDB"
Database header page information:
	Flags			0
	Checksum		12345
	Generation		453071
	Page size		4096
	ODS version		11.1
	Oldest transaction	451207
	Oldest active		451208
	Oldest snapshot		451208
	Next transaction	451213
	Bumped transaction	1
	Sequence number		0
	Next attachment ID	2384
	Implementation ID	16
	Shadow count		0
	Page buffers		0
	Next header page	0
	Database dialect	3
	Creation date		Jan 16, 2009 12:11:58
	Attributes		force write

    Variable header data:
	*END*


Database file sequence:
File c:\sample.GDB is the only file

Analyzing database pages ...
test (166)
    Primary pointer page: 6401, Index root page: 6402
    Data pages: 7, data page slots: 10, average fill: 57%
    Fill distribution:
	 0 - 19% = 1
	20 - 39% = 1
	40 - 59% = 1
	60 - 79% = 0
	80 - 99% = 4

test2 (128)
    Primary pointer page: 308, Index root page: 309
    Data pages: 129, data page slots: 129, average fill: 93%
    Fill distribution:
	 0 - 19% = 0
	20 - 39% = 0
	40 - 59% = 1
	60 - 79% = 0
	80 - 99% = 128
	...

猜你喜欢

转载自blog.csdn.net/sgs595595/article/details/83106736