PostgreSQL で dbsize をインストールして、DB のサイズを調べる。
% cd src/postgresql-7.3.4/contrib/dbsize % make sed 's,MODULE_PATHNAME,$libdir/dbsize,g' dbsize.sql.in >dbsize.sql gcc -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -fpic -I. -I../../src/include -c -o dbsize.o dbsize.c gcc -shared -o dbsize.so dbsize.o rm dbsize.o %# make install
mkdir /usr/local/pgsql/share/contrib
mkdir /usr/local/pgsql/doc/contrib
/bin/sh ../../config/install-sh -c -m 644 dbsize.sql /usr/local/pgsql/share/contrib
/bin/sh ../../config/install-sh -c -m 755 dbsize.so /usr/local/pgsql/lib
/bin/sh ../../config/install-sh -c -m 644 ./README.dbsize /usr/local/pgsql/doc/contrib
#% less dbsize.sql
CREATE FUNCTION database_size (name) RETURNS bigint
AS '$libdir/dbsize', 'database_size'
LANGUAGE C WITH (isstrict);CREATE FUNCTION relation_size (text) RETURNS bigint
AS '$libdir/dbsize', 'relation_size'
LANGUAGE C WITH (isstrict);
% psql -U postgres testdb -f dbsize.sql
CREATE FUNCTION
CREATE FUNCTION
% psql testdb postgres
Welcome to psql 7.3.4, the PostgreSQL interactive terminal.Type: \copyright for distribution terms
\h for help with SQL commands
\? for help on internal slash commands
\g or terminate with semicolon to execute query
\q to quittestdb=> SELECT database_size('testdb');
database_size
---------------
31813876
(1 row)testdb=>
DB サイズは 31,813,876 bytes
% bc bc 1.06 Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc. This is free software with ABSOLUTELY NO WARRANTY. For details type `warranty'. 31813876/8192 3883
8kbytes で割ると、共有バッファ 3883 必要ということになる。

Leave a comment