SlideShare a Scribd company logo
Community
Enterprise
on Azure
Postgresql
citus
Postgresql
citus
Postgresql
citus
Postgresql
citus
relay query 수행 (routes)
coordinator
metadata
Worker1
Worker2
Worker3
D1
D2
D3
D3
D1
D2
distributed Table replica
duplicated
duplicated
duplicated
reference Tablelocal tables LOCAL
coordinator
(master)
Worker1
Worker2
Worker3
Worker4
Worker5
Worker6
coordinator
(hot standby)
Worker1
(Standby)
Worker2
(Standby)
Worker3
(Standby)
Worker4
(Standby)
Worker5
(Standby)
Worker6
(Standby)
streaming repliacation
streaming repliacation
pg_auto_failover
KAFKA
Kafka connect
JDBC for Oracle
kafka connect
kudu
ORACLE KUDU
Debezium
connector for
PostgreSQL
pg_auto_failover
naverdb=> select * from pg_dist_shard
where logicalrelid='companies'::regclass
order by 2;
logicalrelid | shardid | shardstorage | shardminvalue | shardmaxvalue
--------------+---------+--------------+---------------+---------------
companies | 102200 | t | -2147483648 | -1073741825
companies | 102201 | t | -1073741824 | -1
companies | 102202 | t | 0 | 1073741823
companies | 102203 | t | 1073741824 | 2147483647
(4 rows)
SELECT
shardid,
node.nodename,
node.nodeport
FROM pg_dist_placement placement
JOIN pg_dist_node node
ON placement.groupid = node.groupid
AND node.noderole = 'primary'::noderole
WHERE shardid in ('102200','102201','102202','102203')
shardid | nodename | nodeport
---------+----------------------+----------
102200 | dev-hanccitus002-ncl | 6432
102201 | dev-hanccitus003-ncl | 6432
102202 | dev-hanccitus004-ncl | 6432
102203 | dev-hanccitus002-ncl | 6432
(4 rows)
• Rebalance Shards without Downtime
select master_update_node(nodeid, 'new-address', nodeport)
from pg_dist_node
where nodename = 'old-address';
select * from sales where deptno=1;
deptno | deptname | total_amount
--------+-------------+--------------
1 | french_dept | 10000
SELECT shardid, shardstate, shardlength, nodename, nodeport, placementid
FROM pg_dist_placement AS placement,
pg_dist_node AS node
WHERE placement.groupid = node.groupid
AND node.noderole = 'primary'
AND shardid = (
SELECT get_shard_id_for_distribution_column('sales', 1)
);
shardid | shardstate | shardlength | nodename | nodeport | placementid
---------+------------+-------------+----------------------+----------+-------------
102009 | 1 | 0 | dev-hanccitus003-ncl | 6432 | 2
-- create example table
CREATE TABLE products (
store_id bigint,
product_id bigint,
name text,
price money,
CONSTRAINT products_pkey PRIMARY KEY (store_id, product_id)
);
-- pick store_id as distribution column
SELECT create_distributed_table('products', 'store_id');
-- get distribution column name for products table
SELECT column_to_column_name(logicalrelid, partkey) AS dist_col_name
FROM pg_dist_partition
WHERE logicalrelid='products'::regclass;
dist_col_name
---------------
store_id
installation
git clone -b v${CITUS_VER} https://github.com/citusdata/citus.git citus-v${CITUS_VER}
./configure
make
sudo make install
# config 수정
vi $PGDATA/postgresql.conf
shared_preload_libraries = 'citus'
vi $PGDATA/pg_hba.conf
sudo vi /etc/hosts
10.113.252.215 dev-hanccitus001-ncl.nfra.io dev-hanccitus001-ncl
10.113.252.111 dev-hanccitus002-ncl.nfra.io dev-hanccitus002-ncl
10.113.254.10 dev-hanccitus003-ncl.nfra.io dev-hanccitus003-ncl
10.113.255.8 dev-hanccitus004-ncl.nfra.io dev-hanccitus004-ncl
# restart
pg_ctl stop
pg_ctl start
SELECT * FROM pg_available_extensions WHERE name='citus';
name | default_version | installed_version | comment
-------+-----------------+-------------------+----------------------------
citus | 8.3-1 | 8.3-1 | Citus distributed database
SHOW shared_preload_libraries ;
shared_preload_libraries
--------------------------
citus
CREATE EXTENSION citus ;
postgres=# dx
List of installed extensions
Name | Version | Schema | Description
---------+---------+------------+------------------------------
citus | 8.3-1 | pg_catalog | Citus distributed database
add worker nodes
SELECT * from master_add_node('dev-hanccitus002-ncl', 6432);
SELECT * from master_add_node('dev-hanccitus003-ncl', 6432);
SELECT * from master_add_node('dev-hanccitus004-ncl', 6432);
SELECT * FROM master_get_active_worker_nodes();
node_name | node_port
----------------------+-----------
dev-hanccitus004-ncl | 6432
dev-hanccitus002-ncl | 6432
dev-hanccitus003-ncl | 6432
CREATE TABLE sales
(deptno int not null,
deptname varchar(20),
total_amount int,
CONSTRAINT pk_sales PRIMARY KEY (deptno)) ;
SELECT create_distributed_table('sales', 'deptno');
insert into sales (deptno,deptname,total_amount) values (1,'french_dept',10000);
insert into sales (deptno,deptname,total_amount) values (2,'german_dept',15000);
insert into sales (deptno,deptname,total_amount) values (3,'china_dept',21000);
insert into sales (deptno,deptname,total_amount) values (4,'gambia_dept',8750);
insert into sales (deptno,deptname,total_amount) values (5,'japan_dept',12010);
insert into sales (deptno,deptname,total_amount) values (6,'china_dept',35000);
insert into sales (deptno,deptname,total_amount) values (7,'nigeria_dept',10000);
insert into sales (deptno,deptname,total_amount) values (8,'senegal_dept',33000);
insert into sales (deptno,deptname,total_amount) values (9,'korea_dept',43000);
insert into sales (deptno,deptname,total_amount) values (10,'usa_dept',5000);
create_distributed_table
explain
naverdb=> explain verbose select * from sales where deptno=2;
QUERY PLAN
------------------------------------------------------------------------------------------------------------
Custom Scan (Citus Adaptive) (cost=0.00..0.00 rows=0 width=0)
Output: remote_scan.deptno, remote_scan.deptname, remote_scan.total_amount
Task Count: 1
Tasks Shown: All
-> Task
Node: host=dev-hanccitus002-ncl port=6432 dbname=naverdb
-> Index Scan using pk_sales_102032 on appo.sales_102032 sales (cost=0.15..8.17 rows=1 width=66)
Output: deptno, deptname, total_amount
Index Cond: (sales.deptno = 2)
(9 rows)
Time: 3.367 ms
create_reference_table
CREATE TABLE geo_ips (
addrs cidr NOT NULL PRIMARY KEY,
latlon point NOT NULL
CHECK (-90 <= latlon[0] AND latlon[0] <= 90 AND
-180 <= latlon[1] AND latlon[1] <= 180)
);
CREATE INDEX ON geo_ips USING gist (addrs inet_ops);
SELECT create_reference_table('geo_ips');
copy geo_ips from 'geo_ips.csv' with csv
SELECT c.id, clicked_at, latlon
FROM geo_ips, clicks c
WHERE addrs >> c.user_ip
AND c.company_id = 5
AND c.ad_id = 290;
id | clicked_at | latlon
------+---------------------+---------------------
3155 | 2017-03-16 03:56:00 | (42.3763,-85.4597)
3156 | 2017-06-10 09:44:11 | (34.0067,-118.3455)
3158 | 2017-02-11 18:40:11 | (4.5981,-74.0758)
3159 | 2017-05-27 22:38:18 | (42.2399,-83.1508)
3160 | 2017-02-27 07:48:24 | (30.0355,31.223)
3162 | 2017-05-30 14:01:24 | (46.0511,14.5051)
3163 | 2017-02-02 11:20:42 | (46.0511,14.5051)
3164 | 2017-01-22 08:51:16 | (30.0355,31.223)
3168 | 2017-01-12 05:40:53 | (46.0511,14.5051)
3169 | 2017-04-20 21:06:53 | (44.8784,-93.2793)
3171 | 2017-06-12 10:37:48 | (42.2399,-83.1508)
(11 rows)
[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스

More Related Content

What's hot

What's hot (20)

スケールアウトするPostgreSQLを目指して!その第一歩!(NTTデータ テクノロジーカンファレンス 2020 発表資料)
スケールアウトするPostgreSQLを目指して!その第一歩!(NTTデータ テクノロジーカンファレンス 2020 発表資料)スケールアウトするPostgreSQLを目指して!その第一歩!(NTTデータ テクノロジーカンファレンス 2020 発表資料)
スケールアウトするPostgreSQLを目指して!その第一歩!(NTTデータ テクノロジーカンファレンス 2020 発表資料)
 
バックアップと障害復旧から考えるOracle Database, MySQL, PostgreSQLの違い - Database Lounge Tokyo #2
バックアップと障害復旧から考えるOracle Database, MySQL, PostgreSQLの違い - Database Lounge Tokyo #2バックアップと障害復旧から考えるOracle Database, MySQL, PostgreSQLの違い - Database Lounge Tokyo #2
バックアップと障害復旧から考えるOracle Database, MySQL, PostgreSQLの違い - Database Lounge Tokyo #2
 
これからLDAPを始めるなら 「389-ds」を使ってみよう
これからLDAPを始めるなら 「389-ds」を使ってみようこれからLDAPを始めるなら 「389-ds」を使ってみよう
これからLDAPを始めるなら 「389-ds」を使ってみよう
 
マネージドPostgreSQLの実現に向けたPostgreSQL機能向上(PostgreSQL Conference Japan 2023 発表資料)
マネージドPostgreSQLの実現に向けたPostgreSQL機能向上(PostgreSQL Conference Japan 2023 発表資料)マネージドPostgreSQLの実現に向けたPostgreSQL機能向上(PostgreSQL Conference Japan 2023 発表資料)
マネージドPostgreSQLの実現に向けたPostgreSQL機能向上(PostgreSQL Conference Japan 2023 発表資料)
 
CentOS 8で標準搭載! 「389-ds」で構築する 認証サーバーについて
CentOS 8で標準搭載! 「389-ds」で構築する 認証サーバーについてCentOS 8で標準搭載! 「389-ds」で構築する 認証サーバーについて
CentOS 8で標準搭載! 「389-ds」で構築する 認証サーバーについて
 
Deep dive into PostgreSQL statistics.
Deep dive into PostgreSQL statistics.Deep dive into PostgreSQL statistics.
Deep dive into PostgreSQL statistics.
 
Memoizeの仕組み(第41回PostgreSQLアンカンファレンス@オンライン 発表資料)
Memoizeの仕組み(第41回PostgreSQLアンカンファレンス@オンライン 発表資料)Memoizeの仕組み(第41回PostgreSQLアンカンファレンス@オンライン 発表資料)
Memoizeの仕組み(第41回PostgreSQLアンカンファレンス@オンライン 発表資料)
 
使ってみませんか?pg_hint_plan
使ってみませんか?pg_hint_plan使ってみませんか?pg_hint_plan
使ってみませんか?pg_hint_plan
 
Postgres Performance for Humans
Postgres Performance for HumansPostgres Performance for Humans
Postgres Performance for Humans
 
PostgreSQLレプリケーション10周年!徹底紹介!(PostgreSQL Conference Japan 2019講演資料)
PostgreSQLレプリケーション10周年!徹底紹介!(PostgreSQL Conference Japan 2019講演資料)PostgreSQLレプリケーション10周年!徹底紹介!(PostgreSQL Conference Japan 2019講演資料)
PostgreSQLレプリケーション10周年!徹底紹介!(PostgreSQL Conference Japan 2019講演資料)
 
PostgreSQL High_Performance_Cheatsheet
PostgreSQL High_Performance_CheatsheetPostgreSQL High_Performance_Cheatsheet
PostgreSQL High_Performance_Cheatsheet
 
Mvcc in postgreSQL 권건우
Mvcc in postgreSQL 권건우Mvcc in postgreSQL 권건우
Mvcc in postgreSQL 권건우
 
今、改めて考えるPostgreSQLプラットフォーム - マルチクラウドとポータビリティ -(PostgreSQL Conference Japan 20...
今、改めて考えるPostgreSQLプラットフォーム - マルチクラウドとポータビリティ -(PostgreSQL Conference Japan 20...今、改めて考えるPostgreSQLプラットフォーム - マルチクラウドとポータビリティ -(PostgreSQL Conference Japan 20...
今、改めて考えるPostgreSQLプラットフォーム - マルチクラウドとポータビリティ -(PostgreSQL Conference Japan 20...
 
1日5分でPostgreSQLに詳しくなるアプリの開発 ~PostgRESTを使ってみた~(第38回PostgreSQLアンカンファレンス@オンライン 発...
1日5分でPostgreSQLに詳しくなるアプリの開発 ~PostgRESTを使ってみた~(第38回PostgreSQLアンカンファレンス@オンライン 発...1日5分でPostgreSQLに詳しくなるアプリの開発 ~PostgRESTを使ってみた~(第38回PostgreSQLアンカンファレンス@オンライン 発...
1日5分でPostgreSQLに詳しくなるアプリの開発 ~PostgRESTを使ってみた~(第38回PostgreSQLアンカンファレンス@オンライン 発...
 
PostgreSQLのロール管理とその注意点(Open Source Conference 2022 Online/Osaka 発表資料)
PostgreSQLのロール管理とその注意点(Open Source Conference 2022 Online/Osaka 発表資料)PostgreSQLのロール管理とその注意点(Open Source Conference 2022 Online/Osaka 発表資料)
PostgreSQLのロール管理とその注意点(Open Source Conference 2022 Online/Osaka 発表資料)
 
What is new in PostgreSQL 14?
What is new in PostgreSQL 14?What is new in PostgreSQL 14?
What is new in PostgreSQL 14?
 
How to Use JSON in MySQL Wrong
How to Use JSON in MySQL WrongHow to Use JSON in MySQL Wrong
How to Use JSON in MySQL Wrong
 
Percona toolkit
Percona toolkitPercona toolkit
Percona toolkit
 
PostgreSQL Administration for System Administrators
PostgreSQL Administration for System AdministratorsPostgreSQL Administration for System Administrators
PostgreSQL Administration for System Administrators
 
Working with JSON Data in PostgreSQL vs. MongoDB
Working with JSON Data in PostgreSQL vs. MongoDBWorking with JSON Data in PostgreSQL vs. MongoDB
Working with JSON Data in PostgreSQL vs. MongoDB
 

Similar to [Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스

Advanced tips of dbms statas
Advanced tips of dbms statasAdvanced tips of dbms statas
Advanced tips of dbms statas
Louis liu
 
Postgres performance for humans
Postgres performance for humansPostgres performance for humans
Postgres performance for humans
Craig Kerstiens
 
Understanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
Understanding Query Optimization with ‘regular’ and ‘Exadata’ OracleUnderstanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
Understanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
Guatemala User Group
 
John Melesky - Federating Queries Using Postgres FDW @ Postgres Open
John Melesky - Federating Queries Using Postgres FDW @ Postgres OpenJohn Melesky - Federating Queries Using Postgres FDW @ Postgres Open
John Melesky - Federating Queries Using Postgres FDW @ Postgres Open
PostgresOpen
 
11thingsabout11g 12659705398222 Phpapp01
11thingsabout11g 12659705398222 Phpapp0111thingsabout11g 12659705398222 Phpapp01
11thingsabout11g 12659705398222 Phpapp01
Karam Abuataya
 

Similar to [Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스 (20)

Advanced tips of dbms statas
Advanced tips of dbms statasAdvanced tips of dbms statas
Advanced tips of dbms statas
 
Drizzle to MySQL, Stress Free Migration
Drizzle to MySQL, Stress Free MigrationDrizzle to MySQL, Stress Free Migration
Drizzle to MySQL, Stress Free Migration
 
PostgreSQL 9.6 새 기능 소개
PostgreSQL 9.6 새 기능 소개PostgreSQL 9.6 새 기능 소개
PostgreSQL 9.6 새 기능 소개
 
クラウドDWHとしても進化を続けるPivotal Greenplumご紹介
クラウドDWHとしても進化を続けるPivotal Greenplumご紹介クラウドDWHとしても進化を続けるPivotal Greenplumご紹介
クラウドDWHとしても進化を続けるPivotal Greenplumご紹介
 
MySQLinsanity
MySQLinsanityMySQLinsanity
MySQLinsanity
 
Введение в современную PostgreSQL. Часть 2
Введение в современную PostgreSQL. Часть 2Введение в современную PostgreSQL. Часть 2
Введение в современную PostgreSQL. Часть 2
 
Sql2
Sql2Sql2
Sql2
 
New Tuning Features in Oracle 11g - How to make your database as boring as po...
New Tuning Features in Oracle 11g - How to make your database as boring as po...New Tuning Features in Oracle 11g - How to make your database as boring as po...
New Tuning Features in Oracle 11g - How to make your database as boring as po...
 
Postgres performance for humans
Postgres performance for humansPostgres performance for humans
Postgres performance for humans
 
OpenWorld Sep14 12c for_developers
OpenWorld Sep14 12c for_developersOpenWorld Sep14 12c for_developers
OpenWorld Sep14 12c for_developers
 
SQLQueries
SQLQueriesSQLQueries
SQLQueries
 
Understanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
Understanding Query Optimization with ‘regular’ and ‘Exadata’ OracleUnderstanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
Understanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
 
Oracle dbms_xplan.display_cursor format
Oracle dbms_xplan.display_cursor formatOracle dbms_xplan.display_cursor format
Oracle dbms_xplan.display_cursor format
 
Basicsof c make and git for a hello qt application
Basicsof c make and git for a hello qt applicationBasicsof c make and git for a hello qt application
Basicsof c make and git for a hello qt application
 
Hadoop Integration in Cassandra
Hadoop Integration in CassandraHadoop Integration in Cassandra
Hadoop Integration in Cassandra
 
The Hidden Face of Cost-Based Optimizer: PL/SQL Specific Statistics
The Hidden Face of Cost-Based Optimizer: PL/SQL Specific StatisticsThe Hidden Face of Cost-Based Optimizer: PL/SQL Specific Statistics
The Hidden Face of Cost-Based Optimizer: PL/SQL Specific Statistics
 
John Melesky - Federating Queries Using Postgres FDW @ Postgres Open
John Melesky - Federating Queries Using Postgres FDW @ Postgres OpenJohn Melesky - Federating Queries Using Postgres FDW @ Postgres Open
John Melesky - Federating Queries Using Postgres FDW @ Postgres Open
 
Introduction to MySQL InnoDB Cluster
Introduction to MySQL InnoDB ClusterIntroduction to MySQL InnoDB Cluster
Introduction to MySQL InnoDB Cluster
 
11thingsabout11g 12659705398222 Phpapp01
11thingsabout11g 12659705398222 Phpapp0111thingsabout11g 12659705398222 Phpapp01
11thingsabout11g 12659705398222 Phpapp01
 
11 Things About11g
11 Things About11g11 Things About11g
11 Things About11g
 

More from PgDay.Seoul

More from PgDay.Seoul (20)

[pgday.Seoul 2022] 서비스개편시 PostgreSQL 도입기 - 진소린 & 김태정
[pgday.Seoul 2022] 서비스개편시 PostgreSQL 도입기 - 진소린 & 김태정[pgday.Seoul 2022] 서비스개편시 PostgreSQL 도입기 - 진소린 & 김태정
[pgday.Seoul 2022] 서비스개편시 PostgreSQL 도입기 - 진소린 & 김태정
 
[pgday.Seoul 2022] POSTGRES 테스트코드로 기여하기 - 이동욱
[pgday.Seoul 2022] POSTGRES 테스트코드로 기여하기 - 이동욱[pgday.Seoul 2022] POSTGRES 테스트코드로 기여하기 - 이동욱
[pgday.Seoul 2022] POSTGRES 테스트코드로 기여하기 - 이동욱
 
[pgday.Seoul 2022] PostgreSQL구조 - 윤성재
[pgday.Seoul 2022] PostgreSQL구조 - 윤성재[pgday.Seoul 2022] PostgreSQL구조 - 윤성재
[pgday.Seoul 2022] PostgreSQL구조 - 윤성재
 
[pgday.Seoul 2022] PostgreSQL with Google Cloud
[pgday.Seoul 2022] PostgreSQL with Google Cloud[pgday.Seoul 2022] PostgreSQL with Google Cloud
[pgday.Seoul 2022] PostgreSQL with Google Cloud
 
[Pgday.Seoul 2021] 2. Porting Oracle UDF and Optimization
[Pgday.Seoul 2021] 2. Porting Oracle UDF and Optimization[Pgday.Seoul 2021] 2. Porting Oracle UDF and Optimization
[Pgday.Seoul 2021] 2. Porting Oracle UDF and Optimization
 
[Pgday.Seoul 2021] 1. 예제로 살펴보는 포스트그레스큐엘의 독특한 SQL
[Pgday.Seoul 2021] 1. 예제로 살펴보는 포스트그레스큐엘의 독특한 SQL[Pgday.Seoul 2021] 1. 예제로 살펴보는 포스트그레스큐엘의 독특한 SQL
[Pgday.Seoul 2021] 1. 예제로 살펴보는 포스트그레스큐엘의 독특한 SQL
 
[Pgday.Seoul 2020] 포스트그레스큐엘 자국어화 이야기
[Pgday.Seoul 2020] 포스트그레스큐엘 자국어화 이야기[Pgday.Seoul 2020] 포스트그레스큐엘 자국어화 이야기
[Pgday.Seoul 2020] 포스트그레스큐엘 자국어화 이야기
 
[Pgday.Seoul 2020] SQL Tuning
[Pgday.Seoul 2020] SQL Tuning[Pgday.Seoul 2020] SQL Tuning
[Pgday.Seoul 2020] SQL Tuning
 
[Pgday.Seoul 2019] AppOS 고성능 I/O 확장 모듈로 성능 10배 향상시키기
[Pgday.Seoul 2019] AppOS 고성능 I/O 확장 모듈로 성능 10배 향상시키기[Pgday.Seoul 2019] AppOS 고성능 I/O 확장 모듈로 성능 10배 향상시키기
[Pgday.Seoul 2019] AppOS 고성능 I/O 확장 모듈로 성능 10배 향상시키기
 
[Pgday.Seoul 2019] Advanced FDW
[Pgday.Seoul 2019] Advanced FDW[Pgday.Seoul 2019] Advanced FDW
[Pgday.Seoul 2019] Advanced FDW
 
[Pgday.Seoul 2018] PostgreSQL 11 새 기능 소개
[Pgday.Seoul 2018]  PostgreSQL 11 새 기능 소개[Pgday.Seoul 2018]  PostgreSQL 11 새 기능 소개
[Pgday.Seoul 2018] PostgreSQL 11 새 기능 소개
 
[Pgday.Seoul 2018] PostgreSQL 성능을 위해 개발된 라이브러리 OS 소개 apposha
[Pgday.Seoul 2018]  PostgreSQL 성능을 위해 개발된 라이브러리 OS 소개 apposha[Pgday.Seoul 2018]  PostgreSQL 성능을 위해 개발된 라이브러리 OS 소개 apposha
[Pgday.Seoul 2018] PostgreSQL 성능을 위해 개발된 라이브러리 OS 소개 apposha
 
[Pgday.Seoul 2018] PostgreSQL Authentication with FreeIPA
[Pgday.Seoul 2018]  PostgreSQL Authentication with FreeIPA[Pgday.Seoul 2018]  PostgreSQL Authentication with FreeIPA
[Pgday.Seoul 2018] PostgreSQL Authentication with FreeIPA
 
[Pgday.Seoul 2018] AWS Cloud 환경에서 PostgreSQL 구축하기
[Pgday.Seoul 2018]  AWS Cloud 환경에서 PostgreSQL 구축하기[Pgday.Seoul 2018]  AWS Cloud 환경에서 PostgreSQL 구축하기
[Pgday.Seoul 2018] AWS Cloud 환경에서 PostgreSQL 구축하기
 
[Pgday.Seoul 2018] Greenplum의 노드 분산 설계
[Pgday.Seoul 2018]  Greenplum의 노드 분산 설계[Pgday.Seoul 2018]  Greenplum의 노드 분산 설계
[Pgday.Seoul 2018] Greenplum의 노드 분산 설계
 
[Pgday.Seoul 2018] replacing oracle with edb postgres
[Pgday.Seoul 2018] replacing oracle with edb postgres[Pgday.Seoul 2018] replacing oracle with edb postgres
[Pgday.Seoul 2018] replacing oracle with edb postgres
 
[Pgday.Seoul 2017] 6. GIN vs GiST 인덱스 이야기 - 박진우
[Pgday.Seoul 2017] 6. GIN vs GiST 인덱스 이야기 - 박진우[Pgday.Seoul 2017] 6. GIN vs GiST 인덱스 이야기 - 박진우
[Pgday.Seoul 2017] 6. GIN vs GiST 인덱스 이야기 - 박진우
 
[Pgday.Seoul 2017] 5. 테드폴허브(올챙이) PostgreSQL 확장하기 - 조현종
[Pgday.Seoul 2017] 5. 테드폴허브(올챙이) PostgreSQL 확장하기 - 조현종[Pgday.Seoul 2017] 5. 테드폴허브(올챙이) PostgreSQL 확장하기 - 조현종
[Pgday.Seoul 2017] 5. 테드폴허브(올챙이) PostgreSQL 확장하기 - 조현종
 
[Pgday.Seoul 2017] 1. PostGIS의 사례로 본 PostgreSQL 확장 - 장병진
[Pgday.Seoul 2017] 1. PostGIS의 사례로 본 PostgreSQL 확장 - 장병진[Pgday.Seoul 2017] 1. PostGIS의 사례로 본 PostgreSQL 확장 - 장병진
[Pgday.Seoul 2017] 1. PostGIS의 사례로 본 PostgreSQL 확장 - 장병진
 
[Pgday.Seoul 2017] 7. PostgreSQL DB Tuning 기업사례 - 송춘자
[Pgday.Seoul 2017] 7. PostgreSQL DB Tuning 기업사례 - 송춘자[Pgday.Seoul 2017] 7. PostgreSQL DB Tuning 기업사례 - 송춘자
[Pgday.Seoul 2017] 7. PostgreSQL DB Tuning 기업사례 - 송춘자
 

Recently uploaded

Recently uploaded (20)

Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
 
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
 
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
 
Crafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM IntegrationCrafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM Integration
 
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with StrimziStrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi
 
The Impact of PLM Software on Fashion Production
The Impact of PLM Software on Fashion ProductionThe Impact of PLM Software on Fashion Production
The Impact of PLM Software on Fashion Production
 
KLARNA - Language Models and Knowledge Graphs: A Systems Approach
KLARNA -  Language Models and Knowledge Graphs: A Systems ApproachKLARNA -  Language Models and Knowledge Graphs: A Systems Approach
KLARNA - Language Models and Knowledge Graphs: A Systems Approach
 
how-to-download-files-safely-from-the-internet.pdf
how-to-download-files-safely-from-the-internet.pdfhow-to-download-files-safely-from-the-internet.pdf
how-to-download-files-safely-from-the-internet.pdf
 
Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web Services
 
INGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by DesignINGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by Design
 
A Guideline to Gorgias to to Re:amaze Data Migration
A Guideline to Gorgias to to Re:amaze Data MigrationA Guideline to Gorgias to to Re:amaze Data Migration
A Guideline to Gorgias to to Re:amaze Data Migration
 
CompTIA Security+ (Study Notes) for cs.pdf
CompTIA Security+ (Study Notes) for cs.pdfCompTIA Security+ (Study Notes) for cs.pdf
CompTIA Security+ (Study Notes) for cs.pdf
 
Microsoft 365 Copilot; An AI tool changing the world of work _PDF.pdf
Microsoft 365 Copilot; An AI tool changing the world of work _PDF.pdfMicrosoft 365 Copilot; An AI tool changing the world of work _PDF.pdf
Microsoft 365 Copilot; An AI tool changing the world of work _PDF.pdf
 
iGaming Platform & Lottery Solutions by Skilrock
iGaming Platform & Lottery Solutions by SkilrockiGaming Platform & Lottery Solutions by Skilrock
iGaming Platform & Lottery Solutions by Skilrock
 
Agnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in KrakówAgnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in Kraków
 
5 Reasons Driving Warehouse Management Systems Demand
5 Reasons Driving Warehouse Management Systems Demand5 Reasons Driving Warehouse Management Systems Demand
5 Reasons Driving Warehouse Management Systems Demand
 
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
 
Studiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting softwareStudiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting software
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
 
OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024
 

[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스

  • 1.
  • 2.
  • 3.
  • 8. naverdb=> select * from pg_dist_shard where logicalrelid='companies'::regclass order by 2; logicalrelid | shardid | shardstorage | shardminvalue | shardmaxvalue --------------+---------+--------------+---------------+--------------- companies | 102200 | t | -2147483648 | -1073741825 companies | 102201 | t | -1073741824 | -1 companies | 102202 | t | 0 | 1073741823 companies | 102203 | t | 1073741824 | 2147483647 (4 rows) SELECT shardid, node.nodename, node.nodeport FROM pg_dist_placement placement JOIN pg_dist_node node ON placement.groupid = node.groupid AND node.noderole = 'primary'::noderole WHERE shardid in ('102200','102201','102202','102203') shardid | nodename | nodeport ---------+----------------------+---------- 102200 | dev-hanccitus002-ncl | 6432 102201 | dev-hanccitus003-ncl | 6432 102202 | dev-hanccitus004-ncl | 6432 102203 | dev-hanccitus002-ncl | 6432 (4 rows)
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19. • Rebalance Shards without Downtime
  • 20.
  • 21. select master_update_node(nodeid, 'new-address', nodeport) from pg_dist_node where nodename = 'old-address';
  • 22. select * from sales where deptno=1; deptno | deptname | total_amount --------+-------------+-------------- 1 | french_dept | 10000 SELECT shardid, shardstate, shardlength, nodename, nodeport, placementid FROM pg_dist_placement AS placement, pg_dist_node AS node WHERE placement.groupid = node.groupid AND node.noderole = 'primary' AND shardid = ( SELECT get_shard_id_for_distribution_column('sales', 1) ); shardid | shardstate | shardlength | nodename | nodeport | placementid ---------+------------+-------------+----------------------+----------+------------- 102009 | 1 | 0 | dev-hanccitus003-ncl | 6432 | 2
  • 23. -- create example table CREATE TABLE products ( store_id bigint, product_id bigint, name text, price money, CONSTRAINT products_pkey PRIMARY KEY (store_id, product_id) ); -- pick store_id as distribution column SELECT create_distributed_table('products', 'store_id'); -- get distribution column name for products table SELECT column_to_column_name(logicalrelid, partkey) AS dist_col_name FROM pg_dist_partition WHERE logicalrelid='products'::regclass; dist_col_name --------------- store_id
  • 24.
  • 25. installation git clone -b v${CITUS_VER} https://github.com/citusdata/citus.git citus-v${CITUS_VER} ./configure make sudo make install # config 수정 vi $PGDATA/postgresql.conf shared_preload_libraries = 'citus' vi $PGDATA/pg_hba.conf sudo vi /etc/hosts 10.113.252.215 dev-hanccitus001-ncl.nfra.io dev-hanccitus001-ncl 10.113.252.111 dev-hanccitus002-ncl.nfra.io dev-hanccitus002-ncl 10.113.254.10 dev-hanccitus003-ncl.nfra.io dev-hanccitus003-ncl 10.113.255.8 dev-hanccitus004-ncl.nfra.io dev-hanccitus004-ncl # restart pg_ctl stop pg_ctl start SELECT * FROM pg_available_extensions WHERE name='citus'; name | default_version | installed_version | comment -------+-----------------+-------------------+---------------------------- citus | 8.3-1 | 8.3-1 | Citus distributed database SHOW shared_preload_libraries ; shared_preload_libraries -------------------------- citus CREATE EXTENSION citus ; postgres=# dx List of installed extensions Name | Version | Schema | Description ---------+---------+------------+------------------------------ citus | 8.3-1 | pg_catalog | Citus distributed database
  • 26. add worker nodes SELECT * from master_add_node('dev-hanccitus002-ncl', 6432); SELECT * from master_add_node('dev-hanccitus003-ncl', 6432); SELECT * from master_add_node('dev-hanccitus004-ncl', 6432); SELECT * FROM master_get_active_worker_nodes(); node_name | node_port ----------------------+----------- dev-hanccitus004-ncl | 6432 dev-hanccitus002-ncl | 6432 dev-hanccitus003-ncl | 6432 CREATE TABLE sales (deptno int not null, deptname varchar(20), total_amount int, CONSTRAINT pk_sales PRIMARY KEY (deptno)) ; SELECT create_distributed_table('sales', 'deptno'); insert into sales (deptno,deptname,total_amount) values (1,'french_dept',10000); insert into sales (deptno,deptname,total_amount) values (2,'german_dept',15000); insert into sales (deptno,deptname,total_amount) values (3,'china_dept',21000); insert into sales (deptno,deptname,total_amount) values (4,'gambia_dept',8750); insert into sales (deptno,deptname,total_amount) values (5,'japan_dept',12010); insert into sales (deptno,deptname,total_amount) values (6,'china_dept',35000); insert into sales (deptno,deptname,total_amount) values (7,'nigeria_dept',10000); insert into sales (deptno,deptname,total_amount) values (8,'senegal_dept',33000); insert into sales (deptno,deptname,total_amount) values (9,'korea_dept',43000); insert into sales (deptno,deptname,total_amount) values (10,'usa_dept',5000); create_distributed_table
  • 27. explain naverdb=> explain verbose select * from sales where deptno=2; QUERY PLAN ------------------------------------------------------------------------------------------------------------ Custom Scan (Citus Adaptive) (cost=0.00..0.00 rows=0 width=0) Output: remote_scan.deptno, remote_scan.deptname, remote_scan.total_amount Task Count: 1 Tasks Shown: All -> Task Node: host=dev-hanccitus002-ncl port=6432 dbname=naverdb -> Index Scan using pk_sales_102032 on appo.sales_102032 sales (cost=0.15..8.17 rows=1 width=66) Output: deptno, deptname, total_amount Index Cond: (sales.deptno = 2) (9 rows) Time: 3.367 ms
  • 28. create_reference_table CREATE TABLE geo_ips ( addrs cidr NOT NULL PRIMARY KEY, latlon point NOT NULL CHECK (-90 <= latlon[0] AND latlon[0] <= 90 AND -180 <= latlon[1] AND latlon[1] <= 180) ); CREATE INDEX ON geo_ips USING gist (addrs inet_ops); SELECT create_reference_table('geo_ips'); copy geo_ips from 'geo_ips.csv' with csv SELECT c.id, clicked_at, latlon FROM geo_ips, clicks c WHERE addrs >> c.user_ip AND c.company_id = 5 AND c.ad_id = 290; id | clicked_at | latlon ------+---------------------+--------------------- 3155 | 2017-03-16 03:56:00 | (42.3763,-85.4597) 3156 | 2017-06-10 09:44:11 | (34.0067,-118.3455) 3158 | 2017-02-11 18:40:11 | (4.5981,-74.0758) 3159 | 2017-05-27 22:38:18 | (42.2399,-83.1508) 3160 | 2017-02-27 07:48:24 | (30.0355,31.223) 3162 | 2017-05-30 14:01:24 | (46.0511,14.5051) 3163 | 2017-02-02 11:20:42 | (46.0511,14.5051) 3164 | 2017-01-22 08:51:16 | (30.0355,31.223) 3168 | 2017-01-12 05:40:53 | (46.0511,14.5051) 3169 | 2017-04-20 21:06:53 | (44.8784,-93.2793) 3171 | 2017-06-12 10:37:48 | (42.2399,-83.1508) (11 rows)