X-Original-To: pgsql-admin@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 44CC147652A for ; Mon, 31 Mar 2003 10:41:01 -0500 (EST) Received: from nil.tinet.org (tinet.org [195.77.216.130]) by postgresql.org (Postfix) with ESMTP id E72324766F4 for ; Mon, 31 Mar 2003 10:32:40 -0500 (EST) Received: from tinet.org ([195.76.233.3]) by nil.tinet.org (Netscape Messaging Server 4.1) with ESMTP id HCMDUI03.C1K for ; Mon, 31 Mar 2003 17:32:42 +0200 Message-ID: <3E885F80.80703@tinet.org> Date: Mon, 31 Mar 2003 17:32:16 +0200 From: Daniel Rubio User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.2) Gecko/20021120 Netscape/7.01 X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-admin Subject: Sizes for all databases Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, hits=-12.1 required=5.0 tests=BAYES_10,USER_AGENT_MOZILLA_UA autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200303/494 X-Sequence-Number: 8134 Hi! 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. 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. 1-The function uses the database_size function that you can find in the=20 contrib directory (dbsize) 2-Create a table in one of your databases (with plpgsql active and the=20 addient permissions) with this structure CREATE TABLE "mides" ( "nom" name NOT NULL, "mida" int4 NOT NULL ); 3-This is the function you must add 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'; 4-Now, if you execute SELECT * FROM mides_bds() you'll obtain the sizes=20 in Kb for all your databases 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 ********************************************************