I am using Gitpod cloud IDE which uses Docker images to provide a nice linux environment with VSCode IDE.
It is possible to use a Docker file in Gitpod to install additional software in the environment. So by following Gitpod docs I installed PostgreSQL.
https://medium.com/gitpod/bring-your-own-docker-image-to-gitpod-52db1aa861de
I can now connect to the PostgreSQL with this command. Note that I had to provide the sockets folder to get this working.
psql -h ~/pg/sockets postgres
I have a spring boot application which should connect to the PostgreSQL DB. The connection URL is taken from an Environment variable.
export JDBC_DATABASE_URL=jdbc:postgresql://gitpod@127.0.0.1/postgres
And this is what I have in my properties file.
spring.datasource.url=${JDBC_DATABASE_URL}
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.datasource.driverClassName=org.postgresql.Driver
spring.jpa.show-sql=false
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=update
spring.datasource.maxActive=10
spring.datasource.maxIdle=5
spring.datasource.minIdle=2
spring.datasource.initialSize=5
spring.datasource.removeAbandoned=true
this is what I get when I run \du on psql to list the users.
postgres=# \du
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------------------+-----------
gitpod | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
The Gitpod user logged in to this linux environment is named gitpod. ( I do not know the password )
When I run the command netstat -plunt | grep postgres I get the following output
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 955/postgres
But when I run my App it throws the following exception
Caused by: java.net.UnknownHostException: gitpod@127.0.0.1
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184) ~[na:1.8.0_202]
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:1.8.0_202]
at java.net.Socket.connect(Socket.java:589) ~[na:1.8.0_202]
at org.postgresql.core.PGStream.<init>(PGStream.java:75) ~[postgresql-42.2.6.jar!/:42.2.6]
at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:91) ~[postgresql-42.2.6.jar!/:42.2.6]
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:192) ~[postgresql-42.2.6.jar!/:42.2.6]
... 56 common frames omitted
I think it should be a problem with the Connection URL. Can someone please explain me how to get this working ?
Really appreciate your help. Thanks.