```object DatabaseFactory { fun init(applicati...
# server
l
Copy code
object DatabaseFactory {
    fun init(application: Application) {
        <http://application.log.info|application.log.info>("DB: Initializing database connection...")

        val config = HikariConfig().apply {
            jdbcUrl = "jdbc:<postgresql://localhost:5432/db_name>"
            driverClassName = "org.postgresql.Driver"
            username = "username"
            password = "password"
            maximumPoolSize = 10
            isAutoCommit = false
            transactionIsolation = "TRANSACTION_REPEATABLE_READ"
            validate()
        }

        <http://application.log.info|application.log.info>("DB: Connecting to: ${config.jdbcUrl}")
        val dataSource = HikariDataSource(config)
        Database.connect(dataSource)


        <http://application.log.info|application.log.info>("DB: Connected to database!")

        transaction {
            <http://application.log.info|application.log.info>("DB: Creating tables...")
            SchemaUtils.create(UsersSchema, RefreshTokenSchema)
            <http://application.log.info|application.log.info>("DB: Tables ready!")
        }

        <http://application.log.info|application.log.info>("DB: Database setup complete!")

    }

    suspend fun <T> dbQuery(block: suspend () -> T): T =
        withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
            suspendTransaction {
                block()
            }
        }
}
I have this code thats trying to connect to my postgres db thats run on a docker on my machine, but i keep getting FATAL: password authentication failed for user. Im able to connect my pg admind to this postgres and also able to login trough docker into my postgres, but my code wont connect to it. I can provide the docker-compose.yml if needed or any other info. Yes I've checked and the password/username do match the ones for my database
e
can you see what postgres thinks is going on; the request it received?
l
How would I go about that? First time trying docker and postgres so not sure how to see it's logs or anything? Also I did manage to connect pgadmin when run from another container, but when I tried to run local one without a docker, it failed on authentication even tho I entered the right username and password.
e
Then I'd suggest using #C0CG7E0A1 or jooq, without hikari; you'll get more help. Anyway, to get the logs you do
Copy code
SELECT  pg_current_logfile();
1
❤️ 1
l
Thanks Ill try to setup a db in another project and then try to transfer it over to to my main project when it all works out
Just using exposed didnt seem to fix it even in a new project... I tried following a youtube video but still the issue persists. Also select pg_current_logfile(); return null... and going trough the docker to search the postgres files, the log folder is empty. If I run the postgres db locally instead of container it works fine...
e
That is informative. What docker command did you use to run postgres? If you want your postgres instance to be accessible outside of Docker you need to expose its port, like
-p 5432:5432
like so
l
I setup a docker-compose.yml, I can paste it? And then I did docker compose up -d. Of course there was the ports: "5432:5432" inside that file
Copy code
services:
  postgres:
    image: postgres:18
    container_name: boqez_db
    environment:
      POSTGRES_DB: ${DB_NAME}
      POSTGRES_USER: ${DB_USER}
      POSTGRES_PASSWORD: ${DB_PASSWORD}
    ports:
      - "5432:5432"
    volumes:
      - dbdata:/var/lib/postgresql
    restart: always

volumes:
  dbdata:
this is the docker file that I use with that command
Could there be an issue since I have both docker postgres and localdb postgres both on :5432 port?
Yep I changed port to 5431:5432 and it worked, seems there was some port confilct between docker postgres and local postgres, which I forgot I had installed before docker...
🤦 1