AGE11 시작하기(setting)

Ja L·2023년 5월 30일
0

age

목록 보기
1/1

AGE 는 PosgreSQL의 extension으로 제공되어 기존에 PostgreSQL을 사용하던 유저가 편리하게 그래프 데이터를 이용할 수 있습니다.

Extension을 생성하고 load 후, search_path를 설정하는 과정이 필요합니다. search_path를 하기 전에 우선 PostgreSQL의 pg_catalog에서 어떤 내용을 확인할 수 있는지 알아봅니다.

snb1gb=# create database test01 ;
CREATE DATABASE

snb1gb=# \c test01
You are now connected to database "test01" as user "snbuser".

test01=# create extension age ;
CREATE EXTENSION

test01=# load 'age' ;
LOAD

Database를 새로 생성할 시 자동으로 생성되는 namespace 이외에 ag_catalog가 생성되었습니다. nspowner 16384로 생성되었네요.

test01=# select * from pg_namespace ;
-[ RECORD 1 ]---------------------------------
nspname  | pg_toast
nspowner | 10
nspacl   |
-[ RECORD 2 ]---------------------------------
nspname  | pg_temp_1
nspowner | 10
nspacl   |
-[ RECORD 3 ]---------------------------------
nspname  | pg_toast_temp_1
nspowner | 10
nspacl   |
-[ RECORD 4 ]---------------------------------
nspname  | pg_catalog
nspowner | 10
nspacl   | {postgres=UC/postgres,=U/postgres}
-[ RECORD 5 ]---------------------------------
nspname  | public
nspowner | 10
nspacl   | {postgres=UC/postgres,=UC/postgres}
-[ RECORD 6 ]---------------------------------
nspname  | information_schema
nspowner | 10
nspacl   | {postgres=UC/postgres,=U/postgres}
-[ RECORD 7 ]---------------------------------
nspname  | ag_catalog
nspowner | 16384
nspacl   |

pg_proc 에서 관련한 내용을 살펴봅니다. pg_proc은 함수, 프로시저를 관리하는 pg_catalog입니다. nspowner가 16384이고 graph 관련한 이름을 가진 함수와 프로시저를 검색해봅니다.

test01=# select * from pg_proc where proowner=16384 and proname like '%graph%' ;
-[ RECORD 1 ]---+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------
proname         | create_graph
pronamespace    | 39872
proowner        | 16384
prolang         | 13
procost         | 1
prorows         | 0
provariadic     | 0
protransform    | -
prokind         | f
prosecdef       | f
proleakproof    | f
proisstrict     | f
proretset       | f
provolatile     | v
proparallel     | u
pronargs        | 1
pronargdefaults | 0
prorettype      | 2278
proargtypes     | 19
proallargtypes  |
proargmodes     |
proargnames     | {graph_name}
proargdefaults  |
protrftypes     |
prosrc          | create_graph
probin          | $libdir/age
proconfig       |
proacl          |
-[ RECORD 2 ]---+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------
proname         | drop_graph
pronamespace    | 39872
proowner        | 16384
prolang         | 13
procost         | 1
prorows         | 0
provariadic     | 0
protransform    | -
prokind         | f
prosecdef       | f
proleakproof    | f
proisstrict     | f
proretset       | f
provolatile     | v
proparallel     | u
pronargs        | 2
pronargdefaults | 1
prorettype      | 2278
proargtypes     | 19 16
proallargtypes  |
proargmodes     |
proargnames     | {graph_name,cascade}
proargdefaults  | ({CONST :consttype 16 :consttypmod -1 :constcollid 0 :constlen 1 :constbyval true :constisnull false :location 2632 :constvalue 1 [ 0 0 0 0 0 0 0 0 ]})
protrftypes     |
prosrc          | drop_graph
probin          | $libdir/age
proconfig       |
proacl          |
-[ RECORD 3 ]---+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------
proname         | alter_graph
pronamespace    | 39872
proowner        | 16384
prolang         | 13
procost         | 1
prorows         | 0
provariadic     | 0
protransform    | -
prokind         | f
prosecdef       | f
proleakproof    | f
proisstrict     | f
--More--
test01=# set search_path = ag_catalog, pulbic, '$user' ;
SET

ag_catalog의 기능과 역할을 파악할 수 있습니다.

set search_path 에 ag_catalog를 추가하여 조회하는 Schema의 대상에 ag_catalog를 포함시키는 과정이 필요합니다.

set search_path에 ag_catalog를 추가해줍니다.

test01=# set search_path = ag_catalog, pulbic, '$user' ;
SET

PostgreSQL에서 search_path 란 Schema를 조회하는 순서를 지정하는 것입니다.
예를 들어, employer 과 employee 라는 스키마가 있다고 가정해봅니다.
두 Schema 내에 salary 라는 같은 table이 있습니다.

만약 'select * from salary;' 라는 쿼리문을 실행하여 salary 테이블의 데이터를 조회하면, Schema를 순서대로 조회하면서 가장 먼저 매칭되는 Table에서 해당 명령을 실행하게됩니다.

후순위인 employee Schema에서 salary table의 데이터를 조회하고 싶으면 'select * from employee.salary ;' 처럼 Schema를 지정해주어야 합니다.

profile
DB Engineer

0개의 댓글