Thorntail create datasource connection in postgres in openshift - postgresql

I have a java app that use thorntail, postgres DB and i want to deploy this app to openshift via docker image.
I have tested successful build app with docker image and deploy to minishift and external postgres DB.
And now I want to use postgres in openshift instead of external postgres
But I dont know how to specify postgres connection for openshift in project-defaults.yml.
This is my project-defaults.yml: It does't work for postgres in openshift
thorntail:
datasources:
data-sources:
postgres_tenancy:
driver-name: mypostgres
connection-url: postgresql://postgresql:5432/$POSTGRESQL_DATABASE
user-name: $POSTGRESQL_USER
password: $POSTGRESQL_PASSWORD
jdbc-drivers:
mypostgres:
driver-class-name: org.postgresql.Driver
xa-datasource-name: org.postgresql.xa.PGXADataSource
driver-module-name: org.postgresql
Anybody has any idea?

Related

How to see/install pg_activity for the crunchy data postgres operator?

I have setup an Rancher (RKE) (kuberbetes) for my application.
and application using the postgres so i have setup Crunchydata postgres operator and create postgres cluster using that.
everything fine but now i want to see the pg_activity for my postgresql.
how i can see the activity of whole postgres ?
you use the monitoring tools in rancher to monitor the Postgres.
apart from that you can SSH inside the respective pod of the database and use the cli command and check the output.
In rancher, you can also use the client tool to connect with the rancher and run the cli command to check the pg_activity.
Client docker image : https://hub.docker.com/r/jbergknoff/postgresql-client/
you can also deploy the GUI docker client on rancher and use it
GUI postgress client : https://hub.docker.com/r/dpage/pgadmin4/
GUI Example : https://dataedo.com/kb/query/postgresql/list-database-sessions#:~:text=Using%20pgAdmin,all%20connected%20sessions%20(3).

Setup a PostgreSQL connection to an already existing project in Docker

I had never used PostgreSQL nor Docker before. I set up an already developed project that uses these two technologies in order to modify it.
To get the project running on my Linux (Pop!_OS 20.04) machine I was given these instructions (sorry if this is irrelevant but I don't know what is important and what is not to state my problem):
Installed Docker CE and Docker Compose.
Cloned the project with git and ran the commands git submodule init and git submodule update.
Initialized the container with: docker-compose up -d
Generated the application configuration file: ./init.sh
After all of that the app was available at http://localhost:8080/app/ and I got inside the project's directory the following subdirectories:
And inside dbdata:
Now I need to modify the DB and there's where the difficulty arose since I don't know how to set up the connection with PostgreSQL inside Docker.
In a project without Docker which uses MySQL I would
Create the local project's database "dbname".
Import the project's DB: mysql -u username -ppassword dbname < /path/to/dbdata.sql
Connect a DB client (DBeaver in my case) to the local DB and perform the necessary modifications.
In an endeavour to do something like that with PostgeSQL, I have read that I need to
Install and configure Ubuntu 20.04 serve.
Install PostgreSQL.
Configure Postgres “roles” to handle authentication and authorization.
Create a new Database.
And then what?
How can I set up the connection in order to be able to modify the DB from DBeaver and see the changes reflected on http://localhost:8080/app/ when Docker is involved?
Do I really need an Ubuntu server?
Do I need other program than psql to connect to Postgres from the command line?
I have found many articles related to the local setup of PostgreSQL with Docker but all of them address the topic from scratch, none of them talk about how to connect to the DB of an "old" project inside Docker. I hope someone here can give directions for a newbie on what to do or recommend an article explaining from scratch how to configure PostgreSQL and then connecting to a DB in Docker. Thanks in advance.
Edit:
Here's the output of docker ps
You have 2 options to get into known waters pretty fast:
Publish the postgres port on the docker host machine, install any postgres client you like on the host and connect to the database hosted in the container as you would have done this traditionally. You will use localhost:5433 to reach the DB. << Update: 5433 is the port where the postgres container is published on you host, according to the screenshot.
Another option is to add another service in your docker-compose file to host the client itself in a container.
Here's a minimal example in which I am launching two containers: the postgres and an adminer that is exposed on the host machine on port 9999.
version: '3'
services:
db:
image: postgres
restart: always
environment:
POSTGRES_PASSWORD: example
adminer:
image: adminer
restart: always
ports:
- 9999:8080
then I can access the adminer at localhost:9999 (password is example):
Once I'm connected to my postgres through adminer, I can import and execute any SQL query I need:
A kind advice is to have a thorough lecture to understand how the data is persisted in a Docker context. Performance and security are also topics that you might want to add under your belt as a novice in the field better sooner than later.
If you're running your PostgreSQL container inside your own machine you don't need anything else to connect using a database client. That's because to the host machine, all the containers are accessible using their own subnet.
That means that if you do this:
docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' 341164c5050f`
it will output a list of IPs that you can configure in your DBeaver to access the container instance directly.
If you're not fond of doing that (or you prefer to use cli) you can always use the psql inside the installation of the PostgreSQL container to achieve something like you described in mysql point nº2:
docker exec -i 341164c5050f bash -c 'psql -U $POSTGRES_USER' < /path/to/your/schema.sql
It's important to inform the -i, otherwise it'll not read the schema from the stdin. If you're looking for psql in the interactive mode, use -it instead.
Last but not least, you can always edit the docker-compose.yml file to export the port and connect to the instance using the public IP/loopback device.

How to connect SpringBoot application inside Docker to outside PostgreSQL

I have Java SpringBoot Web-application working on host machine. Application connects to PostgreSQL database. All works well. OS - Ubuntu 18.
Now i need to move application in Docker container, except for PostgreSQL which will remain on host machine.
I installed Docker, rise up container, but my app inside docker cannot connect to PostgreSQL database with default settings (localhost).
Here is my application.properties file:
spring.datasource.driverClassName=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/webdemodb
spring.datasource.username=postgres
spring.datasource.password=123
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL95Dialect
spring.jpa.generate-ddl=true
Here is my Dockerfile:
FROM java:8
WORKDIR /
ADD target/webaccount-1.0-SNAPSHOT.jar app.jar
EXPOSE 8080
RUN fc-cache -f -v
ENTRYPOINT ["java","-jar","/app.jar"]
I read about Docker's networking but didn't find solution. What i need to setup?
Artemiy, thanks! For simple usage i've just applied the next option when running container:
--network="host"
Full command:
docker run -d -p 9000:8080 --network="host" --name webaccount webaccount:1.0

Heroku PostgreSQL user and database creation

Currently I have my Ruby on Rails program running great on my Linux Ubuntu development environment, and now I want to run it live on my website, and get it hosted on Heroku.
The problem is that I don't know how to create a user and a database on Heroku. I have tried the command
heroku run rake db:create
I got the error:
permission denied for database - user does nothave connect privilage
I also tried the command
heroku run su - postgres
and it posted that I need to use the terminal so I do not know how to proceed.
This is my database.yml
default: &default
adapter: postgresql
host: localhost
development:
<<: *default
database: app_development
test:
<<: *default
database: app_test
production:
<<: *default
database: app_production
How do I set up my database and the proper connections with my Heroku PostgreSQL database?
i also did this
heroku pg:info
which gave me this
shrouded-reaches-3063 has no heroku-postgresql databases.
also tried this
heroku addons | grep POSTGRES
but nothing was printed
heroku addons:create heroku-postgresql:hobby-dev
! `addons:create` is not a heroku command.
! See `heroku help` for a list of available commands.
also this
heroku pg:wait
and displayed nothing... this really is something T_T really need some major help here , and will be really greatful for any help
Have you provisioned a database? What does heroku addons say? You can create an add-on as documented here with heroku addons:create heroku-postgresql:hobby-dev
!!!NOT IN THE DOCUMENTATION!!!
heroku addons:create heroku-postgresql:hobby-dev --version=12 --app "APPNAME" --name "APPNAME-database"
--app : Specify the heroku app you want to add the database too. Really good if you have more than one heroku app.
--name : The name you would like to give your database. I like to take my application name and postfix it with "database" as a nice convention. Better than whatever randomly generated name you'll get.
APPNAME: A placeholder for whatever your application name is.
No mention of any of this on heroku.com documentation pages for addons in general or postgres addon. I think I came to this via guessing based on documentation for creating apps. But I don't remember. This was in my notes from 5+ years ago. However, I just tried it, still works as of 2022.05.14.

How can I connect a docker container in AWS to a RDS

How can I --link a docker container(odoo) running on a plain EC2 instance or via EB to a RDS in AWS? I tried loading a custom config file with the location of the server but that didn't work. In EB I created an app with a postgres DB, successfully deployed my docker.aws.json but I can not connect to web interface of the the application.
When I check the docker logs of the container it says everything started fine but expects the DB on localhost.
So like I said my question is how can I tell a docker container to --link to a RDS and not an other docker container à la --link db:db?
If you created a database in AWS Elastic Beanstalk, you can access it using environment variables that EB set for you. See examples in the documentation: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-rds.html (Python example)
The environment variable containing the RDS DB hostname is called RDS_HOSTNAME. See example: https://github.com/awslabs/eb-demo-php-simple-app/tree/docker-apache
It's not possible to use a link as your RDS DB is not a Docker container.