PostgreSQL La base de donnees la plus sophistiquee au monde.

Forums PostgreSQL.fr

Le forum officiel de la communauté francophone de PostgreSQL

Vous n'êtes pas identifié(e).

#1 04/06/2010 17:11:33

mich30
Membre

vacuum analyse par schema

bbonjour
je veux rentrer le nom du  schema
et patiner toutes les tables pour faire un 'VACUUM ANALYSE
mais erreur

ERROR:  VACUUM cannot be executed from a function
CONTEXT:  SQL statement "VACUUM ANALYSE rga.rga2000_04"
PL/pgSQL function "fct_vacuum_by_schema" line 30 at execute statement

********** Erreur **********

ERROR: VACUUM cannot be executed from a function
État SQL :25001
Contexte : SQL statement "VACUUM ANALYSE rga.rga2000_04"
PL/pgSQL function "fct_vacuum_by_schema" line 30 at execute statement


Merci

CREATE OR REPLACE FUNCTION fct_vacuum_by_schema
(v_name_schema character varying)
  RETURNS void AS
$BODY$

DECLARE
    l_va_schema varchar; /* Nom du schema*/
    l_va_table varchar;  /* Nom tables du schema */
    l_va_tmp  varchar;


    /* Requete extrait toutes les tables d'un schema*/
     c_com CURSOR for SELECT  distinct info.table_schema,info.table_name  from
     (select c.*, pc.*, pc.oid as oid
     from pg_catalog.pg_class as pc, information_schema.columns as c
     where pc.relname=c.table_name and c.table_schema != 'information_schema' 
     and c.table_schema != 'pg_catalog') as info
     LEFT OUTER JOIN
     (SELECT pc.*, PD.* FROM pg_catalog.pg_description PD right outer join pg_catalog.pg_class PC
     on PD.objoid = PC.oid AND PD.objsubid = 0 ) as pde on info.oid = pde.objoid
     where
     info.table_schema =     ''||  quote_ident($1)  || ''; 

BEGIN

  /* Ouverture Curseur*/
  open c_com;
LOOP
FETCH c_com into l_va_schema,l_va_table;
IF l_va_table IS NOT NULL then

      l_va_tmp:='';
      l_va_tmp := 'VACUUM ANALYSE ' || trim(l_va_schema) ||'.'|| trim(l_va_table);
      EXECUTE l_va_tmp;
      RAISE NOTICE ' Traitement --->  %', l_va_tmp;
END IF;
EXIT WHEN NOT FOUND;

END LOOP;
/* Fermeture Curseur*/
RAISE NOTICE ' FIN VACUUM ANALYSE  %', l_va_table;

CLOSE c_com;
END;
$BODY$
  LANGUAGE 'plpgsql' VOLATILE;
ALTER FUNCTION fct_genere_trigger(character varying, character varying) OWNER TO "admin";

select acl_admin.fct_vacuum_by_schema('rga');

Hors ligne

#2 04/06/2010 17:22:00

Marc Cousin
Membre

Re : vacuum analyse par schema

ERROR:  VACUUM cannot be executed from a function

Je ne vois pas quoi rajouter


Marc.

Hors ligne

#3 04/06/2010 17:41:56

mich30
Membre

Re : vacuum analyse par schema

ah c'est dommage alors creer un fichier texte de script ?
merci

Hors ligne

#4 04/06/2010 18:38:37

Marc Cousin
Membre

Re : vacuum analyse par schema

Oui.


Marc.

Hors ligne

#5 05/06/2010 00:15:51

mich30
Membre

Re : vacuum analyse par schema

RAISE NOTICE ' Traitement --->  %', l_va_tmp;
comment fait t'on pour afficher à l'ecran que l_va_tmp
et qui'l n'y ai pas raise notice devant ?

Hors ligne

#6 05/06/2010 10:01:30

gleu
Administrateur

Re : vacuum analyse par schema

On ne peut pas empêcher l'affichage du NOTICE.


Guillaume.

Hors ligne

#7 28/06/2010 14:34:17

floriaan60
Membre

Re : vacuum analyse par schema

bonjour,
peut on empêcher l'affichage des messages contexte ??

Hors ligne

Pied de page des forums