2009-06-11 06:12:28 +08:00
|
|
|
/* $PostgreSQL: pgsql/contrib/pg_freespacemap/pg_freespacemap.sql.in,v 1.12 2009/06/10 22:12:28 tgl Exp $ */
|
2007-11-13 12:24:29 +08:00
|
|
|
|
2006-02-12 11:55:53 +08:00
|
|
|
-- Adjust this setting to control where the objects get created.
|
|
|
|
SET search_path = public;
|
|
|
|
|
2006-04-27 06:46:09 +08:00
|
|
|
|
2008-09-30 18:52:14 +08:00
|
|
|
-- Register the C function.
|
2008-10-02 20:20:50 +08:00
|
|
|
CREATE OR REPLACE FUNCTION pg_freespace(regclass, bigint)
|
2008-09-30 18:52:14 +08:00
|
|
|
RETURNS int2
|
|
|
|
AS 'MODULE_PATHNAME', 'pg_freespace'
|
2009-06-11 06:12:28 +08:00
|
|
|
LANGUAGE C STRICT;
|
2006-02-12 11:55:53 +08:00
|
|
|
|
2008-09-30 18:52:14 +08:00
|
|
|
-- pg_freespace shows the recorded space avail at each block in a relation
|
|
|
|
CREATE OR REPLACE FUNCTION
|
2008-10-02 20:20:50 +08:00
|
|
|
pg_freespace(rel regclass, blkno OUT bigint, avail OUT int2)
|
2006-04-27 06:46:09 +08:00
|
|
|
RETURNS SETOF RECORD
|
2008-09-30 18:52:14 +08:00
|
|
|
AS $$
|
2008-10-02 20:20:50 +08:00
|
|
|
SELECT blkno, pg_freespace($1, blkno) AS avail
|
2008-09-30 18:52:14 +08:00
|
|
|
FROM generate_series(0, pg_relation_size($1) / current_setting('block_size')::bigint - 1) AS blkno;
|
|
|
|
$$
|
|
|
|
LANGUAGE SQL;
|
2006-04-27 06:46:09 +08:00
|
|
|
|
|
|
|
|
2006-05-05 04:39:34 +08:00
|
|
|
-- Don't want these to be available to public.
|
2008-10-02 20:20:50 +08:00
|
|
|
REVOKE ALL ON FUNCTION pg_freespace(regclass, bigint) FROM PUBLIC;
|
2008-09-30 18:52:14 +08:00
|
|
|
REVOKE ALL ON FUNCTION pg_freespace(regclass) FROM PUBLIC;
|