pg_hint_plan 1탄 .. : 2023.10.13 - [DB/PostgreSQL] - [PostgreSQL - DA] PostgreSQL Hint 사용하기 (pg_Hint 1/3)
[PostgreSQL - DA] PostgreSQL Hint 사용하기 (pg_Hint 1/3)
오늘은 PostgreSQL에서 힌트를 사용하는 것을 연습해보려 한다. 일단 PostgreSQL은 Hint를 사용하려면 pg_hint_plan을 Extension 해야한다. 이게 무슨말이냐.. 하면.. PostgreSQL은 외부 lib를 추가하듯이 pg_hint_plan
holog.tistory.com
pg_hint_plan 2탄 .. : 2023.10.25 - [DB/PostgreSQL] - [PostgreSQL - DBA] wsl에 PostgreSQL 설치하기(pg_dumpall로 백업하기) (pg_Hint 2/3)
[PostgreSQL - DBA] wsl에 PostgreSQL 설치하기(pg_dumpall로 백업하기) (pg_Hint 2/3)
부제 : PostgreSQL Hint 사용하기 - 2 https://holog.tistory.com/80 [PostgreSQL - DA] PostgreSQL Hint 사용하기 오늘은 PostgreSQL에서 힌트를 사용하는 것을 연습해보려 한다. 일단 PostgreSQL은 Hint를 사용하려면 pg_hint_plan
holog.tistory.com
일단... pg_hint_plan 최신 버전을 설치하려 공홈에 들어갔다.
첫번째 삽질..
클릭하라는 아래 링크로 들어가서 rpm 파일을 다운받았다.. rpm 밖에 없네..
https://github.com/ossc-db/pg_hint_plan/releases
Releases · ossc-db/pg_hint_plan
Give PostgreSQL ability to manually force some decisions in execution plans. - ossc-db/pg_hint_plan
github.com

ubuntu에서 rpm 파일을 설치하려면 alien 패키지를 이용해서
Ubuntu에서 사용하는 Deb로 변경시켜야 한다.
먼저 alien 패키지를 설치하자.
# 최신 버전 update
sudo apt-get update
# alien 패키지를 설치
sudo apt-get install alien


이제 alien 패키지를 이용해 rpm 파일을 Ubuntu에서 사용하는 deb로 변환시키자.
#RPM파일을 Deb파일로 변환
sudo alien -c {RPM파일명}
#Deb파일 설치
sudo dpkg -i {Deb로변환된파일명}
참고 : https://bramhyun.tistory.com/65
[Linux] Ubuntu에서 RPM 파일 설치
- 이 글은 제가 공부를 하며, 이해한 것을 바탕으로 작성하는 글입니다. - 그렇기에 틀리거나 잘못된 부분이 있을 수 있습니다. - 글의 오류를 발견하시면, 댓글로 말씀해 주시면 정말 감사하겠습
bramhyun.tistory.com



이제 postgresql.conf에 아래 문구를 추가해 준 후에 재기동을 해야한다.
shared_preload_libraries='pg_hint_plan'
postgresql.conf 파일 위치는 아래와 같다.
/etc/postgresql/16/main

vi postgresl.conf로 편집기를 연 후에 해당 위치를 찾아서 바꿔주자.


..하려는데 아나 파일이 readonly 였다. 확인해보니 rw r r이네.. postgres로 유저 바꾸고 수정해주자.


이제 다시 바꿔주자.

이제 postgresql을 재기동 해주자.

# postgresql service 상태 확인해주고
systemctl status postgresql.service
# 죽인 후에
systemctl stop postgresql.service
# 다시 기동
systemctl start postgresql.service
# 다시 상태 확인
systemctl status postgresql.service
이제 postgresql 에 접속해서 드디어!!!! create extension 하러 가보자..,.,!
.
.
.

아씨 postgresql이 기동이 안된다.. 열받네..

로그 찾으러 가보자..


아니 뭐야 나 설치했는데 왜 폴더가 없대..?
설치한 놈이 어디에 있는지 찾아보자..
dpkg -L pg-hint-plan16

음? /usr/pgasql-16 폴더 아래에 있네..? 아까 위에서 보면 /usr/share/... 여기서 못찾고있던데..
저기에다가 옮겨줘 보자

이제 다시 아까 postgresql.conf 파일을 수정하고 재기동 해보자... 제발..!

하...씨!!!!!!!!!!!!!! 안된다!!

첫번째 삽질에서 postgresl.conf 수정하는 것은 꼭 해야하는 일이니 위에서 보고 오도록..
shared_preload_libraries='pg_hint_plan'
휴......... 두번째 도전...
이번엔 tar.gz 파일을 받아서.. make install 해본다...
일단 받았고.......... 공홈 사이트 보니까 뭐 요래요래 하란다... 해보자..
https://pg-hint-plan.readthedocs.io/en/latest/installation.html#building-binary-module
Installation — pg_hint_plan documentation
© Copyright 2012-2023, NIPPON TELEGRAPH AND TELEPHONE CORPORATION. Revision fa0a461a.
pg-hint-plan.readthedocs.io
하려는데 make가 없네? 먼저 받아주자..
이제 make를 해볼까.................

아니 이건 또 뭔오륜데?
root@AISELN-kanghb:/home/hobin/pg_hint/pg_hint_plan-REL16_1_6_0# make install
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wcast-function-type -Wshadow=compatible-local -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -Wno-stringop-truncation -g -g -O2 -flto=auto -ffat-lto-objects -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security -fno-omit-frame-pointer -fPIC -fvisibility=hidden -I. -I./ -I/usr/include/postgresql/16/server -I/usr/include/postgresql/internal -Wdate-time -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -I/usr/include/libxml2 -c -o pg_hint_plan.o pg_hint_plan.c
pg_hint_plan.c:12:10: fatal error: postgres.h: No such file or directory
12 | #include "postgres.h"
| ^~~~~~~~~~~~
compilation terminated.
make: *** [<builtin>: pg_hint_plan.o] Error 1
검색 해보니 바로 나오는 stack over flow 답변... 감사합니다...
https://stackoverflow.com/questions/56724622/how-to-fix-postgres-h-file-not-found-problem
How to fix 'postgres.h' file not found problem?
I am trying to write a base type for PostgreSQL in C (using xcode), and I already installed PostgreSQL 11, but it seems that postgres.h cannot be simply included in the file ("'postgres.h' file not...
stackoverflow.com
요약 : 다음 명령을 사용하여 postgresql-server-dev 패키지를 설치하렴.
sudo apt install postgresql-server-dev-16
그럼 make install 날려주고..
오오ㅓ오ㅓ오ㅗ오 되는 거 같다 이제 postgresql 서버를 재기동 다시 해주면..?
하 드디어 설치된 거 같다................ extension 확인해보러 psql 접속 해보자!!!
하..... 됬따...
아까 공식문서에서 pg_hint_plan does not require CREATE EXTENSION.. 라는 문구로 보니.. 뭐 create 안해도 된다니까 한번 안하고 현재 Session 에서만 Load 해서 써보자.
테스트 쿼리 준비하고
힌트를 안썼을 땐 b 테이블이 index Scan 대상으로 나오니 한번 b 테이블을 SeqScan 하라고 강제해보자.
오오오오오오 내 말을 잘 듣는다 seqscan으로 변경됬다..................!
하 드디어...성공... hint........
create extension 까지만 해놓고 끝내야지..
hint에 대한 더 다양한 활동은 추후 이어서 쓰겠다..
오늘은 여기까지..

'DB > PostgreSQL' 카테고리의 다른 글
[PostgreSQL] now(), clock_timestamp(), statement_timestamp() 차이 (2) | 2024.01.03 |
---|---|
[PostgreSQL - DBA] PostgreSQL 관련 참고 쿼리 (3) | 2024.01.02 |
[PostgreSQL - DBA] wsl에 PostgreSQL 설치하기(pg_dumpall로 백업하기) (pg_Hint 2/3) (3) | 2023.10.25 |
[PostgreSQL - DBA] 오브젝트 생성 시 기본 권한 자동 부여(alter default privileges) (0) | 2023.10.20 |
[PostgreSQL - DBA] FK Option (1) | 2023.10.16 |