Database Research & Development

  • Home
  • NoSQL
    • NoSQL
    • Cassandra
  • Databases
    • Database Theory
    • Database Designing
    • SQL Server Coding Standards
    • SQL Server
    • PostgreSQL
    • MySQL
    • Greenplum
    • Linux
  • Interviews
    • SQL Server Interviews
    • MySQL Interviews
    • SQL Puzzles
  • DBA Scripts
    • SQL Server DBA Scripts
    • PostgreSQL DBA Scripts
    • MySQL DBA Scripts
    • Greenplum DBA Scripts
  • Home
  • Blog Archives !
  • (: Laugh@dbrnd :)
  • Contact Me !
sqlserverinterviews
Home 2017 June Greenplum: Script to find the size and usage statistics of Indexes

Greenplum: Script to find the size and usage statistics of Indexes

This article is half-done without your Comment! *** Please share your thoughts via Comment ***

In this post, I am sharing a script to find the size and usage statistics of Greenplum Indexes. Having the complete knowledge of our database indexes is imperative. We should check the size and usage of indexes.

Recently, I started my work with Greenplum which based on PostgreSQL 8.2, so I am sharing a script to check index usage in Greenplum.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
SELECT
t.schemaname AS schema_name
,t.tablename AS table_name
,indexname AS index_name
,c.reltuples AS num_rows
,pg_size_pretty(pg_relation_size(quote_ident(t.tablename)::text)) AS table_size
,pg_size_pretty(pg_relation_size(quote_ident(indexrelname)::text)) AS index_size
,CASE WHEN indisunique THEN 'Y'
ELSE 'N'
END AS UNIQUE
,idx_scan AS number_of_scans
,idx_tup_read AS tuples_read
,idx_tup_fetch AS tuples_fetched
FROM pg_tables t
LEFT OUTER JOIN pg_class c ON t.tablename=c.relname
LEFT OUTER JOIN
( SELECT c.relname AS ctablename, ipg.relname AS indexname, x.indnatts AS number_of_columns, idx_scan, idx_tup_read, idx_tup_fetch, indexrelname, indisunique FROM pg_index x
JOIN pg_class c ON c.oid = x.indrelid
JOIN pg_class ipg ON ipg.oid = x.indexrelid
JOIN pg_stat_all_indexes psai ON x.indexrelid = psai.indexrelid )
AS t1
ON t.tablename = t1.ctablename;

Jun 8, 2017Anvesh Patel
PostgreSQL: Script to find the count of objects for each Database SchemaGreenplum: Script to find configuration information of Resource Queues
Comments: 2
  1. Suma
    May 24, 2018 at 5:47 am

    Hi Anvesh,

    I need help on this.
    There are so many regular users have udw_prd_connect__r group rle.ally
    Usually regular users should have acccess for udw_prd_connect__sso_r group role to connect to the PRD database.
    Task:- Need to find the only regular users who have access for udw_prd_connect_r incorrectly.
    Need to write a script for this..Below where i am going wrong find out.let me know..Or please if possible modify.

    select rpt.grantee,rpt.rolcanlogin2,rpt.connect_r,rpt.connect_sso_r,
    case
    when rpt.connect_r=TRUE and rpt.connect_sso_r=TRUE then ‘ERROR’
    when rpt.connect_r=FALSE and rpt.connect_sso_r=FALSE then ‘ERROR’
    else ‘OK’ end as “flag”
    from (
    select r.grantee,r.rolcanlogin2,r.grantor,
    case when r.grantor=’udw_prd_connect_r’ then TRUE else FALSE
    end as “connect_r”,
    case when r.grantor=’udw_prd_connect_sso_r’ then TRUE else FALSE
    end as “connect_sso_r”
    from(
    select au2.rolname grantee,au2.rolcanlogin AS rolcanlogin2,au1.rolname grantor,
    au1.rolcanlogin rolcalogin1 from pg_catalog.pg_auth_members m,
    pg_catalog.pg_authid au2 , pg_catalog.pg_authid au1
    where m.roleid=au1.oid and m.member=au2.oid

    This query will not encounter the errors. but it will show the duplicate rows because some users have both roles (udw_prd_connect_r and udw_prd_connect_sso_r) but i need every user should have one row.

    TASK:
    Need to exapand:-
    Regular user should have udw_prd_connect_r
    Service account should not have udw_prd_connect_sso_r

    Please help me out to get proper result.

    Thank you,
    Suma R

    ReplyCancel
  2. Suma
    May 24, 2018 at 5:51 am

    Correct script:-

    select rpt.grantee,rpt.rolcanlogin2,rpt.connect_r,rpt.connect_sso_r,
    case
    when rpt.connect_r=TRUE and rpt.connect_sso_r=TRUE then ‘ERROR’
    when rpt.connect_r=FALSE and rpt.connect_sso_r=FALSE then ‘ERROR’
    else ‘OK’ end as “flag”
    from (
    select r.grantee,r.rolcanlogin2,r.grantor,
    case when r.grantor=’udw_prd_connect_r’ then TRUE else FALSE
    end as “connect_r”,
    case when r.grantor=’udw_prd_connect_sso_r’ then TRUE else FALSE
    end as “connect_sso_r”
    from(
    select au2.rolname grantee,au2.rolcanlogin AS rolcanlogin2,au1.rolname grantor,
    au1.rolcanlogin rolcalogin1 from pg_catalog.pg_auth_members m,
    pg_catalog.pg_authid au2 , pg_catalog.pg_authid au1
    where m.roleid=au1.oid and m.member=au2.oid
    and aq1.rolname in (‘udw_prd_connect_r’,’udw_prd_connect_sso_r’) r
    group by 1,2,3
    ) rpt
    order by 1,2;

    Please help to find out the result.

    ReplyCancel

Leave a Reply to Suma Cancel reply

CAPTCHA
Refresh

*

Anvesh Patel
Anvesh Patel

Database Engineer

June 8, 2017 2 Comments Greenplum, Greenplum DBA ScriptAnvesh Patel, database, database research and development, dbrnd, Greenplum, Greenplum Administrator, Greenplum Error, Greenplum Monitoring, Greenplum Performance Tuning, Greenplum Programming, Greenplum Query, Greenplum Tips and Tricks, index usage, pg_stat_all_indexes, PostgreSQL 8.2, Statistics
About Me!

I'm Anvesh Patel, a Database Engineer certified by Oracle and IBM. I'm working as a Database Architect, Database Optimizer, Database Administrator, Database Developer. Providing the best articles and solutions for different problems in the best manner through my blogs is my passion. I have more than six years of experience with various RDBMS products like MSSQL Server, PostgreSQL, MySQL, Greenplum and currently learning and doing research on BIGData and NoSQL technology. -- Hyderabad, India.

About DBRND !

dbrnd

This is a personal blog (www.dbrnd.com).

Any views or opinions represented in this blog are personal and belong solely to the blog owner and do not represent those of people, institutions or organizations that the owner may or may not be associated with in professional or personal capacity, unless explicitly stated.

Feel free to challenge me, disagree with me, or tell me I’m completely nuts in the comments section of each blog entry, but I reserve the right to delete any comment for any reason whatsoever (abusive, profane, rude, or anonymous comments) - so keep it polite.

The content of this website is protected by copyright. No portion of this website may be copied or replicated in any form without the written consent of the website owner.

Recent Comments !
  • Anvesh Patel { Sure will do... } – May 27, 12:43 PM
  • Anvesh Patel { Great... } – May 27, 12:41 PM
  • Anvesh Patel { Great... } – May 27, 12:39 PM
  • Anvesh Patel { Great... } – May 27, 12:36 PM
  • Anvesh Patel { Great... } – May 27, 12:28 PM
  • Anvesh Patel { Great... } – May 27, 12:27 PM
  • Anvesh Patel { Great... } – May 27, 12:16 PM
  • Older »
Follow Me !
  • facebook
  • linkedin
  • twitter
  • youtube
  • google
  • flickr
© 2015 – 2019 All rights reserved. Database Research & Development (dbrnd.com)
Posting....