๐Ÿ“œ ๐Ÿ˜ file_fdw๊ฐ€ ์žˆ๋Š” ๐Ÿš€ ๋กœ๊ทธ ํŒŒ์ผ์—์„œ * ์„ ํƒ

8053 ๋‹จ์–ด yugabytedbfdwlogfiletroubleshooting
์ด ์‹œ๋ฆฌ์ฆˆ์˜ ์ฒซ ๋ฒˆ์งธ ๊ฒŒ์‹œ๋ฌผ์—์„œ๋Š” yb_debug_log_docdb_requests ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ DocDB์— ๋Œ€ํ•œ ํ˜ธ์ถœ์„ ์ถ”์ ํ–ˆ์Šต๋‹ˆ๋‹ค. ๋กœ๊ทธ๋Š” PostgreSQL ๋กœ๊ทธ ํŒŒ์ผ๋กœ ์ด๋™ํ•˜์ง€๋งŒ PostgreSQL ๊ธฐ๋Šฅ์„ ํ†ตํ•ด์„œ๋Š” ์ด๋™ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ์ด๋Š” client_min_messages ๋ฅผ ์„ค์ •ํ•  ๋•Œ ํด๋ผ์ด์–ธํŠธ๋กœ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์—†์Œ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. ์ด๋ž˜์„œ ์ ‘์†ํ–ˆ๋˜ ์„œ๋ฒ„์—์„œ ์ ‘์†ํ•ด์„œ pg_current_logfile()๋ผ๋Š” ํŒŒ์ผ๋ช…์„ ๋ฐ›๊ณ  OS๋กœ ๊ฐ‘๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ PostgreSQL ์„ธ์…˜์—์„œ OS์— ์•ก์„ธ์Šคํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ ๋‹ค์Œ์€ file_fdw ์˜ ์˜ˆ์ž…๋‹ˆ๋‹ค.

๋‚˜๋Š” FDW ์™ธ๋ถ€ ํ…Œ์ด๋ธ”์„ ํ†ตํ•ด ํŒŒ์ผ์— ์•ก์„ธ์Šคํ•˜๊ธฐ ์œ„ํ•ด file_fdw ์„œ๋ฒ„์™€ ํ•จ๊ป˜ YugabyteDB์— ์—ฐ๊ฒฐ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ํƒ€์ž„์Šคํƒฌํ”„(awk)๋ฅผ ํ•ด๋…ํ•˜๊ณ  ๋ผ์ธ ๋ฒˆํ˜ธ(ts)๋ฅผ ์ถ”๊ฐ€ํ•˜์—ฌ ์ฃผ๋ฌธํ•˜๋Š” nr ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์‚ดํŽด๋ด…๋‹ˆ๋‹ค. ๋˜ํ•œ ์ •๋ณด๋ฅผ csv ํ˜•์‹์œผ๋กœ ๋ณ€ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ์ฟผ๋ฆฌํ•  ๋•Œ ๋งˆ์ง€๋ง‰ ํƒ€์ž„์Šคํƒฌํ”„๊ฐ€ string_add ์ธ ํ•˜๋‚˜์˜ ํ–‰์„ ์–ป๊ธฐ ์œ„ํ•ด ๋ชจ๋“  ์ค„์„ ํ•˜๋‚˜์˜ ๊ฐ’( with as last_ts )์œผ๋กœ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ๋‹ค์Œ ํ˜ธ์ถœ์—์„œ ์ƒˆ ์ค„gset๋งŒ ํ‘œ์‹œ๋˜๋„๋ก ์ถ”์ ํ•˜๊ธฐ ์œ„ํ•ด >:'last_ts'๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด ์ด ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

์ด๊ฒƒ์ด ๋‚ด๊ฐ€ ๋ชจ๋“  ๊ฒƒ์„ ์ƒ์„ฑํ•˜๊ณ  ์ฟผ๋ฆฌ๋ฅผ ์ค€๋น„ํ•˜๊ธฐ ์œ„ํ•ด ์‹คํ–‰ํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

# create privileges, extension, and FDW server
do $do$ begin execute $sql$ grant yb_extension,yb_fdw to $sql$ || user; end; $do$;
create extension if not exists file_fdw;
create server if not exists file_fdw foreign data wrapper file_fdw;
# create FDW table on current logfile
drop foreign table current_logfile ;
create foreign table current_logfile (ts timestamptz, nr int, log text) server file_fdw options ( program $bash$ awk '
/^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}[.][0-9]*/ { t=$1" "$2}
/^.[0-9]{4} [0-9]{2}:[0-9]{2}:[0-9]{2}[.][0-9]*/ { t=d" "$2}
{gsub(/"/,q q);print q t q "," q NR q "," q $0 q}
' q='"' d=$(date +%Y-%m-%d) '/home/opc/10.0.0.61/var/data/yb-data/tserver/logs/postgresql-2022-07-20_000000.log'
$bash$, format 'csv');
#
select now() as last_ts
\gset
deallocate logfile;
prepare logfile(timestamp) as
select
 max(ts) as last_ts,e'\n'||string_agg(log,e'\n' order by ts,nr) log
 from current_logfile where log like 'I%' and ts>$1
;
\pset format unaligned

log like 'I%'๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ YugabyteDB ์ •๋ณด ๋ฉ”์‹œ์ง€๋งŒ ๊ฐ€์ ธ์˜ค๋„๋ก ํ•„ํ„ฐ๋งํ•ฉ๋‹ˆ๋‹ค. ์ด๊ฒƒ์„ ์ œ๊ฑฐํ•˜์—ฌ PostgreSQL ๋ฉ”์‹œ์ง€๋ฅผ ํฌํ•จํ•œ ๋ชจ๋“  ์ค„์„ ํ‘œ์‹œํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ด์ œ ๋‹ค์Œ์„ ์‚ฌ์šฉํ•˜์—ฌ ๋งˆ์ง€๋ง‰ ํ˜ธ์ถœ ์ดํ›„ ์ƒˆ ์ค„์„ ํ‘œ์‹œํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

execute logfile(:'last_ts');\gset


์˜ˆ์‹œ






-- set start timestamp and enable log docdb requests
select now() as last_ts;\gset
set yb_debug_log_docdb_requests=true;

-- run query
select count(*) from demo;

--  show log since start timestamp and reset to last time
\pset format unaligned
execute logfile(:'last_ts');
\gset
\pset format aligned


์ด๊ฒƒ์€ DocDB์— ๋Œ€ํ•œ ์ฝ๊ธฐ ์š”์ฒญ์„ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค.


YSQL ์ฟผ๋ฆฌ ๋ ˆ์ด์–ด์—์„œ DocDB ๋ถ„์‚ฐ ์Šคํ† ๋ฆฌ์ง€ ๋ฐ ํŠธ๋žœ์žญ์…˜์— ๋Œ€ํ•œ ํ˜ธ์ถœ์„ ๋” ์ž˜ ์ดํ•ดํ•˜๊ธฐ ์œ„ํ•ด ์‹คํ—˜์‹ค์—์„œ ์ด๊ฒƒ์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

์ข‹์€ ์›นํŽ˜์ด์ง€ ์ฆ๊ฒจ์ฐพ๊ธฐ