[tibero@T1:/home/tibero]$ tbsql sys/tibero
tbSQL 7
TmaxTibero Corporation Copyright (c) 2020-. All rights reserved.
Connected to Tibero.
SQL> SELECT VALUE FROM V$PARAMETERS WHERE NAME='WTHR_PER_PROC';
VALUE
--------------------------------------------------------------------------------
10
1 row selected.
SQL> SELECT NAME FROM V$DATAFILE;
NAME
--------------------------------------------------------------------------------
/tibero/tbdata/tibero/system001.dtf
/tibero/tbdata/tibero/undo001.dtf
/tibero/tbdata/tibero/usr001.dtf
/tibero/tbdata/tibero/syssub001.dtf
/tibero/tbdata/my_file001.dtf
5 rows selected.
SQL> SELECT MEMBER FROM V$LOGFILE;
MEMBER
--------------------------------------------------------------------------------
/tibero/tbdata/tibero/log01.log
/tibero/tbdata/tibero/log11.log
/tibero/tbdata/tibero/log21.log
/tibero/tbdata/tibero/log31.log
/tibero/tbdata/tibero/log32.log
5 rows selected.
SQL> SELECT NAME FROM V$CONTROLFILE;
NAME
--------------------------------------------------------------------------------
/tibero/tbdata/tibero/c1.ctl
/tibero/tbdata/tibero/c2.ctl
2 rows selected.
SQL> SELECT LOG_MODE FROM V$DATABASE;
LOG_MODE
------------
ARCHIVELOG
1 row selected.
SQL> LS USER
USERNAME
--------------------------------------------------------------------------------
SYS
SQL>
SQL> -- 테이블 생성 및 조회, 이미 생성된 유저들 티베로 쪽에 접속해서 사용해라.
SQL> SELECT USERNAME FROM DBA_USERS;
USERNAME
--------------------------------------------------------------------------------
SYS
SYSCAT
SYSGIS
OUTLN
TIBERO
TIBERO1
6 rows selected.
SQL> LS USER
USERNAME
--------------------------------------------------------------------------------
SYS
SQL> CONNECT TIBERO/TMAX -> 기존의 세션을 끊고 새로운 세션을 연결한다.
Connected to Tibero.
SQL> LS USER
USERNAME
--------------------------------------------------------------------------------
TIBERO
SQL> CREATE TABLE PRODUCT (
PROD_ID NUMBER(6),
PROD_NAME VARCHAR(50),
PROD_COST VARCHAR(30),
PROD_PID NUMBER(6),
PROD_DATE DATE
)
TABLESPACE MY_SPACE
PCTFREE 5
INITRANS 3; 2 3 4 5 6 7 8 9 10
Table 'PRODUCT' created.
SQL>
SQL> DESC USER_TABLES
COLUMN_NAME TYPE CONSTRAINT
---------------------------------------- ----------------- - --------------------
TABLE_NAME VARCHAR(128)
TABLESPACE_NAME VARCHAR(128)
PCT_FREE NUMBER
INI_TRANS NUMBER
LOGGING VARCHAR(3)
NUM_ROWS NUMBER
BLOCKS NUMBER
AVG_ROW_LEN NUMBER
DEGREE NUMBER
SAMPLE_SIZE NUMBER
LAST_ANALYZED DATE
PARTITIONED VARCHAR(3)
BUFFER_POOL VARCHAR(7)
ROW_MOVEMENT VARCHAR(8)
DURATION VARCHAR(11)
COMPRESSION VARCHAR(3)
COMPRESS_FOR VARCHAR(12)
DROPPED VARCHAR(3)
READ_ONLY VARCHAR(3)
TEMPORARY VARCHAR(3)
MAX_EXTENTS NUMBER
IOT_TYPE VARCHAR(12)
INITIAL_EXTENT NUMBER
NEXT_EXTENT NUMBER
MIN_EXTENTS NUMBER
IS_VIRTUAL VARCHAR(1)
INMEMORY VARCHAR(8)
INMEMORY_PRIORITY VARCHAR(8)
INMEMORY_DISTRIBUTE VARCHAR(15)
INMEMORY_COMPRESSION VARCHAR(14)
INMEMORY_DUPLICATE VARCHAR(13)
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL> COL TABLE_NAME FOR A15
SQL> COL TABLESPACE_NAME FOR A15
SQL> SELECT TABLE_NAME, TABLESPACE_NAME FROM USER_TABLES;
TABLE_NAME TABLESPACE_NAME
--------------- ---------------
PRODUCT MY_SPACE
1 row selected.
SQL> ED
Wrote file .tbedit.sql
1 SELECT TABLE_NAME, TABLESPACE_NAME,INI_TRANS,PCT_FREE
2 FROM USER_TABLES
SQL> /
TABLE_NAME TABLESPACE_NAME INI_TRANS PCT_FREE
--------------- --------------- ---------- ----------
PRODUCT MY_SPACE 3 5
1 row selected.
SQL> DROP TABLE PRODUCT;
Table 'PRODUCT' dropped.
SQL> SELECT TABLE_NAME, TABLESPACE_NAME,INI_TRANS,PCT_FREE
2 FROM USER_TABLES
3 ;
0 row selected.
SQL> ED
Wrote file .tbedit.sql
1 CREATE TABLE PRODUCT (
2 PROD_ID NUMBER(6),
3 PROD_NAME VARCHAR(50),
4 PROD_COST VARCHAR(30),
5 PROD_PID NUMBER(6),
6 PROD_DATE DATE
7 )
SQL> /
Table 'PRODUCT' created.
SQL> SELECT TABLE_NAME, TABLESPACE_NAME,INI_TRANS,PCT_FREE
2 FROM USER_TABLES;
TABLE_NAME TABLESPACE_NAME INI_TRANS PCT_FREE
--------------- --------------- ---------- ----------
PRODUCT USR 2 10
1 row selected.
SQL> ed
Wrote file .tbedit.sql
1 SELECT TABLE_NAME,BLOCKS,NUM_ROWS,LAST_ANALYZED
2 FROM USER_TABLES
SQL> /
TABLE_NAME BLOCKS NUM_ROWS
--------------- ---------- ----------
LAST_ANALYZED
---------------------------------------------------------- ----------------------
PRODUCT 0 0
1 row selected.
SQL> COL LAST_ANALYZED FOR A25
SQL> ED
Wrote file .tbedit.sql
1 SELECT TABLE_NAME,BLOCKS,NUM_ROWS,LAST_ANALYZED
2 FROM USER_TABLES
-> 테이블에 대한 통계 정보
몇개의 블럭을 점유하고 있냐, 예약하고 있는 공간, 테이블스페이스에 속해 있는 데이터 파일의 블록 공간, 사용하고 있는냐, 몇건의 데이터를 보관하고 있느냐, 통계 정보 수집을 언제 확인하였냐
실행 계획을 만드는 과정에서 통계정보가 사용된다. 없을 경우에는 다이나믹하게 즉시 블록에 접근해서 샘플링을
통해 추정을 하여 실행계획을 만들고 사용한다.(데이터가 적을 경우에만.)
중요하다!
어떻게 통계정보 수집을 하냐? -> 자동이 아니다.(큰 부하가 발생하기 때문에) 사용자가 만져줘야한다.
어떤 방식으로 수집할 것인지 사용자가 정의를 해서.
티베로 메뉴얼 -> 프로시저를 통해서
티베로 tbPSM 참조 안내서 -> 시스템 패키지에 관한 내용(여러 함수와, 프로시저)
통계정보 수집에 관련된 내용 -> DBMS STATS(statistic information), 패키지 타입의 데이터베이스 객체
45.3.24 gather_table_stats를 활용한다.
SQL> /
TABLE_NAME BLOCKS NUM_ROWS LAST_ANALYZED
--------------- ---------- ---------- -------------------- -----
PRODUCT 0 0
1 row selected.
SQL> SELECT * FROM PRODUCT;
0 row selected.
SQL>
SQL>
SQL>
SQL> EXECUTE DBMS_STATS.GATHER_TABLE_STATS('TIBERO','PRODUCT');
PSM completed.
SQL> SELECT TABLE_NAME,BLOCKS,NUM_ROWS,LAST_ANALYZED
2 FROM USER_TABLES;
TABLE_NAME BLOCKS NUM_ROWS LAST_ANALYZED
--------------- ---------- ---------- -------------------------
PRODUCT 0 0 2023/04/10
1 row selected.
SQL> ed
Wrote file .tbedit.sql
1 SELECT TABLE_NAME,BLOCKS,NUM_ROWS,TO_CHAR(LAST_ANALYZED,'YYYYMMDD HH24:MI:SS')
2 FROM USER_TABLES
SQL> /
TABLE_NAME BLOCKS NUM_ROWS
--------------- ---------- ----------
TO_CHAR(LAST_ANALYZED,'YYYYMMDDHH24:MI:SS')
-------------------------------------------
PRODUCT 0 0
20230410 14:16:54
1 row selected.
SQL> INSERT INTO PRODUCT(PROD_ID) VALUES(1);
1 row inserted.
SQL> COMMIT;
Commit completed.
SQL> SELECT TABLE_NAME,BLOCKS,NUM_ROWS,TO_CHAR(LAST_ANALYZED,'YYYYMMDD HH24:MI:SS') FROM USER_TABLES;
TABLE_NAME BLOCKS NUM_ROWS
--------------- ---------- ----------
TO_CHAR(LAST_ANALYZED,'YYYYMMDDHH24:MI:SS')
-------------------------------------------
PRODUCT 0 0
20230410 14:16:54
1 row selected.
SQL> EXECUTE DBMS_STATS.GATHER_TABLE_STATS('TIBERO','PRODUCT');
PSM completed.
SQL> SELECT TABLE_NAME,BLOCKS,NUM_ROWS,TO_CHAR(LAST_ANALYZED,'YYYYMMDD HH24:MI:SS') FROM USER_TABLES;
TABLE_NAME BLOCKS NUM_ROWS
--------------- ---------- ----------
TO_CHAR(LAST_ANALYZED,'YYYYMMDDHH24:MI:SS')
-------------------------------------------
PRODUCT 16 1
20230410 14:23:25
1 row selected.
-> 1이 들어가 있고 나머지는 아마 비어있겠지? 다른 것은 사용할 수 없다. 예약이 되어 있는 것이다. 가득차면 또 다른 EXTENT를 할당 받는다.
SQL>
SQL> DESC USER_TBL_COLUMNS;
COLUMN_NAME TYPE CONSTRAINT
---------------------------------------- ------------------ --------------------
TABLE_NAME VARCHAR(128)
COLUMN_NAME VARCHAR(128)
DATA_TYPE VARCHAR(128)
DATA_TYPE_OWNER VARCHAR(128)
DATA_LENGTH NUMBER
DATA_PRECISION NUMBER
DATA_SCALE NUMBER
NULLABLE VARCHAR(1)
COLUMN_ID NUMBER
DATA_DEFAULT LONG
DEFAULT_LENGTH NUMBER
CHAR_COL_DECL_LENGTH NUMBER
CHAR_LENGTH NUMBER
CHAR_USED VARCHAR(1)
VIRTUAL_COLUMN VARCHAR(1)
SQL> SELECT COLUMN_NAME FROM USER_TBL_COLUMNS;
COLUMN_NAME
--------------------------------------------------------------------------------
PROD_ID
PROD_NAME
PROD_COST
PROD_PID
PROD_DATE
SQL> desc v$session
COLUMN_NAME TYPE CONSTRAINT
---------------------------------------- ------------------ --------------------
SID NUMBER
SERIAL# NUMBER
AUDSID NUMBER
USER# NUMBER
USERNAME VARCHAR(128)
IPADDR VARCHAR(46)
COMMAND NUMBER
STATUS VARCHAR(32)
SCHEMA# NUMBER
SCHEMANAME VARCHAR(128)
TYPE VARCHAR(15)
SQL_ID VARCHAR(13)
SQL_CHILD_NUMBER NUMBER
PREV_SQL_ID VARCHAR(13)
PREV_CHILD_NUMBER NUMBER
SQL_ET NUMBER
LOGON_TIME DATE
STATE VARCHAR(25)
WLOCK_WAIT VARCHAR(18)
WAIT_EVENT NUMBER
WAIT_TIME NUMBER
PGA_USED_MEM NUMBER
SQL_TRACE VARCHAR(8)
PROG_NAME VARCHAR(30)
CLIENT_PID NUMBER
PID NUMBER
WTHR_ID NUMBER
OS_THR_ID NUMBER
OSUSER VARCHAR(128)
MACHINE VARCHAR(64)
TERMINAL VARCHAR(15)
MODULE VARCHAR(64)
ACTION VARCHAR(64)
CLIENT_INFO VARCHAR(64)
CLIENT_IDENTIFIER VARCHAR(64)
PDML_ENABLED VARCHAR(3)
PDML_STATUS VARCHAR(8)
PDDL_STATUS VARCHAR(8)
PQ_STATUS VARCHAR(8)
ROW_WAIT_OBJ_ID NUMBER
ROW_WAIT_FILE_NO NUMBER
ROW_WAIT_BLOCK_NO NUMBER
ROW_WAIT_ROW_NO NUMBER
CONSUMER_GROUP VARCHAR(32)
CONSUMED_CPU_TIME NUMBER
SQL> show all
PARAMETER VALUE
---------------- ---------------------------------------------------------------
AUTOCOMMIT OFF
AUTOTRACE OFF
BLOCKTERMINATOR "." (0x2E)
COLSEP " " (0x20)
CONCAT "." (0x2E)
DDLSTATS OFF
DEFINE "&" (0x26)
DESCRIBE DEPTH 10
ECHO OFF
EDITFILE ".tbedit.sql"
ESCAPE OFF
EXITCOMMIT ON
FEEDBACK 0
HEADING ON
HEADSEP "|" (0x7C)
HISTORY 50
INTERVAL 1
LINESIZE 80
LONG 80
MARKUP HTML OFF HEAD "<style type='text/css'> body {font:10pt Arial,He
lvetica,sans-serif; color:black; background:White;} p {font:10p
t Arial,Helvetica,sans-serif; color:black; background:White;} t
able,tr,td {font:10pt Arial,Helvetica,sans-serif; color:Black;
background:#f7f7e7; padding:0px 0px 0px 0px; margin:0px 0px 0px
0px;} th {font:bold 10pt Arial,Helvetica,sans-serif; color:#33
6699; background:#cccc99; padding:0px 0px 0px 0px;} h1 {font:16
pt Arial,Helvetica,Geneva,sans-serif; color:#336699; background
-color:White; border-bottom:1px solid #cccc99; margin-top:0pt;
margin-bottom:0pt; padding:0px 0px 0px 0px;} h2 {font:bold 10pt
Arial,Helvetica,Geneva,sans-serif; color:#336699; background-c
olor:White; margin-top:4pt; margin-bottom:0pt;} a {font:9pt Ari
al,Helvetica,sans-serif; color:#663300; background:#ffffff; mar
gin-top:0pt; margin-bottom:0pt; vertical-align:top;}</style><ti
tle>TBSQL Report</title>" BODY "" TABLE "border='1' width='90%'
align='center' summary='Script output'" SPOOL OFF ENTMAP ON PR
EFORMAT OFF
NUMFORMAT ""
NEWPAGE 1
NUMWIDTH 10
PAGESIZE 24
PAUSE OFF
RECSEP WRAPPED
RECSEPCHAR " " (0x20)
ROWS ON
SERVEROUTPUT OFF
SQLCODE -1001
SQLPROMPT "SQL> "
SQLTERMINATOR ";" (0x3B)
SUFFIX "sql"
TERMOUT ON
TIME OFF
TIMEOUT 3
TIMING OFF
TRIMOUT ON
TRIMSPOOL OFF
UNDERLINE "-" (0x2D)
VERIFY ON
WRAP ON
SQL>
SQL>
SQL> conn tibero/tmax
Connected to Tibero.
SQL> SELECT COLUMN_NAME FROM USER_TBL_COLUMNS;
COLUMN_NAME
--------------------------------------------------------------------------------
PROD_ID
PROD_NAME
PROD_COST
PROD_PID
PROD_DATE
ENAME
JOB
MGR
DEPTNO
DNAME
LOC
EMPNO
HIREDATE
SAL
COMM
DEPTNO
16 rows selected.
SQL> conn scott/tiger
Connected to Tibero.
SQL> SELECT COLUMN_NAME FROM USER_TBL_COLUMNS;
COLUMN_NAME
--------------------------------------------------------------------------------
EMPNO
ENAME
JOB
MGR
HIREDATE
SAL
COMM
DEPTNO
ENAME
JOB
SAL
COMM
GRADE
LOSAL
HISAL
DUMMY
DEPTNO
DNAME
LOC
19 rows selected.
SQL>