SlideShare a Scribd company logo
1 of 29
Download to read offline
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)

Percona Live 2022 - MySQL Architectures
Percona Live 2022 - MySQL ArchitecturesPercona Live 2022 - MySQL Architectures
Percona Live 2022 - MySQL Architectures
 
PostgreSQL Replication High Availability Methods
PostgreSQL Replication High Availability MethodsPostgreSQL Replication High Availability Methods
PostgreSQL Replication High Availability Methods
 
[Pgday.Seoul 2017] 8. PostgreSQL 10 새기능 소개 - 김상기
[Pgday.Seoul 2017] 8. PostgreSQL 10 새기능 소개 - 김상기[Pgday.Seoul 2017] 8. PostgreSQL 10 새기능 소개 - 김상기
[Pgday.Seoul 2017] 8. PostgreSQL 10 새기능 소개 - 김상기
 
MySQL/MariaDB Proxy Software Test
MySQL/MariaDB Proxy Software TestMySQL/MariaDB Proxy Software Test
MySQL/MariaDB Proxy Software Test
 
MariaDB 10.11 key features overview for DBAs
MariaDB 10.11 key features overview for DBAsMariaDB 10.11 key features overview for DBAs
MariaDB 10.11 key features overview for DBAs
 
Oracleのトランケートについて知っておくべきこと
Oracleのトランケートについて知っておくべきことOracleのトランケートについて知っておくべきこと
Oracleのトランケートについて知っておくべきこと
 
redis 소개자료 - 네오클로바
redis 소개자료 - 네오클로바redis 소개자료 - 네오클로바
redis 소개자료 - 네오클로바
 
PostgreSQL- An Introduction
PostgreSQL- An IntroductionPostgreSQL- An Introduction
PostgreSQL- An Introduction
 
Pgday bdr 천정대
Pgday bdr 천정대Pgday bdr 천정대
Pgday bdr 천정대
 
祝!PostgreSQLレプリケーション10周年!徹底紹介!!
祝!PostgreSQLレプリケーション10周年!徹底紹介!!祝!PostgreSQLレプリケーション10周年!徹底紹介!!
祝!PostgreSQLレプリケーション10周年!徹底紹介!!
 
[Pgday.Seoul 2020] SQL Tuning
[Pgday.Seoul 2020] SQL Tuning[Pgday.Seoul 2020] SQL Tuning
[Pgday.Seoul 2020] SQL Tuning
 
PostgreSQL Deep Internal
PostgreSQL Deep InternalPostgreSQL Deep Internal
PostgreSQL Deep Internal
 
[pgday.Seoul 2022] PostgreSQL구조 - 윤성재
[pgday.Seoul 2022] PostgreSQL구조 - 윤성재[pgday.Seoul 2022] PostgreSQL구조 - 윤성재
[pgday.Seoul 2022] PostgreSQL구조 - 윤성재
 
Histograms in MariaDB, MySQL and PostgreSQL
Histograms in MariaDB, MySQL and PostgreSQLHistograms in MariaDB, MySQL and PostgreSQL
Histograms in MariaDB, MySQL and PostgreSQL
 
ProxySQL and the Tricks Up Its Sleeve - Percona Live 2022.pdf
ProxySQL and the Tricks Up Its Sleeve - Percona Live 2022.pdfProxySQL and the Tricks Up Its Sleeve - Percona Live 2022.pdf
ProxySQL and the Tricks Up Its Sleeve - Percona Live 2022.pdf
 
Keepalived+MaxScale+MariaDB_운영매뉴얼_1.0.docx
Keepalived+MaxScale+MariaDB_운영매뉴얼_1.0.docxKeepalived+MaxScale+MariaDB_운영매뉴얼_1.0.docx
Keepalived+MaxScale+MariaDB_운영매뉴얼_1.0.docx
 
PostgreSQL and RAM usage
PostgreSQL and RAM usagePostgreSQL and RAM usage
PostgreSQL and RAM usage
 
ProxySQL at Scale on AWS.pdf
ProxySQL at Scale on AWS.pdfProxySQL at Scale on AWS.pdf
ProxySQL at Scale on AWS.pdf
 
あなたの知らないPostgreSQL監視の世界
あなたの知らないPostgreSQL監視の世界あなたの知らないPostgreSQL監視の世界
あなたの知らないPostgreSQL監視の世界
 
YugabyteDBの実行計画を眺める(NewSQL/分散SQLデータベースよろず勉強会 #3 発表資料)
YugabyteDBの実行計画を眺める(NewSQL/分散SQLデータベースよろず勉強会 #3 発表資料)YugabyteDBの実行計画を眺める(NewSQL/分散SQLデータベースよろず勉強会 #3 発表資料)
YugabyteDBの実行計画を眺める(NewSQL/分散SQLデータベースよろず勉強会 #3 発表資料)
 

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 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 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] 이기종 DB에서 PostgreSQL로의 Migration을 위한 DB2PG
[Pgday.Seoul 2018]  이기종 DB에서 PostgreSQL로의 Migration을 위한 DB2PG[Pgday.Seoul 2018]  이기종 DB에서 PostgreSQL로의 Migration을 위한 DB2PG
[Pgday.Seoul 2018] 이기종 DB에서 PostgreSQL로의 Migration을 위한 DB2PG
 
[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 기업사례 - 송춘자
 
[Pgday.Seoul 2017] 4. Composite Type/JSON 파라미터를 활용한 TVP구현(with C#, JAVA) - 지현명
[Pgday.Seoul 2017] 4. Composite Type/JSON 파라미터를 활용한 TVP구현(with C#, JAVA) - 지현명[Pgday.Seoul 2017] 4. Composite Type/JSON 파라미터를 활용한 TVP구현(with C#, JAVA) - 지현명
[Pgday.Seoul 2017] 4. Composite Type/JSON 파라미터를 활용한 TVP구현(with C#, JAVA) - 지현명
 

Recently uploaded

%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
chiefasafspells
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 

Recently uploaded (20)

AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 

[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)