1. 程式人生 > >Firebird獲取錶行數及物理檔案體積表示

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