최근 Tibero 테이블 400여개를 PG로, ElasticSearch index 200여개에 1억개 정도의 데이터를 PG 로 이관했습니다.
데이터가 정상적으로 잘 넘어왔는지 간단하게 확인하려고 합니다.
1. SourceDB의 table 수와 TargetDB의 table 수 비교
2. 각 table의 row 수 비교 (Source vs Target)
DB 별 테이블의 row 수 비교 쿼리를 확인해봅니다.
table의 이름을 기준 오름차순으로 조회합니다.
Tibero
SELECT OWNER, TABLE_NAME, NUM_ROWS
FROM ALL_TABLES
WHERE OWNER = 'TEST'
ORDER BY TABLE_NAME ASC ;
ElasticSearch
http://hostname:9200/_cat/indices?v&s=index:asc
PostgreSQL
create or replace function count_rows_of_table(table_schema text, table_name text)
returns numeric
language plpgsql
as
$$
declare
count numeric;
begin
execute format('select count(*) from %s.%s', table_schema, table_name)
into count;
return count;
end;
$$;
select n.nspname as table_schema, c.relname as table_name, c.reltuples as estimated_row_count, count_rows_of_table(n.nspname, c.relname) as exact_row_count
from pg_class c join pg_namespace n on n.oid = c.relnamespace
where c.relkind = 'r' and n.nspname = 'public'
order by table_name ASC;
감사합니다. 이런 정보를 나눠주셔서 좋아요.