Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

connect to cockroachdb #170

Open
araneta opened this issue Dec 20, 2021 · 6 comments
Open

connect to cockroachdb #170

araneta opened this issue Dec 20, 2021 · 6 comments

Comments

@araneta
Copy link

araneta commented Dec 20, 2021

is it possible to connect to cockroachdb? the connection string is like this :
postgresql://aldo:@free-tier6.gcp-asia-southeast1.cockroachlabs.cloud:26257/defaultdb?sslmode=verify-full&sslrootcert=$HOME/.postgresql/root.crt&options=--cluster%3Dsmoggy-deer-1769

i tried this in the props file but failed

dsl=./dsl
postgres=free-tier6.gcp-asia-southeast1.cockroachlabs.cloud/smoggy-deer-1769.defaultdb?user=aldo&password=KM89dd7]za#Kt3V&sslmode=verify-full&sslrootcert=$HOME/.postgresql/root.crt&options=--cluster%3Dsmoggy-deer-1769
migration
apply
force

@zapov
Copy link
Member

zapov commented Dec 20, 2021

I never tried it so I don't know. Without the error/logs its hard to say anything

@araneta
Copy link
Author

araneta commented Dec 21, 2021

here is the error
Error connecting to the database.
The connection attempt failed.
Retry database connection with different credentials (y/N):

i dont know how to add this line of code
sslmode=verify-full&sslrootcert=$HOME/.postgresql/root.crt&options=--cluster%3Dsmoggy-deer-1769
in the props file

@zapov
Copy link
Member

zapov commented Dec 21, 2021

CLC does not understand variables, so try it without the $HOME (just to test if it can connect at all)

@araneta
Copy link
Author

araneta commented Dec 21, 2021

i tried this but does not work
postgres=free-tier6.gcp-asia-southeast1.cockroachlabs.cloud/smoggy-deer-1769.defaultdb?user=aldo&password=KM89dd7zaKt3V&sslmode=verify-full&sslrootcert=/home/aldo/.postgresql/root.crt&options=--cluster%3Dsmoggy-deer-1769

how to include the ssl certificate file ?

@zapov
Copy link
Member

zapov commented Dec 21, 2021

What does it say exactly? Does this connection string work via pgjdbc?

@araneta
Copy link
Author

araneta commented Dec 21, 2021

here is the documentation using jdbc https://www.cockroachlabs.com/docs/v21.2/build-a-java-app-with-cockroachdb
we need to set the ssl file.
PGSimpleDataSource ds = new PGSimpleDataSource();
ds.setServerNames(new String[]{"{globalhost}"});
ds.setPortNumbers(new int[]{26257});
ds.setDatabaseName("{cluster_name}.bank");
ds.setSsl(true);
ds.setUser("{username}");
ds.setPassword("{password}");
ds.setSslMode("verify-full");
ds.setSslRootCert(System.getenv("$HOME/.postgresql/root.crt"));
ds.setReWriteBatchedInserts(true); // add rewriteBatchedInserts=true to pg connection string
ds.setApplicationName("BasicExample");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants