{"id":2715,"date":"2018-02-02T22:44:28","date_gmt":"2018-02-02T13:44:28","guid":{"rendered":"http:\/\/haisins.epac.to\/wordpress\/?p=2715"},"modified":"2018-02-02T23:16:16","modified_gmt":"2018-02-02T14:16:16","slug":"dba%ea%b0%80-%ea%b0%80%ec%a7%80%ea%b3%a0-%ec%9e%88%ec%96%b4%ec%95%bc-%ed%95%a0-10%ea%b0%9c%ec%9d%98-sql","status":"publish","type":"post","link":"http:\/\/haisins.synology.me\/wordpress\/?p=2715","title":{"rendered":"DBA\uac00 \uac00\uc9c0\uace0 \uc788\uc5b4\uc57c \ud560 10\uac1c\uc758 SQL"},"content":{"rendered":"<p>=============================================<\/p>\n<p>NO 1: Display the Current Archivelog Status<\/p>\n<p>=============================================<\/p>\n<p>&nbsp;<\/p>\n<p>The command below, when entered via SQLDBA, will display the current archivelog status of the database. The script<\/p>\n<p>will display the active log_archive_dest location, as well as the current and oldest online redo log sequence numbers.<\/p>\n<p>&nbsp;<\/p>\n<p>ARCHIVE LOG LIST;<\/p>\n<p>&nbsp;<\/p>\n<p>===========================================<\/p>\n<p>NO 2: Creating a Control File Trace File<\/p>\n<p>===========================================<\/p>\n<p>&nbsp;<\/p>\n<p>The command below, when entered via SQLDBA, will create a trace file in your trace file destination directory. The<\/p>\n<p>trace file will contain the complete CREATE CONTROLFILE command for the current database, saving you vast<\/p>\n<p>quantities of time if you ever need to generate that command.<\/p>\n<p>&nbsp;<\/p>\n<p>ALTER DATABASE BACKUP CONTROLFILE TO TRACE;<\/p>\n<p>&nbsp;<\/p>\n<p>=============================================<\/p>\n<p>NO 3: Tablespace Free Extents and Free Space<\/p>\n<p>=============================================<\/p>\n<p>&nbsp;<\/p>\n<p>The query below will ONLY work in Oracle7.2 and higher. In previous versions, it was difficult to query<\/p>\n<p>DBA_DATA_FILES and DBA_FREE_SPACE in one query, since both could have multiple rows for each tablespace.<\/p>\n<p>Using 7.2&#8217;s FROM clause subquery feature, you can group the two queries separately, then join them on the<\/p>\n<p>Tablespace_Name value. The result shows the largest free extent in the tablespace, the number of free extents in the<\/p>\n<p>tablespace, the total free space in the tablespace, and the percentage of the tablespace&#8217;s available space that is free.<\/p>\n<p>&nbsp;<\/p>\n<p>column Tablespace_Name format A20<\/p>\n<p>column Pct_Free format 999.99<\/p>\n<p>&nbsp;<\/p>\n<p>select Tablespace_Name,<\/p>\n<p>Max_Blocks,<\/p>\n<p>Count_Blocks,<\/p>\n<p>Sum_Free_Blocks,<\/p>\n<p>100*Sum_Free_Blocks\/Sum_Alloc_Blocks AS Pct_Free<\/p>\n<p>from<\/p>\n<p>(select Tablespace_Name, SUM(Blocks) Sum_Alloc_Blocks<\/p>\n<p>from DBA_DATA_FILES<\/p>\n<p>group by Tablespace_Name),<\/p>\n<p>(select Tablespace_Name FS_TS_NAME,<\/p>\n<p>MAX(Blocks) AS Max_Blocks,<\/p>\n<p>COUNT(Blocks) \u00a0 AS Count_Blocks,<\/p>\n<p>SUM(Blocks) AS Sum_Free_Blocks<\/p>\n<p>from DBA_FREE_SPACE<\/p>\n<p>group by Tablespace_Name)<\/p>\n<p>where Tablespace_Name = FS_TS_NAME;<\/p>\n<p>&nbsp;<\/p>\n<p>================================================<\/p>\n<p>No. 4: Display Allocated Space &amp; Quota by User<\/p>\n<p>================================================<\/p>\n<p>&nbsp;<\/p>\n<p>DBA_TS_QUOTAS displays the allocated space, by user, in each tablespace, along with the quota for each of those<\/p>\n<p>users. If a user has unlimited quota in a tablespace, the quota will be displayed as 0 or negative. Running this script is a<\/p>\n<p>great quick way to see which users own objects in which tablespaces, and how close they are to their quotas. You&#8217;ll<\/p>\n<p>need to SET LINESIZE 132 before running this script.<\/p>\n<p>&nbsp;<\/p>\n<p>select * from DBA_TS_QUOTAS<\/p>\n<p>order by Tablespace_Name, Username;<\/p>\n<p>&nbsp;<\/p>\n<p>================================================<\/p>\n<p>No. 5: Show Allocated Storage for All Objects<\/p>\n<p>================================================<\/p>\n<p>&nbsp;<\/p>\n<p>DBA_SEGMENTS shows the allocated storage for all objects in the database. Valid values for the &amp;segment_type<\/p>\n<p>variable include:<\/p>\n<p>&nbsp;<\/p>\n<p>TEMPORARY&#8211;for currently used temporary segments. Watch them grow!<\/p>\n<p>ROLLBACK&#8211;for rollback segments<\/p>\n<p>INDEX&#8211;for indexes<\/p>\n<p>TABLE&#8211;for tables<\/p>\n<p>&nbsp;<\/p>\n<p>There is one record in DBA_SEGMENTS for each segment. There is a one-to-many relationship between<\/p>\n<p>DBA_SEGMENTS and DBA_EXTENTS: DBA_SEGMENTS shows you the total space allocated to a segment;<\/p>\n<p>DBA_EXTENTS shows the space allocated to each extent within the segment.<\/p>\n<p>&nbsp;<\/p>\n<p>column Segment_Name format A40<\/p>\n<p>&nbsp;<\/p>\n<p>select Segment_Name, Extents, Blocks<\/p>\n<p>from DBA_SEGMENTS<\/p>\n<p>where Segment_Type = &#8216;&amp;segment_type&#8217;<\/p>\n<p>order by Segment_Name;<\/p>\n<p>&nbsp;<\/p>\n<p>==============================================<\/p>\n<p>No. 6: Map a Tablespace&#8217;s Used and Free Space<\/p>\n<p>==============================================<\/p>\n<p>&nbsp;<\/p>\n<p>Since DBA_EXTENTS shows the starting block of each extent (the combination of File_ID and Block_ID), plus the<\/p>\n<p>length of each extent (the Blocks column), you can map out the allocated space within a given tablespace as a series of<\/p>\n<p>consecutive extents. DBA_FREE_SPACE shows the free extents, so the combination of DBA_EXTENTS and<\/p>\n<p>DBA_FREE_SPACE produces a map of the used and unused free space within a tablespace. You can use this map of<\/p>\n<p>the tablespace&#8217;s space to determine whether an object has been properly sized or if the tablespace needs to be<\/p>\n<p>defragmented.<\/p>\n<p>&nbsp;<\/p>\n<p>select Segment_Name, File_Id, Block_Id, Blocks<\/p>\n<p>from DBA_EXTENTS<\/p>\n<p>where Tablespace_Name = &#8216;&amp;&amp;tablespacename&#8217;<\/p>\n<p>UNION<\/p>\n<p>select &#8216;Free Space&#8217;, File_Id, Block_Id, Blocks<\/p>\n<p>from DBA_FREE_SPACE<\/p>\n<p>where Tablespace_Name = &#8216;&amp;&amp;tablespacename&#8217;<\/p>\n<p>order by 2,3;<\/p>\n<p>&nbsp;<\/p>\n<p>=======================================<\/p>\n<p>No. 7: Blocks Used by Data in a Table<\/p>\n<p>=======================================<\/p>\n<p>&nbsp;<\/p>\n<p>When you replace &#8220;sometable&#8221; with the name of a table in your database, the query below will return the number of<\/p>\n<p>blocks used by the data in that table. The query examines the Block_ID (columns 1-8) and the File_ID (columns 15-18)<\/p>\n<p>of the ROWID. The query then returns the number of distinct blocks used by the records within the table. The<\/p>\n<p>ANALYZE command can also provide this information, but this query is faster.<\/p>\n<p>&nbsp;<\/p>\n<p>select COUNT(DISTINCT(SUBSTR(ROWID,1,8)||SUBSTR(ROWID,15,4)))<\/p>\n<p>Blocks_Used<\/p>\n<p>from sometable;<\/p>\n<p>&nbsp;<\/p>\n<p>================================<\/p>\n<p>No. 8: Reset a User&#8217;s Password<\/p>\n<p>================================<\/p>\n<p>&nbsp;<\/p>\n<p>The script below generates an ALTER USER command that will reset a user&#8217;s password (the user whose username is<\/p>\n<p>passed to the script as &amp;&amp;1). If you spool the output of this command, you will be able to reset the user&#8217;s password<\/p>\n<p>without ever having to know what the password was. You can change the user&#8217;s password to anything you like, use the<\/p>\n<p>account for testing purposes, and then reset the password when your testing is complete. For a detailed discussion, see<\/p>\n<p>Chapter 9 of the Oracle DBA Handbook.<\/p>\n<p>&nbsp;<\/p>\n<p>select &#8216;ALTER USER &amp;&amp;1 IDENTIFIED BY VALUES &#8216;<\/p>\n<p>||&#8221;&#8221;||Password||&#8221;&#8221;||&#8217;;&#8217;<\/p>\n<p>from DBA_USERS where Username = UPPER(&#8216;&amp;&amp;1&#8217;);<\/p>\n<p>&nbsp;<\/p>\n<p>=========================<\/p>\n<p>No. 9: Query V$PARAMETER<\/p>\n<p>=========================<\/p>\n<p>&nbsp;<\/p>\n<p>Don&#8217;t try to guess what parameters are in effect. You can never tell for sure which INIT.ORA file was used to start an<\/p>\n<p>instance, or if the INIT.ORA file has been modified since the database was started. The only sure way to tell the setting<\/p>\n<p>of an initialization parameter is to query V$PARAMETER.<\/p>\n<p>&nbsp;<\/p>\n<p>column Name format A50<\/p>\n<p>column Value format A28<\/p>\n<p>&nbsp;<\/p>\n<p>select Name, Value from V$PARAMETER;<\/p>\n<p>&nbsp;<\/p>\n<p>======================================<\/p>\n<p>No. 10: Show Statement Execution Path<\/p>\n<p>======================================<\/p>\n<p>&nbsp;<\/p>\n<p>This query selects the execution path from the PLAN_TABLE, ordered according to the hierarchy of the steps<\/p>\n<p>involved. The query shown in the listing specifically queries for the execution path of a statement using the<\/p>\n<p>Statement_ID of &#8216;TEST&#8217;. Prior to running this query, you should use the EXPLAIN PLAN command to populate<\/p>\n<p>PLAN_TABLE.<\/p>\n<p>&nbsp;<\/p>\n<p>select<\/p>\n<p>LPAD(&#8216; &#8216;,2*LEVEL)||Operation||&#8217; &#8216;||Options<\/p>\n<p>||&#8217; &#8216;||Object_Name \u00a0 Q_PLAN<\/p>\n<p>from PLAN_TABLE<\/p>\n<p>where Statement_ID = &#8216;TEST&#8217;<\/p>\n<p>connect by prior ID = Parent_ID and Statement_ID = &#8216;TEST&#8217;<\/p>\n<p>start with ID=1;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>============================================= NO 1: Display the Current Archivelog Status ============================================= &nbsp; The command below, when entered via SQLDBA, will display the current archivelog status of the database. The script will display the active log_archive_dest location, as well as the current and oldest online redo log sequence numbers. &nbsp; ARCHIVE LOG LIST; &nbsp; =========================================== NO 2: Creating [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2410,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"spay_email":""},"categories":[3],"tags":[902,903],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/haisins.synology.me\/wordpress\/wp-content\/uploads\/2018\/01\/databaetail.jpg?fit=905%2C480","amp_enabled":true,"_links":{"self":[{"href":"http:\/\/haisins.synology.me\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/2715"}],"collection":[{"href":"http:\/\/haisins.synology.me\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/haisins.synology.me\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/haisins.synology.me\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/haisins.synology.me\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2715"}],"version-history":[{"count":1,"href":"http:\/\/haisins.synology.me\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/2715\/revisions"}],"predecessor-version":[{"id":2716,"href":"http:\/\/haisins.synology.me\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/2715\/revisions\/2716"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/haisins.synology.me\/wordpress\/index.php?rest_route=\/wp\/v2\/media\/2410"}],"wp:attachment":[{"href":"http:\/\/haisins.synology.me\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2715"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/haisins.synology.me\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2715"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/haisins.synology.me\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2715"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}