Data Base/Linux

231208 Linux_startup, shutdown

잇꼬 2023. 12. 11. 11:02
728x90
반응형
SMALL

■ daily check list
★ listener 상태정보, sql DB 확인
client - listener(host, port, SID, protocdl 의 정보)  - server 
              : network 길                                               putty로 접속했을 때 

# listener 중지
[oracle@oracle ~]$ lsnrctl stop


# listener 상태 정보 확인
[oracle@oracle ~]$ lsnrctl status



# listener 중지되었을 경우, network 오류


# 위에 오류상태 일 경우, listener 시작
[oracle@oracle ~]$ lsnrctl start


# 오라클이 사용하고 있는 프로세스 확인
[oracle@oracle ~]$ ps -ef | grep oracle

# 관리해야 할 DB 접속
[oracle@oracle ~]$ sqlplus / as sysdba

# open 
SQL> select * from v$instance;



# 오류발생
sql 로 접속했을경우,
Connected to an idle instance. : db가 내려갔다. 중단됐다
으로 출력되었을때
SQL> startup
[oracle@oracle ~]$ lsnrctl start 
[oracle@oracle ~]$ lsnrctl status 실행

# 마지막으로 수행한 쿼리문
SQL> l
  1* select * from v$instance


# define 환경설정 -> DEFINE _EDITOR ="vi" 로 변경
SQL> cd
SP2-0042: unknown command "cd" - rest of line ignored.
SQL> q
SP2-0042: unknown command "q" - rest of line ignored.
SQL> define
DEFINE _DATE           = "07-DEC-23" (CHAR)
DEFINE _CONNECT_IDENTIFIER = "ora11g" (CHAR)
DEFINE _USER           = "SYS" (CHAR)
DEFINE _PRIVILEGE      = "AS SYSDBA" (CHAR)
DEFINE _SQLPLUS_RELEASE = "1102000400" (CHAR)
DEFINE _EDITOR         = "ed" (CHAR)
DEFINE _O_VERSION      = "Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options" (CHAR)
DEFINE _O_RELEASE      = "1102000400" (CHAR)
SQL>
SQL>
SQL>
SQL> define_editor="vi"
SQL> define <- 환경설정
DEFINE _DATE           = "07-DEC-23" (CHAR)
DEFINE _CONNECT_IDENTIFIER = "ora11g" (CHAR)
DEFINE _USER           = "SYS" (CHAR)
DEFINE _PRIVILEGE      = "AS SYSDBA" (CHAR)
DEFINE _SQLPLUS_RELEASE = "1102000400" (CHAR)
DEFINE _EDITOR         = "vi" (CHAR)
DEFINE _O_VERSION      = "Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options" (CHAR)
DEFINE _O_RELEASE      = "1102000400" (CHAR)
SQL> 

# vi 편집기 실행
SQL> ed
Wrote file afiedt.buf

  1* select open from v$instance

# 오류발생
SQL> /
select open from v$instance
       *
ERROR at line 1:
ORA-00904: "OPEN": invalid identifier


# define_editor 설정
# glogin.sql vi 편집기를 열어 "defin_editor="vi"" 삽입
[oracle@oracle admin]$ ls
glogin.sql  help  libsqlplus.def  plustrce.sql  pupbld.sql

[oracle@oracle admin]$ vi glogin.sql
--
-- Copyright (c) 1988, 2011, Oracle and/or its affiliates.
-- All rights reserved.
--
-- NAME
--   glogin.sql
--
-- DESCRIPTION
--   SQL*Plus global login "site profile" file
--
--   Add any SQL*Plus commands here that are to be executed when a
--   user starts SQL*Plus, or uses the SQL*Plus CONNECT command.
--
-- USAGE
--   This script is automatically run
--
defin_editor="vi"
[oracle@oracle admin]$ cd
[oracle@oracle ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Thu Dec 7 20:36:43 2023

Copyright (c) 1982, 2013, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> define
DEFINE _DATE           = "07-DEC-23" (CHAR)
DEFINE _CONNECT_IDENTIFIER = "ora11g" (CHAR)
DEFINE _USER           = "SYS" (CHAR)
DEFINE _PRIVILEGE      = "AS SYSDBA" (CHAR)
DEFINE _SQLPLUS_RELEASE = "1102000400" (CHAR)
DEFINE _EDITOR         = "vi" (CHAR)
DEFINE _O_VERSION      = "Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options" (CHAR)
DEFINE _O_RELEASE      = "1102000400" (CHAR)
SQL>

■ alert log file 
- 오라클이 운영되고 종료될 때까지 중요한 내용들을 저장하고 있는 파일
- 오라클 서버에서 어떤 장애가 발생했거나 문제의 징후가 보일 경우 이 파일 내용을 자세히 분석해보면 해답을 찾을 수 있다.

[oracle@oracle trace]$ pwd
/u01/app/oracle/diag/rdbms/ora11g/ora11g/trace
$ORACLE_BASE/oracle/diag/rdbms/SID(현장에서 다를수있다)/SID/trace

■ ORACLE DateBase 시작

SQL> startup
ORACLE instance started.

Total System Global Area  711430144 bytes
Fixed Size                  1367004 bytes
Variable Size             469763108 bytes
Database Buffers          234881024 bytes
Redo Buffers                5419008 bytes
Database mounted.
Database opened.

★ startup 단계

1. nomount - instance 시작(sga 영역과 background process 생성)
- initialization parameter file(초기 파라미터 파일) open
2. mount(control file) - control file open
- mount 단계에서 오라클 작업하는 일
- 데이터 파일명 바꾸기
- noarchivelog mode를 archivelog mode 바꾸는 작업
- full database recovery 
- rman 을 활용해서 close backup 할때
3. open - data file, redo log file open

1. nomount

1) spfile<SID>.ora, init<SID>.ora
- $ORACLE_HOME/dbs

SQL> show parameter spfile

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
spfile                               string      /u01/app/oracle/product/11.2.0
                                                  .4/db_1/dbs/spfileora11g.ora

SQL> startup mount 단계에서 제일 먼저 보는 파일이 spfile<SID>/ora를 찾는데 없으면 init<SID>.ora를 찾는다. 둘다 없으면 오류발생
[oracle@oracle ~]$ cd $ORACLE_HOME/dbs
[oracle@oracle dbs]$ pwd
/u01/app/oracle/product/11.2.0.4/db_1/dbs
[oracle@oracle dbs]$ ls
hc_ora11g.dat  init.ora  lkORA11G  orapwora11g  spfileora11g.ora
[oracle@oracle dbs]$
[oracle@oracle dbs]$ mv spfileora11g.ora spfileora11g.back
[oracle@oracle dbs]$ ls
hc_ora11g.dat  init.ora  lkORA11G  orapwora11g  spfileora11g.back

SQL> startup
ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/u01/app/oracle/product/11.2.0.4/db_1/dbs/initora11g.ora'

- alert<SID>.log, trace file open : 문제발생시 사용하기 위함
- nomount 단계에서 오라클 작업하는 일
- db 생성
- control file 재생성
- 백업, 복구

2. mount(control file)
- control file open
- mount 단계에서 오라클 작업하는 일
- 데이터 파일명 바꾸기
- noarchivelog mode를 archivelog mode 바꾸는 작업
- full database recovery 
- rman 을 활용해서 close backup 할때

3. open
- data file, redo log file open


■ db 읽기모드

SQL> shutdown immediate : 즉시 종료(정상적인 종료)
Database closed.
Database dismounted.
ORACLE instance shut down.

# db읽기모드로 시작
SQL> startup open read only 
ORACLE instance started.

Total System Global Area  711430144 bytes
Fixed Size                  1367004 bytes
Variable Size             469763108 bytes
Database Buffers          234881024 bytes
Redo Buffers                5419008 bytes
Database mounted.
Database opened.
SQL> select open_mode from v$database; : 읽기모드로만 가능

OPEN_MODE
--------------------
READ ONLY

SQL> select salary from hr.employees where employee_id = 100;

    SALARY
----------
     24000

SQL> update hr.employees set salary=1000 where employee_id = 100;
update hr.employees set salary=1000 where employee_id = 100
          *
ERROR at line 1:
ORA-16000: database open for read-only access

# 쓰기모드가 없을 경우
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

# 기본값이 [open] [read, write] 모드
SQL> startup
ORACLE instance started.

Total System Global Area  711430144 bytes
Fixed Size                  1367004 bytes
Variable Size             469763108 bytes
Database Buffers          234881024 bytes
Redo Buffers                5419008 bytes
Database mounted.
Database opened.
SQL> select open_mode from v$database;

OPEN_MODE
--------------------
READ WRITE

# test 해보기
SQL> update hr.employees set salary=1000 where employee_id = 100;

1 row updated.

SQL> rollback;

■ 오라클 종료 shutdown 옵션

SQL> shutdown [normal]
 : 사용의 빈도수↓
- normal 기본 종료 모드
- 새 session 연결을 생성할 수 없다. (=새 session 은 생성할 수 없다, 접속 불허)
- oracle 서버는 모든 유저가 연결을 끊을 때까지 종료하지 않고 대기한다.
- 데이터 버퍼 캐시(data buffer cash) 및 리두 버퍼(redo buffer)가 디스크에 기록된다
- 백그라운드 프로세스가 종료되고 SGA 메모리에서 제거된다.
- instance 종료하기 전에 데이터베이스(데이터파일, 리두로그파일)를 닫고 마운트(컨트롤파일)를 해제한다.(=:안정적으로 종료)
- 데이터베이스를 다시 시작할 때 instance recovery(백업) 가 필요하지 않는다.
(instance recovery 가 필요한 경우 -> 비정상적인 종료 했을 경우)
SQL> shutdown [transactional] - 새 session 연결을 생성할 수 없다. (=새 session 은 생성할 수 없다, 접속 불허)
- (DML 작업을) transactional 수행하는 유저는 계속 오라클에 접속을 나두고 접속은 했지만 아무 작업을 하지 않는 유저는 자동으로 session 을 종료시킨다.
- 모든 transaction 이 완료되면 (commit, rollback) 즉시 데이터베이스가 종료 된다.
- instance 종료하기 전에 데이터베이스(데이터파일, 리두로그파일)를 닫고 마운트(컨트롤파일)를 해제한다.(=:안정적으로 종료)
- 데이터베이스를 다시 시작할 때 instance recovery(백업) 가 필요하지 않는다.
(instance recovery 가 필요한 경우 -> 비정상적인 종료 했을 경우)
SQL> shutdown [immediat]
: 보편적으로 많이 사용
 새 session 연결을 생성할 수 없다. (=새 session 은 생성할 수 없다, 접속 불허)
- 오라클 서버는 현재 연결하고 있는 유저를 자동으로 kill 시킨다.(=session 종료)
- 현재 유저들 중에 DML 작업을 수행하고 있을 경우에 kill 시키는 순간 자동으로 rollback 된다.
- instance 종료하기 전에 데이터베이스(데이터파일, 리두로그파일)를 닫고 마운트(컨트롤파일)를 해제한다.(=:안정적으로 종료)
- 데이터베이스를 다시 시작할 때 instance recovery(백업) 가 필요하지 않는다.
(instance recovery 가 필요한 경우 -> 비정상적인 종료 했을 경우)
- 데이터베이스 close backup 을 수행할 때 한다. (백업본)
SQL> shutdown [abort] - 비정상적인 종료, 리커버리 필요
- normal, transaction , immediate 작동되지 않을 경우 (프로세스,메모리가 엉켜있을 경우)
- 데이터버퍼 캐시 및 리두버퍼가 디스크에 기록되지 않는다.
- commit 되지 않는 트랜잭션은 rollback 되지 않았다.
- 파일을 닫지 않은 상태로 instance 가 종료된다.
- 데이터베이스가 닫히거나 마운트 해제되지 않는다.( mount 불안정하게 open 되어 있다.)
- (다음 시작일때,) 데이터베이스를 시작시 instance recovery 가 필요하며 이는 자동으로 수행된다.
  주의!! shutdowm abort 수행한 후 데이터베이스 백업은 하지 말자!

 

728x90
반응형
LIST