Re: [GENERAL] Run analyze on schema

From: Suresh Raja <suresh(dot)rajaabc(at)gmail(dot)com>
To: Jerry Sievers <gsievers19(at)comcast(dot)net>
Cc: pgsql-general(at)postgresql(dot)org, pgsql-sql(at)postgresql(dot)org
Subject: Re: [GENERAL] Run analyze on schema
Date: 2015-06-24 03:34:05
Message-ID: CAJP7dtDo3ivr72PPx=hf6FjfWJMfKKKTspow=bwHCPzfhypg6w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-sql

On Mon, Jun 22, 2015 at 6:53 PM, Jerry Sievers <gsievers19(at)comcast(dot)net>
wrote:

> Suresh Raja <suresh(dot)rajaabc(at)gmail(dot)com> writes:
>
> > Hi All:
> >
> > Does postgresql support schema analyze. I could not find
> > analyze schema anywhere. Can we create a function to run
> > analyze and reindex on all objects in the schema. Any
> > suggestions or ideas.
>
> Yes "we" certainly can...
>
> begin;
>
> create function foo(sch text)
> returns void as
>
> $$
> declare sql text;
>
> begin
>
> for sql in
> select format('analyze verbose %s.%s', schemaname, tablename) from
> pg_tables
> where schemaname = sch
>
> loop execute sql; end loop;
>
> end
> $$ language plpgsql;
>
> select foo('public');
> select foo('pg_catalog');
>
>
> -- Enjoy!!
>
> >
> > Thanks,
> > -Suresh Raja
> >
>
> --
> Jerry Sievers
> Postgres DBA/Development Consulting
> e: postgres(dot)consulting(at)comcast(dot)net
> p: 312.241.7800
>

Thanks Jerry!

I too your example and added exception handling into it.

Thanks

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Yelai, Ramkumar IN BLR STS 2015-06-24 05:27:25 Pgbouncer compile in VS2013
Previous Message George Weaver 2015-06-24 02:09:54 Re: native api or odbc?

Browse pgsql-sql by date

  From Date Subject
Next Message gmb 2015-06-29 07:43:18 Disable Trigger for session only
Previous Message Jerry Sievers 2015-06-22 23:53:59 Re: Run analyze on schema