Default Postgres settings in Digital Ocean
-
Hello,
I created a Cloudron Droplet in Digital Ocean. Now I am trying to access the Postgresql database of Cloudron, but I don't know which are the default settings.
In the documentation, it is implied that we need to know the username, password, host and database, however all these where created by default during the installation of Cloudron, and the marketplace page doesn't have any info about those variables.
I would be gratefull if you could point me out how I can find the necessary info to access Cloudron's database.
-
Hi, on Cloudron postgres is managed as a service for apps and thus each app will get its own set of credentials. You can read more about this at https://docs.cloudron.io/custom-apps/addons/
What is your use-case to require direct access to the postgres database?
-
I was trying to connect to the database of an application installed in Cloudron and visualize the database with a program like DataGrip.
I hadn't realised that the db credentials of each app can be accessed in the environment of the app with
PGPASSWORD=${CLOUDRON_POSTGRESQL_PASSWORD} psql -h ${CLOUDRON_POSTGRESQL_HOST} -p ${CLOUDRON_POSTGRESQL_PORT} -U ${CLOUDRON_POSTGRESQL_USERNAME} -d ${CLOUDRON_POSTGRESQL_DATABASE}
The problem I faced ended up being that once DataGrip was connected to the Cloudron server with an SSH tunnel, it was expecting to be able to connect to the database in a local port. However, the postgresql container run by Cloudron doesn't expose the 5432 port, so there was no way to connect to it through a simple ssh tunnel. I ended up using a bit of a hack solution to expose the database port 5432 by running a docker container that does only that.
docker run -d --rm --network=cloudron --name sql_redirect --link postgresql:postgresql -p 5432:1234 alpine/socat TCP-LISTEN:1234,reuseaddr,fork TCP:postgresql:5432
-
@nikosgpet Right, so the databases are strictly "internal" to the server and locked down for security purposes. There is no way to expose them to the outside world without creating a ssh tunnel. So, I think something like that you did is pretty much the only way.
Does DataGrip have a way to connect via SSH tunnel (for example, like mysql workbench) ? If so, you can do something like this instead of running sql_redirect container - https://forum.cloudron.io/topic/3237/remote-sql-support-on-a-per-app-basis/2