表存储了哪个数据节点,如何在postgres-xl中查询?

时间:2015-02-27 07:43:49

标签: postgresql database-partitioning postgres-xl

创建表时,不使用distribute子语句。

如果有2个节点,我怎么能查询该表的实际存储位置?

如果有两个表并且它们属于同一模式,它们是否会存储在不同的数据节点上?

1 个答案:

答案 0 :(得分:1)

来自文档:

If DISTRIBUTE BY is not specified, columns with UNIQUE constraint
will be chosen as the distribution key. If no such column is
specified, distribution column is the first eligible column 
in the definition. If no such column is found, then the table 
will be distributed by ROUNDROBIN.

在您的用例场景中,在不使用TO NODE nodename指令创建表或指定分发方法时,将在所有数据节点中创建该表,并在数据节点之间通过散列或循环分布行。

使用EXECUTE DIRECT(这是一个特定于Postgres-XL的SQL命令),您可以看到哪些行在哪个datanode中:

test_db=# CREATE TABLE test (id integer UNIQUE, name varchar(30) NULL);
CREATE TABLE
test_db=# insert into test (id, name) values (0,'0test');
INSERT 0 1
test_db=# insert into test (id, name) values (1,'1test');
INSERT 0 1
test_db=# insert into test (id, name) values (2,'2test');
INSERT 0 1
test_db=# insert into test (id, name) values (3,'3test');
INSERT 0 1
test_db=# EXECUTE DIRECT ON (datanode1) 'select * from test';
 id | name
----+-------
  1 | 1test
  2 | 2test
(2 rows)

test_db=# EXECUTE DIRECT ON (datanode2) 'select * from test';
 id | name
----+-------
  0 | 0test
  3 | 3test
(2 rows)

正如我刚才提到的,如果你使用 TO NODE节点名称 TO GROUP groupname ,你可以在某个数据节点上存储一个表。