Connect to Postgres in DataGrip - postgresql

I try to connect to my Postgres database built by docker in DataGrip but I get connection error.
Here is my application.yml file:
spring:
jpa:
database: POSTGRESQL
show-sql: true
hibernate:
ddl-auto: update
datasource:
url: jdbc:postgresql://db:5432/postgis_db?createDatabaseIfNotExist=true&useSSL=false&allowPublicKeyRetrieval=true
username: postgres
password: postgres
Here is docker-compose.yml file:
version: '3.8'
services:
db:
image: postgres:latest
restart: always
volumes:
- db:/var/lib/postgresql/data
environment:
POSTGRES_DB: postgis_db
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- "5432:5432"
expose:
- 5432
networks:
- app-network
geolocation-service:
image: geolocation-service
build:
context: .
dockerfile: dockerfile
restart: always
ports:
- "8080:8080"
networks:
- app-network
volumes:
db:
networks:
app-network:
DataGrip connection settings:
And the error I get:
Does anybody knows how to solve this?
Connecting to this db by shell works fine:
docker exec -it a37 psql -U postgres postgis_db

Please check pg_hba.conf file, you have to allow connections from all hosts for this user, by default it is restricted to localhost.

Related

Keycloak Quarkus, I don't see the base or its tables

I'm using bitnami's Keycloak v.20.0.0 (Quarkus) image with docker-compose. Everything works fine and I have no problems with any configuration, however when I want to see the tables in the PostgreSQL database, I access without problems but I don't see anything! I don't see that any table or database exists.
I understand that I have to start Keycloak in dev mode which I configured but I still don't see anything.
What am I doing wrong?
this is my setup:
version: "3.7"
services:
keycloak:
image: bitnami/keycloak:20.0.1
container_name: keycloak_20
environment:
DB_VENDOR: POSTGRES
DB_ADDR: postgres
KEYCLOAK_ADMIN_USER: admin
KEYCLOAK_ADMIN_PASSWORD: admin
KEYCLOAK_DATABASE_HOST: postgres
KEYCLOAK_DATABASE_PORT: 5432
KEYCLOAK_DATABASE_NAME: postgres
KEYCLOAK_DATABASE_USER: postgres
KEYCLOAK_DATABASE_PASSWORD: postgres
KEYCLOAK_DATABASE_SCHEMA: public
KEYCLOAK_EXTRA_ARGS: "-Dkeycloak.profile.feature.scripts=enabled"
KC_HOSTNAME: postgres
ENV KC_HOSTNAME_STRICT: false
ENV KC_HTTP_ENABLED: true
ports:
- 8080:8080
volumes:
- ./keycloak/export:/tmp/export
- ./rus-theme:/opt/bitnami/keycloak/themes/my-theme
- ./keycloak/configuration/standalone-ha.xml:/bitnami/keycloak/configuration/standalone-ha.xml:ro
command:
- /bin/bash
- -c
- |
/opt/bitnami/keycloak/bin/kc.sh start-dev
depends_on:
- postgres
postgres:
image: postgres:10
container_name: postgres
volumes:
- postgres_data:/var/lib/postgresql/data
environment:
POSTGRES_DB: postgres
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- "5432:5432"
mailhog:
# Conectarse al nombre del container para acceder
# Ejemplo: mailhog:1025
image: mailhog/mailhog
logging:
driver: 'none' # disable saving logs
container_name: mailhog
ports:
- 1025:1025 # smtp server
- 8025:8025 # web ui
volumes:
postgres_data:
driver: local
KEYCLOAK_DATABASE_* properties were used in the old versions of Keycloak (pre-Quarkus).
New properties are defined as KC_DB_* (see https://www.keycloak.org/server/all-config?q=db)

How does Postgresql inside Docker work? psql: FATAL: password authentication failed for user xy

I created my app with .yml
services:
db:
image: postgres:11-alpine
environment:
POSTGRES_DB: wiki
POSTGRES_PASSWORD: quantoxrocks
POSTGRES_USER: wikijs
logging:
driver: "none"
restart: unless-stopped
volumes:
- db-data:/var/lib/postgresql/data
wiki:
image: ghcr.io/requarks/wiki:2
depends_on:
- db
environment:
DB_TYPE: postgres
DB_HOST: db
DB_PORT: 5432
DB_USER: wikijs
DB_PASS: quantoxrocks
DB_NAME: wiki
restart: unless-stopped
ports:
- "3000:3000"
webserver:
image: nginx:alpine
restart: unless-stopped
tty: true
ports:
- "443:443"
- "80:80"
volumes:
- ./nginx/conf.d:/etc/nginx/conf.d
- ./ssl:/etc/nginx/ssl
volumes:
db-data:
I logged in my db container and want to create database. I have tried at least 10 times and I am sure that password is from the above docker-compose.yml file. It does not work.
docker exec -it wiki_db_1 sh
Next
psql -h wiki_db_1 -U wikijs
Password for user wikijs:
psql: FATAL: password authentication failed for user "wikijs"
Why? How can I check any further logs?
The environment variables for Postgres are only used if there is no database present already when the container starts.
You have a volume mapping of /var/lib/postgresql/data and it's likely that you already have a database there, which was created with different values from the environment variable values.
If you don't have any important data in the existing database, you can delete the volume and Postgres will create a new database with the correct username/password.

Cant login with docker compose to Postgres via pgadmin

I have the following docker-compose:
version: '3.1'
services:
db:
image: postgres
restart: always
environment:
POSTGRES_PASSWORD: postgres
volumes:
- postgres:/pgdata
ports:
- "5432:5432"
pdadmin:
image: dpage/pgadmin4
restart: always
ports:
- "8080:80"
environment:
PGADMIN_DEFAULT_EMAIL: example#gmail.com
PGADMIN_DEFAULT_PASSWORD: example
volumes:
postgres:
when I try to login to postgres via pgadmin i am getting the error: password authentication failed for user "postgres"
I am trying with user postgres and password postgres.
I also tryied to add explisit POSTGRES_USER to the env with no success.
How can I login to my postgres database?
Thanks
you're very close:
version: '3.1'
services:
db:
image: postgres
restart: always
environment:
POSTGRES_USER: postgres # <-- add this
POSTGRES_PASSWORD: postgres
volumes:
- postgres:/pgdata
ports:
- "5432:5432"
pdadmin:
image: dpage/pgadmin4
restart: always
ports:
- "8080:80"
environment:
PGADMIN_DEFAULT_EMAIL: example#gmail.com
PGADMIN_DEFAULT_PASSWORD: example
depends_on: # <-- add this
- db # <-- add this
links: # <-- add this
- db # <-- add this
volumes:
postgres:
Then connect to pgadmin http://localhost:8080
when you want to add new server you need to add the IP of the container
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <container_id>
That it !
try it
PGADMIN_DEFAULT_PASSWORD: Example123
Use a mixture of upper and lower case letters and numerics

Connection Error accessing postgres docker container

I setup a prisma project recently and here is my docker-compose.yml file
version: '3'
services:
prisma:
image: prismagraphql/prisma:1.31
restart: always
ports:
- '4030:4466'
environment:
TZ: ${PRISMA_DB_TIME_ZONE}
PRISMA_CONFIG: |
port: 4466
# managementApiSecret: my-secret
databases:
default:
connector: postgres
host: postgres
port: 5432
user: prisma
password: ${PRISMA_DB_PASSWORD}
migrations: true
rawAccess: true
postgres:
image: postgres:10.3
restart: always
ports:
- "3306:3306"
environment:
POSTGRES_USER: prisma
POSTGRES_PASSWORD: ${PRISMA_DB_PASSWORD}
TZ: ${PRISMA_DB_TIME_ZONE}
volumes:
- postgres:/var/lib/postgresql/data
volumes:
prisma:
postgres:
I can open my prisma playground and it functions without any issue. but I can't create a direct connection to the postgre container with dbeaver.
dbeaver Error message
Connection reset
Why my connection to the database fails?
This photo will be helpful.
postgres by default listens on port 5432.
In your postgres container specification, you should expose the port 5432 not 3306.
version: '3'
services:
prisma:
image: prismagraphql/prisma:1.31
restart: always
ports:
- '4030:4466'
environment:
TZ: ${PRISMA_DB_TIME_ZONE}
PRISMA_CONFIG: |
port: 4466
# managementApiSecret: my-secret
databases:
default:
connector: postgres
host: postgres
port: 5432
user: prisma
password: ${PRISMA_DB_PASSWORD}
migrations: true
rawAccess: true
postgres:
image: postgres:10.3
restart: always
ports:
- "5432:5432"
environment:
POSTGRES_USER: prisma
POSTGRES_PASSWORD: ${PRISMA_DB_PASSWORD}
TZ: ${PRISMA_DB_TIME_ZONE}
volumes:
- postgres:/var/lib/postgresql/data
volumes:
prisma:
postgres:
If 5432 port in your host is already in use and if you want to use 3306 instead , then you can do port forwarding like below:
postgres:
image: postgres:10.3
restart: always
ports:
- "3306:5432"
environment:
POSTGRES_USER: prisma
POSTGRES_PASSWORD: ${PRISMA_DB_PASSWORD}
TZ: ${PRISMA_DB_TIME_ZONE}
volumes:
- postgres:/var/lib/postgresql/data
UPDATE - 1
Reason why prisma can access postgres
ports section is meant only to make our services accessible in host level. But in the container level, If a port is open in a container, any other running container can access that port with the help of networks or links section.
By default, docker-compose will create a network per docker-compose.yml file and joins all the services in that file into that network.
That's the reason we could use the <service name> as the hostname and compose will resolve that name to the ip-address of the respective (in your case postgres) container.

Connecting docker postgres to pgAdmin

Given this docker-compose.yml, am experiencing difficulties connecting the docker stack to my pgAdmin.
version: '3.1'
services:
database:
image: postgres
restart: always
environment:
POSTGRES_USER: db-user
POSTGRES_PASSWORD: db-user
POSTGRES_DB: db
ports:
- 5432:5432
For the pgAdmin Connection properties, here's what I've used (others, default values):
Host: 127.0.0.1
Username & Password: db-user
And for the error message when saving:
Error saving properties: UNAUTHORIZED
Unable to connect to server
The docker postgresql page suggest the stack.yml:
# Use postgres/example user/password credentials
version: '3.1'
services:
db:
image: postgres
restart: always
environment:
POSTGRES_PASSWORD: example
adminer:
image: adminer
restart: always
ports:
- 8080:8080
And then visit http://localhost:8080.
Or:
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" ...
In your case, adding port to the database itself suggests your queries should use that port.