Encountering difficulties connecting to a local PostgreSQL database hosted on Docker while using TypeORM alongside pgAdmin4

I am encountering issues with connecting to a postgres database hosted in docker on localhost using the default port 5432. Both pgAdmin4 and TypeORM are giving me an "invalid password" error when attempting to connect. Here is the content of my docker-compose.yml file:

version: '3.8'
services: 
    db:
        image: postgres
        volumes:
            - ./pgdata:/var/lib/postgresql/data
        ports: 
            - '5432:5432'
        environment: 
            POSTGRES_DB: maindb
            POSTGRES_USER: admin
            POSTGRES_PASSWORD: admin

Despite providing the correct credentials, I am unable to establish a connection via pgAdmin4 or TypeORM. The error message indicating "password authentication failed for user "admin"" has left me puzzled. Even after double-checking the environment variables passed through Docker Desktop, the issue persists.

If anyone could shed light on why this authentication failure is occurring with PostgreSQL in a Docker setting, it would be greatly appreciated. Alternatively, I may need to explore switching to a different database provider?

Edit 1

Below are the logs from the database startup process:

Attaching to backend_db_1

// Log entries omitted for brevity...

db_1 | 2020-08-12 09:26:50.984 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432

db_1 | 2020-08-12 09:26:50.984 UTC [1] LOG: listening on IPv6 address "::", port 5432

db_1 | 2020-08-12 09:26:50.997 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"

db_1 | 2020-08-12 09:26:51.051 UTC [66] LOG: database system was shut down at 2020-08-12 09:26:50 UTC

db_1 | 2020-08-12 09:26:51.080 UTC [1] LOG: database system is ready to accept connections

Answer №1

During the initialization script, both the username and password are being configured.

If you have previously run the compose-up on the same file, it is probable that there is existing data on the volume mounted in the container. In such cases, the initialization script will be skipped and you may encounter this message in the docker-compose up output:

db_1  | PostgreSQL Database directory appears to contain a database; Skipping initialization

You have the following options to resolve the issue:

  • Recall the original password set during the initial composition and use it for connection

OR

  • Empty or completely delete the volume (as explained by @pacuna in a comment - this action will erase all data and start afresh!)
docker-compose down -v

OR

  • Reset the administrator's password:
// Access a console within the container
docker exec -ti <your-psql-container-id> sh

// Connect to maindb using admin user credentials
psql -d maindb -U admin

// Update the admin user password
ALTER USER admin WITH ENCRYPTED PASSWORD 'admin-new-pass';

...and then attempt to connect using admin-new-pass


Post troubleshooting update:
The issue stemmed from a misconfiguration of the pgAdmin4 client. After converting the pgAdmin4 client into a container, the problem was resolved

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue arising from passing an object through a component in a Next.js application during build time when the object is retrieved from a database

Can anyone provide assistance with solving this issue? I have an object called "diary" coming from a database, which is passed to a component where a useState hook is expecting that object. During build time, the following error is occurring. An error is ...

When developing a Yeoman generator using TypeScript, it is important to note that the type 'any' cannot be used as a constructor function type

Embarking on my journey to create my inaugural Yeoman generator using TypeScript, I have encountered some challenges. While my TypeScript code transpiles smoothly into JavaScript and the basic test Yeoman generator functions properly, I am puzzled by the e ...

"Struggling to Get Angular2 HttpClient to Properly Map to Interface

Currently, I am integrating Angular with an ASP.NET WebApi. My goal is to transmit an object from the API to Angular and associate it with an interface that I have defined in Typescript. Let me show you my TypeScript interface: export interface IUser { ...

Typescript disregarding conditional statements

Looking for some assistance with a Next.JS React-Typescript application Here's my code snippet for handling the video HTML element const videoRef = useRef<HTMLVideoElement>(); useEffect(() => { videoRef !== undefined ? videoRef.current. ...

Receiving an error with React Proptypes when using the union type Breakpoint

Struggling to assign the correct proptype to the material-ui Breakpoint type. The breakpoint values are: export type Breakpoint = 'xs' | 'sm' | 'md' | 'lg' | 'xl'; In my App.tsx file, I have the following ...

Setting up a ConnectionString for Postgres in a C# application is a crucial step for

Operating on a Linux server, my database is postgresql. I now need to establish communication with it through a C# program on a Windows operating system. To connect to the database, there exists a public encrypted file on the server that requires my priva ...

Utilizing the value of a parent type in a different type in TypeScript: A guide

Currently, I am in the process of experimenting with creating my own basic ORM system. Below is the snippet of code that I have been working on: type Models = { User: { name: string }, Template: { text: string } } type ExtractKeysF ...

What is the best approach to managing exceptions consistently across all Angular 2/ Typescript observables?

Throughout the learning process of Angular2, I have noticed that exceptions are often caught right at the point of the call. For example: getHeroes(): Promise<Hero[]> { return this.http.get(this.heroesUrl) .toPromise() ...

Is Validators.required a necessity in Angular 2?

Is there a way to dynamically require a form field based on conditions? I created a custom validator, but the conditional variables passed to it remain static. How can I update these conditional values within the custom validator function? Is it possible t ...

Currency symbol display option "narrowSymbol" is not compatible with Next.Js 9.4.4 when using Intl.NumberFormat

I am currently utilizing Next.JS version 9.4.4 When attempting to implement the following code: new Intl.NumberFormat('en-GB', { style: 'currency', currency: currency, useGrouping: true, currencyDisplay: 'narrowSymbol'}); I ...

In search of assistance with implementing Google Maps navigation into an Ionic 2 application

Incorporating external Google Maps navigation with ride distance and time is my goal. I am utilizing a method from phonegap-launch-navigator to achieve this. Here is the code for the method: navigate() { let options: LaunchNavigatorOptions = { s ...

Visual Studio 2017, ASP.NET framework, Typescript programming language, and node package manager

My ASP.net application in Visual Studio used to only utilize JavaScript, but now I am looking to incorporate Typescript. While the installation and transpiling process went smoothly, I encountered an issue when attempting to import modules. I decided to u ...

Is it recommended to use jq in AWS buildspec prior to authentication - is it a best practice

My current buildspec.yml for AWS CodeBuild has the following steps: docker pull jq PASSWORD=`aws secretsmanager get-secret-value ... | docker run jq '.password'` docker login (pull actual images and proceed with build) In order to log in to Doc ...

Why should one bother with specifying types when defining a variable in Typescript?

As someone new to Typescript, I've come to appreciate its many advantages when working on larger applications and with multiple team members :) Imagine you have the following TypeScript code: declare const num = 5: number; Why is this better than: ...

Utilize dynamic properties in zod depending on the current state

I have an object that may contain one of two properties depending on a state in react known as state. I am attempting to incorporate this into the Zod schema to generate an error if either property is empty or undefined based on the state. Data.ts const d ...

The type mismatch issue occurs when using keyof with Typescript generics

One of the challenges I am facing is related to an interface that stores a key of another interface (modelKey) and the corresponding value of that key (value): interface ValueHolder<T, H extends keyof T> { modelKey: H; value: T[H]; } My objectiv ...

The fixed position with bottom at 0 is not displayed on the Chrome browser until a refresh is done

When accessing my React front end in Mobile Chrome browsers, I noticed that the div at the bottom only renders after moving or refreshing the page. Interestingly, it works perfectly fine once cached. However, on the initial load (especially when using inco ...

Step-by-step guide on incorporating HTML into a popover within Angular4

After successfully implementing a hover popover in Angular using PopoverModule from ngx-popover, I now need to modify the content inside the popover. My search led me to this example: <ng-template #popContent>Hello, <b& ...

The Viem Type Inference ABI has mysteriously vanished

I followed the documentation and online resources to migrate from Viem 0.8.x to 1.4.1, but I am facing difficulties making it work as intended. Here is the function I am trying to read from my ABI: { inputs: [], name: 'getTreasuryAndP ...

An issue arises when attempting to write to the database specifically when the model is imported from a separate file

There seems to be an issue with saving the model to the database when it's imported from another file. The error message received is: MongooseError: Operation users.insertOne() buffering timed out after 10000ms at Timeout. (/var/www/bhp_2/server/nod ...