question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Postgres connection string not printed if connection fails because database does not exist

See original GitHub issue

Environment

Liquibase Version: 3.5.5

Database Vendor & Version: Postgres:latest (12.4)

Operating System Type & Version: Linux Pop_OS 20.04, Docker 19.03

Description

Attempting to Debug a connection can be difficult as the connection string is only printed if the database exists.

Steps To Reproduce

The following docker-compose file (using keycloak as it is where I encountered the issue) should produce the unsuccessful connection. Piping the logs to a file, lines 223-224 should be the lines posted in the description section (assuming fresh data volumes). Setting DB_DATABASE: public should give the “connected to” example, while DB_DATABASE: keycloak (or anything else) will produce the “database does not exist” example.

version: "3"
services:
  postgres:
    image: "postgres"
    ports:
      - "5433:5432"
    environment:
      POSTGRES_DB: public
      POSTGRES_USER: admin
      POSTGRES_PASSWORD: password
      PGDATA: /var/lib/postgresql/data/pgdata
    volumes:
      - "postgres_data:/var/lib/postgresql/data/pgdata"
  postgres_wait:
    image: dadarek/wait-for-dependencies
    depends_on:
      - postgres
    command: postgres:5432

  keycloak:
    image: "quay.io/repository/keycloak/keycloak"
    depends_on:
      - postgres_wait
    ports:
      - "8080:8080"
    environment:
      KEYCLOAK_LOGLEVEL: ALL
      DB_VENDOR: POSTGRES

      DB_USER: admin
      DB_PASSWORD: password
      DB_DATABASE: keycloak
      DB_SCHEMA: public
      DB_ADDR: postgres
    volumes:
      - "keycloak_data:/keycloak"

volumes:   
  postgres_data:
    driver: local
  keycloak_data:
    driver: local

Actual Behavior

No Connection string is printed. The following lines are printed instead.

keycloak_1 08:28:36,617 DEBUG [org.keycloak.connections.jpa.updater.liquibase.conn.DefaultLiquibaseConnectionProvider] (ServerService Thread Pool – 63) Added package org.keycloak.connections.jpa.updater.liquibase.lock to liquibase
postgres_1 2020-08-22 08:28:36.859 UTC [74] FATAL: database "keycloak" does not exist

Expected/Desired Behavior

Even if the database does not exist, the connection string is printed like in the following log lines, after which point the database does not exist error would then happen.

keycloak_1 07:14:31,038 DEBUG [org.keycloak.connections.jpa.updater.liquibase.conn.DefaultLiquibaseConnectionProvider] (ServerService Thread Pool – 67) Added package org.keycloak.connections.jpa.updater.liquibase.lock to liquibase
keycloak_1 07:14:31,337 TRACE [org.keycloak.connections.jpa.updater.liquibase.conn.DefaultLiquibaseConnectionProvider] (ServerService Thread Pool – 67) Connected to admin@jdbc:postgresql://postgres:5432/public?schema=keycloak

Additional Context

First Line of logs (keycloak) is located in keycloak here and the connection string is logged (via liquibase) here.

Originally reported to keycloak here but closed as successful connection string is printed by liquibase. I have grabbed the environment data to the best of my ability given i’m working with keycloak, not on keycloak.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
molivasdatcommented, Aug 27, 2020

Hi @karuppiah7890 I would say go for it.

0reactions
molivasdatcommented, Aug 31, 2020

Thanks @karuppiah7890 for the detailed description and where the bug happens to be. Going to close this as needing to be fixed in keycloak code. Really appreciate the thorough details on the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

can't connect to postgresql database "database doesn´t exist"
I have tried to check if the connection string is correct, I have tried to create a new database and connect it but...
Read more >
34.1. Database Connection Control Functions - PostgreSQL
The following functions deal with making a connection to a PostgreSQL backend server. An application program can have several backend connections open at ......
Read more >
Are you running into Postgres connection issues on Azure?
Invalid connection String or password · Make sure the user you are connecting with an account has the appropriate permission. · If you...
Read more >
pg_connect - Manual - PHP
then you should try to leave the host= and port= parts out of the connection string. This sounds strange, but this is an...
Read more >
The psycopg2 module content — Psycopg 2.9.5 documentation
The connection parameters can be specified as a libpq connection string using the dsn ... port – connection port number (defaults to 5432...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found