{"id":2691,"date":"2011-07-06T10:18:12","date_gmt":"2011-07-06T15:18:12","guid":{"rendered":"http:\/\/jianmingli.com\/wp\/?p=2691"},"modified":"2011-07-06T10:18:12","modified_gmt":"2011-07-06T15:18:12","slug":"find-tablespace-usage-for-each-oracle-user-schema","status":"publish","type":"post","link":"https:\/\/jianmingli.com\/wp\/?p=2691","title":{"rendered":"Find Tablespace Usage for Each Oracle User Schema"},"content":{"rendered":"<p>* List each individual tablespace size:<\/p>\n<pre lang=\"sql\">\r\nSET PAGESIZE 100\r\nCOLUMN size_in_mb FORMAT 999999\r\nSELECT tablespace_name, Sum(bytes)\/1024\/1024 AS size_in_mb\r\nFROM dba_segments\r\nGROUP BY tablespace_name\r\nORDER BY tablespace_name;\r\n<\/pre>\n<p>* List tablespace usage for each user.<br \/>\n* Set min_size_mb to limit the minimal tablespace usage to list.<\/p>\n<pre lang=\"sql\">\r\nSET SERVEROUT ON\r\n\r\nDECLARE\r\n  -- Define a record type to hold tablespace information\r\n  TYPE tblspc_info_record_type IS RECORD (\r\n    tblspc_name dba_segments.tablespace_name%TYPE, \r\n    tblspc_size number(6));\r\n\r\n  -- Define a varray type to hold tablepsaces\r\n  TYPE tblspc_infos_varray_type IS VARRAY(1000) \r\n    of tblspc_info_record_type;\r\n\r\n  -- Define a varray type to hold user names\r\n  TYPE usr_names_varray_type IS VARRAY(1000) \r\n    of dba_users.username%TYPE;\r\n\r\n  tblspc_infos tblspc_infos_varray_type;\r\n  usr_names usr_names_varray_type;\r\n  tmp_usr_name dba_users.username%TYPE;\r\n  min_size_mb number(6) := 500;\r\nBEGIN\r\n    SELECT username \r\n    BULK COLLECT INTO usr_names\r\n    FROM dba_users ORDER BY username ASC;\r\n    \r\n    tmp_usr_name := '';\r\n    FOR i IN 1 .. usr_names.count LOOP\r\n      IF tmp_usr_name != usr_names(i) THEN\r\n        DBMS_OUTPUT.PUT(CHR(10));\r\n        DBMS_OUTPUT.PUT_LINE('========= User name: ' \r\n          || usr_names(i) || '============');\r\n      END IF;\r\n      tmp_usr_name := usr_names(i);\r\n\r\n      SELECT tablespace_name, Sum(bytes)\/1024\/1024\r\n      BULK COLLECT INTO tblspc_infos\r\n      FROM dba_segments\r\n      WHERE owner = Upper(usr_names(i))\r\n      GROUP BY tablespace_name\r\n      ORDER BY tablespace_name;\r\n\r\n      FOR j IN 1 .. tblspc_infos.count LOOP\r\n        IF tblspc_infos(j).tblspc_size > min_size_mb THEN\r\n        DBMS_OUTPUT.PUT_LINE('Consumes tablespace ' \r\n          || tblspc_infos(j).tblspc_name \r\n          || ' size: '\r\n          || tblspc_infos(j).tblspc_size || ' MB');\r\n        END IF;\r\n      END LOOP;\r\n    END LOOP;\r\nEND;\r\n\/\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>* List each individual tablespace size: SET PAGESIZE 100 COLUMN size_in_mb FORMAT 999999 SELECT tablespace_name, Sum(bytes)\/1024\/1024 AS size_in_mb FROM dba_segments GROUP BY tablespace_name ORDER BY tablespace_name; * List tablespace usage for each user. * Set min_size_mb to limit the minimal &hellip; <a href=\"https:\/\/jianmingli.com\/wp\/?p=2691\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[35],"tags":[],"class_list":["post-2691","post","type-post","status-publish","format-standard","hentry","category-oracle"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8cRUO-Hp","_links":{"self":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/2691","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2691"}],"version-history":[{"count":7,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/2691\/revisions"}],"predecessor-version":[{"id":2698,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/2691\/revisions\/2698"}],"wp:attachment":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2691"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2691"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2691"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}