X-Original-To: pgsql-admin@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 0C483475A45 for ; Fri, 4 Apr 2003 13:04:04 -0500 (EST) Received: from localhost.localdomain (unknown [65.217.53.66]) by postgresql.org (Postfix) with ESMTP id 5F24E47631F for ; Fri, 4 Apr 2003 13:03:58 -0500 (EST) Received: from thorn.mmrd.com (thorn.mmrd.com [172.25.10.100]) by localhost.localdomain (8.12.8/8.12.5) with ESMTP id h34IfCkj022584; Fri, 4 Apr 2003 13:41:13 -0500 Received: from gnvex001.mmrd.com (gnvex001.mmrd.com [192.168.3.55]) by thorn.mmrd.com (8.11.6/8.11.6) with ESMTP id h34I3sx26437; Fri, 4 Apr 2003 13:03:54 -0500 Received: from camel.mmrd.com ([172.25.5.213]) by gnvex001.mmrd.com with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2653.13) id F3HTL7XV; Fri, 4 Apr 2003 13:03:53 -0500 Subject: Re: Sizes for all databases From: Robert Treat To: Daniel Rubio Cc: pgsql-admin In-Reply-To: <3E885F80.80703@tinet.org> References: <3E885F80.80703@tinet.org> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Mailer: Ximian Evolution 1.0.8 Date: 04 Apr 2003 13:03:53 -0500 Message-Id: <1049479433.8126.151.camel@camel> Mime-Version: 1.0 X-Spam-Status: No, hits=-38.0 required=5.0 tests=BAYES_10,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, REFERENCES,REPLY_WITH_QUOTES,USER_AGENT_XIMIAN autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200304/58 X-Sequence-Number: 8213 This looks pretty neat. Perhaps you can add it to the PostgreSQL Cookbook as well? http://www.brasileiro.net:8080/postgres/cookbook/ Robert Treat On Mon, 2003-03-31 at 10:32, Daniel Rubio wrote: > Hi! >=20 > Not long time ago, I asked the list how to obtain the sizes of all the=20 > databases on my postgres, to have a control on how growths the client's= =20 > applications. >=20 > Now I've found a solution and I thinked that it could be useful for=20 > people working on ISP's offering postgres services or simply as an other= =20 > control utility then I'll put here for those who are interesed. >=20 > 1-The function uses the database_size function that you can find in the= =20 > contrib directory (dbsize) >=20 > 2-Create a table in one of your databases (with plpgsql active and the=20 > addient permissions) with this structure >=20 > CREATE TABLE "mides" ( > "nom" name NOT NULL, > "mida" int4 NOT NULL > ); >=20 > 3-This is the function you must add >=20 > CREATE FUNCTION mides_bds() RETURNS setof mides AS ' > DECLARE > actual mides%ROWTYPE; > treball RECORD; > mida int4; > BEGIN > FOR treball IN SELECT datname FROM pg_database LOOP > SELECT INTO mida database_size(treball.datname); > mida:=3Dmida/1024; > SELECT INTO actual a.datname,mida FROM pg_database a WHERE=20 > a.datname=3Dtreball.datname; > RETURN NEXT actual; > END LOOP; > RETURN actual; > END; > 'LANGUAGE 'plpgsql'; >=20 > 4-Now, if you execute SELECT * FROM mides_bds() you'll obtain the sizes= =20 > in Kb for all your databases >=20 > I hope it's useful for someone else, and once more, sorry for my english > --=20 > ******************************************************** > Daniel Rubio Rodr=EDguez > OASI (Organisme Aut=F2nom Per la Societat de la Informaci=F3) > c/ Assalt, 12 > 43003 - Tarragona > Tef.: 977.244.007 - Fax: 977.224.517 > e-mail: drubio@oasi.org > ******************************************************** >=20 >=20 > ---------------------------(end of broadcast)--------------------------- > TIP 3: if posting/reading through Usenet, please send an appropriate > subscribe-nomail command to majordomo@postgresql.org so that your > message can get through to the mailing list cleanly