已知命令行使用utility,但是业务需要java程序获取greenplum分区表所在的节点,直接访问节点的数据库查数据
直连greenplum segment节点的方法, utility模式 :
使用这种方式,不与其他节点通讯,只操作当前节点。也没有数据分布的概念。
如果使用utility模式连接的是master节点,写入数据时,数据不会分布到segment,使用正常模式连接后,写入master的数据也查不出来。
$ PGOPTIONS='-c gp_session_role=utility' psql -p 40005
psql (8.2.15)
Type "help" for help.
postgres=# \dt
List of relations
Schema | Name | Type | Owner | Storage
--------+------+-------+----------+---------
public | t | table | digoal | heap
public | test | table | digoal | heap
Map<String, Object> params = new HashMap<>();
params.put("dbtype", "postgis");
params.put("host", "1xx.16.1.xx");
params.put("port", 6004);
params.put("schema", "public");
params.put("database", "bigdata");
params.put("user", "admin");
params.put("passwd", "admin");
params.put("gp_session_role","utility");
DataStore dataStore = DataStoreFinder.getDataStore(params);
Exception in thread "main" java.lang.RuntimeException: Unable to obtain connection: Cannot create PoolableConnectionFactory (FATAL: connections to primary segments are not allowed
详细:This database instance is running as a primary segment in a Greenplum cluster and does not permit direct connections.
建议:To force a connection anyway (dangerous!), use utility mode.)