Database Reference
In-Depth Information
The bigger the table, the more files you'll see.
If reltablespace is not zero then the files will be in:
$PGDATADIR/pg_tblspc/{reltablespace}/
{databaseid}/{relfilenode}*
Each file should be 1GB in size, apart from the last file.
The preceding discussion glossed over a few other points, as follows:
F Postgres uses the terms data blocks and pages to refer to the same concept.
Postgres also does that with the terms tuple and row.
F A datablock is 8192 bytes in size, by default, though you can change that if you
re-compile the server yourself, and create a new database.
Function 1
You may want to create an SQL function for this calculation, so you won't need to re-type
it constantly.
CREATE OR REPLACE FUNCTION estimated_row_count(text)
RETURNS bigint
LANGUAGE sql
AS $$
SELECT (CASE WHEN reltuples > 0 THEN
pg_relation_size($1)/(8192*relpages/reltuples)
ELSE 0
END)::bigint
FROM pg_class
WHERE oid = $1::regclass;
$$;
Function 2
CREATE OR REPLACE FUNCTION
pg_relation_size_nolock(tablename regclass)
RETURNS BIGINT
LANGUAGE plpgsql
AS $$
DECLARE
classoutput RECORD;
tsid
INTEGER;
rid
INTEGER;
dbid
INTEGER;
filepath
TEXT;
 
Search WWH ::




Custom Search