Fail to create distributed table from within PL/JAVA routine

15 views
Skip to first unread message

Erik Mata

unread,
Nov 19, 2020, 9:29:41 AM11/19/20
to citus-users
I have set up a local docker environment with a total of 4 Postgres server instances, all including Citus (9.4.1) and PL/JAVA (1.6.0) extensions:
- 1 as Citus master
- 3 as Citus workers

I have set up a simple routine in PL/JAVA which creates a table and requests that the table be distributed in the cluster, as:

CREATE TABLE test1 (a BIGINT PRIMARY KEY);
SELECT create_distributed_table('test1', 'a', colocate_with=>'none');

I connect to the Citus master server via a JDBC-connection to localhost.
I then call the PL/JAVA routine, as:

SELECT test_create_distributed_table();

This results in a local table being created on the Citus master node, but no tables are created on the workers and the Citus utility functions tell me that the table is NOT distributed.

If I use the same statements that I have included in the PL/JAVA routine (see above), but I execute them from within e.g. DataGrip, connected to the Citus master node, the table is created and distributed correctly. I can see that the correct tables are created on the workers and the Citus utility functions tell me that the table is indeed distributed.

So, it seems that there is nothing wrong with my setup (cluster).

The problem, as far as I can tell, should be somewhere in how PL/JAVA connects to the Citus master node. The PL/JAVA routine runs in a JVM that is spawned by the Postgres server process on the Citus master node. The PL/JAVA routine acquires a connection to the local database via a somewhat fake JDBC-connection (jdbc:default:connection) as explained in the PL/JAVA documentation.

I suspect that this fake JDBC-connection is the reason that the Citus master node is unable to distribute the table to the rest of the cluster nodes.

As a side-note: From within PL/JAVA routines, I am able to execute other types of statements that interact with distributed tables created outside of the PL/JAVA routine. I am able to DROP, TRUNCATE, INSERT, UPDATE, DELETE etc. Just not SELECT create_distributed_table.

Any help is appreciated!
Reply all
Reply to author
Forward
0 new messages