【Manager Handbook for Distributed AntDB-T】Detecting the Read-write Separation Function
Detecting the read-write separation function
Information in thepgxc_node table before read-write separation is started:
postgres=# select oid, node_name, node_type from pgxc_node;
oid | node_name | node_type
-------+-----------+-----------
16384 | gcn1 | C
11955 | cn1 | C
16385 | cn2 | C
16386 | cn3 | C
16387 | cn4 | C
16388 | dn1_1 | D
16389 | dn2_1 | D
16390 | dn3_1 | D
16391 | dn4_1 | D
(9 rows)
There is no slave node information, so the read operation is sent to the master node.
postgres=# explain (analyze,verbose) select * from t_demo where id =10;
QUERY PLAN
------------------------------------------------------------------------------------------------------------------------
Data Node Scan on "__REMOTE_FQS_QUERY__" (cost=0.00..0.00 rows=0 width=0) (actual time=10.700..10.705 rows=1 loops=1)
Output: t_demo.id, t_demo.name
Node/s: dn2_1
Remote query: SELECT id, name FROM public.t_demo t_demo WHERE (id = 10)
Planning Time: 0.267 ms
Execution Time: 10.745 ms
(6 rows)
dn2_1 is the master node.
After read-write separation is enabled, there is slave node information in thepgxc_node table of COD.
postgres=# select oid, node_name, node_type from pgxc_node;
oid | node_name | node_type
-------+-----------+-----------
16384 | gcn1 | C
11955 | cn1 | C
16385 | cn2 | C
16386 | cn3 | C
16387 | cn4 | C
16388 | dn1_1 | D
16389 | dn2_1 | D
16390 | dn3_1 | D
16391 | dn4_1 | D
16402 | dn1_2 | E
16403 | dn2_2 | E
16404 | dn3_2 | E
16405 | dn4_2 | E
(13 rows)
In the above result, the node of typeE is the slave node.
Read operations are sent to the slave node.
postgres=# explain (analyze,verbose) select * from t_demo where id =10;
QUERY PLAN
------------------------------------------------------------------------------------------------------------------------
Data Node Scan on "__REMOTE_FQS_QUERY__" (cost=0.00..0.00 rows=0 width=0) (actual time=17.571..17.576 rows=1 loops=1)
Output: t_demo.id, t_demo.name
Node/s: dn2_2
Remote query: SELECT id, name FROM public.t_demo t_demo WHERE (id = 10)
Planning Time: 0.319 ms
Execution Time: 17.636 ms
(6 rows)
dn2_2 is the slave node.