> For the complete documentation index, see [llms.txt](https://docs.tibero.com/tmaxopensql/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tibero.com/tmaxopensql/tmax-o2-extensions/installation/o2-extension.md).

# O2 Extension 설치

## 개요

O2는 PostgreSQL 환경에서 오라클이 지원하는 함수/패키지/타입들과 호환되는 인터페이스를 제공하여 사용자들의 편의를 향상시키는 PostgreSQL Extension 입니다.

### 시스템 요구 사항

OpenSQL에서 지원하는 운영체제/하드웨어 사양과 동일합니다.

O2 Extension에서는 제품 설치를 위한 방법을 다음의 2가지 설치 형태로 제공하고 있습니다.

* make 방식으로 설치
* shell 방식으로 설치

### O2 설치파일 디렉토리 구조

OpenSQL 설치 패키지 내부에 동봉될 O2 설치파일 모음 디렉토리는 아래와 같은 형식으로 제공됩니다.\
내부에는 2가지 설치방법을 위한 파일(`Makefile`, `install.sh`)들이 제공됩니다.

```sh
ls -rlta

total 60
drwxr-xr-x  2 root root 4096 Mar 13 05:09 utl_file
drwxr-xr-x  2 root root 4096 Mar 13 05:09 o2views
drwxr-xr-x  2 root root 4096 Mar 13 05:09 o2types
drwxr-xr-x  2 root root 4096 Mar 13 05:09 o2functions
-rw-r--r--  1 root root 3266 Mar 13 05:09 install.sh        # sh 설치용 스크립트
drwxr-xr-x  2 root root 4096 Mar 13 05:09 dbms_sql
drwxr-xr-x  2 root root 4096 Mar 13 05:09 dbms_random
drwxr-xr-x  2 root root 4096 Mar 13 05:09 dbms_pipe
drwxr-xr-x  2 root root 4096 Mar 13 05:09 dbms_output
drwxr-xr-x  2 root root 4096 Mar 13 05:09 dbms_alert
-rw-r--r--  1 root root 1465 Mar 13 05:09 VERSION.json      # o2 extensions 버전 정보
-rw-r--r--  1 root root  672 Mar 13 05:09 Makefile          # make 방식설치용 파일
drwxr-xr-x 12 root root 4096 Mar 13 05:09 .
drwxr-xr-x  6 root root 4096 Mar 13 05:09 ..
```

## make 설치방법

PostgreSQL가 설치된 Linux 플랫폼에서 O2 Extension을 `make` 커맨드를 통해 자동으로 설치할 수 있습니다

O2 Extension이 포함하는 모든 Extension을 동시 설치하는 **전체 설치**, 개별 Extension을 설치하는 **개별 설치**로 구분합니다.

### 설치 전 요구사항

PostgreSQL이 설치가 되어있고, 터미널 명령줄에서 `make, pg_config` 커맨드가 사용 가능한 상태여야 합니다.

### 전체 설치

O2 Extension 설치 구성 요소가 모여 있는 디렉토리(`Makefile` 이 있는 디렉토리) 내부로 이동하여 아래의 make 커맨드를 수행합니다.

```sh
cd o2
make all # o2 extensions 전체 설치

# 아래는 전체 설치 과정에서 출력되는 예시 로그
make[1]: Entering directory '/home/opensql/o2/build/o2-dist-1.0.1/o2functions'
/usr/bin/mkdir -p '/home/opensql/postgres/build/16/lib'
/usr/bin/mkdir -p '/home/opensql/postgres/build/16/share/extension'
/usr/bin/mkdir -p '/home/opensql/postgres/build/16/share/extension'
/usr/bin/install -c -m 755  o2functions.so '/home/opensql/postgres/build/16/lib/o2functions.so'
/usr/bin/install -c -m 644 .//o2functions.control '/home/opensql/postgres/build/16/share/extension/'
/usr/bin/install -c -m 644 .//VERSION.json .//o2functions--1.0.sql  '/home/opensql/postgres/build/16/share/extension/'
make[1]: Leaving directory '/home/opensql/o2/build/o2-dist-1.0.1/o2functions'
...
```

### 개별 설치

개별 설치는 `make` 커맨드에 설치하려는 extension 이름을 인자로 추가해야 합니다.

```sh
cd o2
# make [ extension1 extension2 ... ]
make o2functions o2types dbms_output

# 아래는 make 수행 시 나오는 예시 로그
make -C o2functions install
make[1]: Entering directory '/home/opensql/o2/build/o2-dist-1.0.1/o2functions'
/usr/bin/mkdir -p '/home/opensql/postgres/build/16/lib'
/usr/bin/mkdir -p '/home/opensql/postgres/build/16/share/extension'
/usr/bin/mkdir -p '/home/opensql/postgres/build/16/share/extension'
/usr/bin/install -c -m 755  o2functions.so '/home/opensql/postgres/build/16/lib/o2functions.so'
/usr/bin/install -c -m 644 .//o2functions.control '/home/opensql/postgres/build/16/share/extension/'
/usr/bin/install -c -m 644 .//VERSION.json .//o2functions--1.0.sql  '/home/opensql/postgres/build/16/share/extension/'
make[1]: Leaving directory '/home/opensql/o2/build/o2-dist-1.0.1/o2functions'
...
```

#### 개별 설치 extension 이름 목록

* DBMS\_ALERT
* DBMS\_ASSERT
* DBMS\_OUTPUT
* DBMS\_PIPE
* DBMS\_RANDOM
* DBMS\_SCHEDULER
* DBMS\_SQL
* DBMS\_JOB
* DBMS\_RLS
* UTL\_FILE
* O2Functions
* O2Types
* O2Views

***

## shell 설치방법

`make` 커맨드를 사용할 수 없는 환경에서 shell script를 이용하여 수기로 설치할 수 있습니다.

PostgreSQL가 설치된 Linux 플랫폼에서 O2 Extension을 수동으로 설치할 수 있습니다. O2 Extension이 포함하는 모든 Extension을 동시 설치하는 **전체 설치**, 개별 Extension을 설치하는 **개별 설치**로 구분됩니다.

### 설치 전 요구사항

PostgreSQL이 설치가 되어있고, 터미널 명령줄에서 `pg_config` 바이너리가 사용가능한 상태여야 합니다.

### 전체 설치

OpenSQL 바이너리 설치 스크립트가 모여있는 디렉터리(scripts)로 이동한 후 `install.sh` 스크립트를 실행합니다.

<pre class="language-sh"><code class="lang-sh"><strong>cd scripts
</strong>sh ./install.sh o2
</code></pre>

### 개별 설치

O2 Extension 설치 구성 요소가 모여 있는 디렉토리(`Makefile` 이 있는 디렉토리) 내부로 이동하여 `install.sh` 을 수행합니다. 설치 커맨드에 설치하려는 extension 이름을 인자로 넣어주어야 합니다.

```sh
# sh install.sh [ extension1 extension2 ... ]
sh install.sh o2functions o2types dbms_output

# 아래는 개별 설치 과정에서 출력되는 예시로그
Installing extensions to:
  Library directory: /home/opensql/postgres/build/16/lib
  Shared extension directory: /home/opensql/postgres/build/16/share/extension
Extensions to install: o2functions o2types dbms_output
Installing extension: o2functions
  Copied control file: ./o2functions.control
  Copied SQL file: ./o2functions--1.0.sql
  Copied shared library: ./extensions/functions/o2functions.so
Installing extension: o2types
  Copied control file: ./o2types.control
  Copied SQL file: ./o2types--1.0.sql
  Copied shared library: ./extensions/types/o2types.so
Installing extension: dbms_output
  Copied control file: ./dbms_output.control
  Copied SQL file: ./dbms_output--1.0.sql
  Copied shared library: ./extensions/dbms_output/dbms_output.so
Copied METADATA: VERSION.json
Installation completed.
```

#### 개별 설치 extension 이름 목록

* DBMS\_ALERT
* DBMS\_ASSERT
* DBMS\_OUTPUT
* DBMS\_PIPE
* DBMS\_RANDOM
* DBMS\_SCHEDULER
* DBMS\_SQL
* DBMS\_JOB
* DBMS\_RLS
* UTL\_FILE
* O2Functions
* O2Types
* O2Views

***

## 설치 유의 사항

### pg\_config와 $PATH 설정

make/shell 설치 방법 모두 `pg_config` 가 사용 가능한 계정으로 설치를 수행해야 합니다.

`$PATH` 변수 값에 `/usr/pgsql-{PG버전}/bin` 이 포함되어 있는지 확인해야합니다.

```bash
[root@20fec5585ddd /]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/pgsql-16/bin/

# 현재 접속한 계정의 $PATH에 경로값이 없다면 PG 버전에 알맞은 경로를 $PATH 경로에 추가
[root@20fec5585ddd /]# echo "export PATH=$PATH:/usr/pgsql-16/bin/" >> ~/.bashrc
[root@20fec5585ddd /]# source ~/.bashrc
```

### $PATH 값에 PG경로가 설정 되어있지 않은 유저 계정에서의 설치 방법

$PATH가 설정되어있는 유저의 권한으로 우회하여 설치를 진행해야 합니다.

sudo 권한을 통해 아래와 같은 명령어를 수행합니다.

```bash
sudo -u {PG경로가 $PATH에 설정된 다른 USER} bash -l -c "{make 또는 shell 설치 명령}"

# 예시)
# postgres 유저의 $PATH에 /usr/pgsql-16/bin/ 경로가 등록되어 있고,
# opensql이라는 유저로 접속하여 make 방식으로 o2 설치하려는 경우
[opensql@20fec5585ddd /]# sudo -u postgres bash -l -c "make all"
```

### 라이선스 관련 설정

O2 extension 은 OpenSQL 라이센스를 확인하므로, 아래와 같이 라이센스 파일 경로를 지정해주어야 합니다.

```
# postgresql.conf의 shared_preload_libraries의 첫 번째로 opensql_license 추가
shared_preload_libraries = 'opensql_license'

# 라이선스 파일 경로 환경변수 설정
export OPENSQL_LICENSE_PATH="/path/to/license.xml"
```

***

## 설치 구성 요소

### Extension 종류

O2 Extension들은 아래와 같이 크게 4종류 그룹으로 분류됩니다.

각 그룹들의 하위 목록은 실제 제공되는 개별 Extension의 이름을 나열한 것입니다.

* Types Extension
  * O2Types
* Views Extension
  * O2Views
* Functions Extension
  * O2Functions
* Package Extensions
  * DBMS\_ALERT
  * DBMS\_ASSERT
  * DBMS\_OUTPUT
  * DBMS\_PIPE
  * DBMS\_RANDOM
  * DBMS\_SCHEDULER
  * DBMS\_SQL
  * DBMS\_JOB
  * DBMS\_RLS
  * UTL\_FILE

### Extension 구성 요소

각 extension들은 아래와 같은 파일들로 구성되어 있고 각 extension별로 개별 생성 가능합니다.

예시) O2Functions Extension의 구성 파일은 다음과같습니다.

* Shared object file (eg. o2functions.so)
* Control file (eg. o2functions.control)
* Script file (eg. o2functions—1.0.sql, o2functions—1.0—1.1.sql, …)

그리고 extension들의 버전 정보를 한 곳으로 묶은 VERSION.json 파일이 존재합니다.

###

***

## O2 Extension 활성화

O2 Extension을 설치한 후 활성화를 하기 위해서는 아래와 같이 SQL 커맨드를 실행해야 합니다.

```sql
CREATE EXTENSION {extension name};
```

* O2 Extension들은 내부에 정의한 객체를 생성하기 위해 스키마 `oracle` 를 사용합니다.
* Package Extension(DBMS\_ALERT, DBMS\_PIPE 등)은 각자 extension 이름을 스키마로 사용합니다.
* O2 Extension에서 사용될 스키마 이름을 변경하기 위해서는 각 extension의 control 파일 내부 `schema` 항목의 값을 수정해야합니다. (단, 각 Package extension들은 스키마 이름이 고정값으로 변경할 수 없습니다.)

***

## O2 Extension 업데이트

O2 Extension을 상위 버전으로 업데이트 하기 위해서는 아래와 같이 SQL 커맨드를 실행해야 합니다.

```sql
ALTER EXTENSION {extension name} UPDATE TO {new version};
```

***

## HA 구성 시 주의 사항

HA 구성 시 각 노드에 직접 붙어 수동으로 O2 Extension 설치 및 업데이트를 진행해야 합니다.

또한 각 노드에 설치된 O2 Extension version은 일치하게 설치되도록 합니다.

노드 간 버전 차이가 발생하면 버전 간 동작 차이로 인해 쿼리 수행 시 어느 노드로 보내 졌는지에 따라 다른 결과값이 나올 수 있습니다.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.tibero.com/tmaxopensql/tmax-o2-extensions/installation/o2-extension.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
