Connecting to Greenplum Database
A newer version of this documentation is available. Use the version menu above to view the most up-to-date release of the Greenplum 6.x documentation.
Connecting to Greenplum Database
The client uses the GPSS Connect service to connect to a specific Greenplum database. The Disconnect service closes the connection to Greenplum.
rpc Connect(ConnectRequest) returns (Session) {} rpc Disconnect(Session) returns (google.protobuf.Empty) {}
The client specifies the information required to connect to Greenplum Database in a ConnectRequest message. The Connect service returns a Session message. The session identifies the client's connection to the GPSS server. The client must provide the session when it invokes metadata- and table-related services on Greenplum Database. The client must also provide the session when it disconnects from Greenplum Database.
message ConnectRequest { string Host = 1; int32 Port = 2; string Username = 3; string Password = 4; string DB = 5; bool UseSSL = 6; } message Session { string ID = 1; }
The following sample includes Java client code to:
- Create and populate a ConnectRequest protocol buffer object.
- Use the blocking stub to call the Connect service.
- Save the Session response object.
- Disconnect the session.
Session mSession = null; String gpMasterHost = "localhost"; Integer gpMasterPort = 15432; String gpRoleName = "gpadmin"; String gpPasswd = "changeme"; String dbname = "testdb"; // create a connect request builder ConnectRequest connReq = ConnectRequest.newBuilder() .setHost(gpMasterHost) .setPort(gpMasterPort) .setUsername(gpRoleName) .setPassword(gpPasswd) .setDB(dbname) .setUseSSL(false) .build(); // use the blocking stub to call the Connect service mSession = bStub.connect(connReq); // (placeholder) do greenplum stuff here // use the blocking stub to call the Disconnect service bStub.disconnect(mSession);
After the GPSS client connects to Greenplum Database, the client can invoke service requests to retrieve information about schemas and tables, and write to Greenplum tables.