Wednesday, 14 August 2024

Generate the drop sql command - Query

 

/*Generate the drop sql command*/
———————————————————————————————————–

select case when pgc.relname like ‘%_index’
then ‘drop index ‘ || pgns.nspname || ‘.’ || pgc.relname || ‘;’
else ‘drop table ‘ || pgns.nspname || ‘.’ || pgc.relname || ‘;’ end as drop_query
from pg_class pgc
join pg_namespace pgns on pgc.relnamespace = pgns.oid
where pg_is_other_temp_schema(pgc.relnamespace)
and pgc.relname not like ‘%toast%’;

No comments:

Post a Comment

Master and Slave - Sync check - PostgreSQL

  1) Run the below Query on Primary:- SELECT     pid,     usename,     application_name,     client_addr,     state,     sync_state,     sen...