504 error when trying to connect to postgres via the node backend

 postgres_1 | The files belonging to this database system will be owned by user "postgres". postgres_1 | This user must also own the server process. postgres_1 | postgres_1 | The database cluster will be initialized with locale "en_US.utf8". postgres_1 | The default database encoding has accordingly been set to "UTF8". postgres_1 | The default text search configuration will be set to "english". postgres_1 | postgres_1 | Data page checksums are disabled. postgres_1 | postgres_1 | fixing permissions on existing directory /var/lib/postgresql/data ... ok postgres_1 | creating subdirectories ... ok postgres_1 | selecting dynamic shared memory implementation ... posix postgres_1 | selecting default max_connections ... 100 postgres_1 | selecting default shared_buffers ... 128MB postgres_1 | selecting default time zone ... Etc/UTC postgres_1 | creating configuration files ... ok postgres_1 | running bootstrap script ... ok postgres_1 | performing post-bootstrap initialization ... ok postgres_1 | syncing data to disk ... ok postgres_1 | postgres_1 | postgres_1 | Success. You can now start the database server using: postgres_1 | postgres_1 | pg_ctl -D /var/lib/postgresql/data -l logfile start postgres_1 | postgres_1 | initdb: warning: enabling "trust" authentication for local connections postgres_1 | You can change this by editing pg_hba.conf or using the option -A, or postgres_1 | --auth-local and --auth-host, the next time you run initdb. postgres_1 | waiting for server to start....2020-05-22 17:59:43.250 UTC [45] LOG: starting PostgreSQL 12.3 (Debian 12.3-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit postgres_1 | 2020-05-22 17:59:43.275 UTC [45] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432" postgres_1 | 2020-05-22 17:59:43.391 UTC [46] LOG: database system was shut down at 2020-05-22 17:59:42 UTC postgres_1 | 2020-05-22 17:59:43.397 UTC [45] LOG: database system is ready to accept connections postgres_1 | done postgres_1 | server started postgres_1 | postgres_1 | /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/* postgres_1 | postgres_1 | 2020-05-22 17:59:43.409 UTC [45] LOG: received fast shutdown request postgres_1 | waiting for server to shut down....2020-05-22 17:59:43.416 UTC [45] LOG: aborting any active transactions postgres_1 | 2020-05-22 17:59:43.422 UTC [45] LOG: background worker "logical replication launcher" (PID 52) exited with exit code 1 postgres_1 | 2020-05-22 17:59:43.424 UTC [47] LOG: shutting down postgres_1 | 2020-05-22 17:59:43.567 UTC [45] LOG: database system is shut down postgres_1 | done postgres_1 | server stopped postgres_1 | postgres_1 | PostgreSQL init process complete; ready for start up. postgres_1 | postgres_1 | 2020-05-22 17:59:43.640 UTC [1] LOG: starting PostgreSQL 12.3 (Debian 12.3-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit postgres_1 | 2020-05-22 17:59:43.640 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432 postgres_1 | 2020-05-22 17:59:43.640 UTC [1] LOG: listening on IPv6 address "::", port 5432 postgres_1 | 2020-05-22 17:59:43.666 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432" postgres_1 | 2020-05-22 17:59:43.714 UTC [54] LOG: database system was shut down at 2020-05-22 17:59:43 UTC postgres_1 | 2020-05-22 17:59:43.724 UTC [1] LOG: database system is ready to accept connections 

So postgres is working and so is the backend:

 backend_1 | Pool { backend_1 | _events: [Object: null prototype] {}, backend_1 | _eventsCount: 0, backend_1 | _maxListeners: undefined, backend_1 | options: { backend_1 | Client: [Function: Client] { Query: [Function: Query] }, backend_1 | user: 'postgres', backend_1 | host: 'postgres', backend_1 | database: 'postgres', backend_1 | password: 'postgres_password', backend_1 | port: '5432', backend_1 | max: 10, backend_1 | idleTimeoutMillis: 10000 backend_1 | }, backend_1 | log: [Function (anonymous)], backend_1 | Client: [Function: Client] { Query: [Function: Query] }, backend_1 | Promise: [Function: Promise], backend_1 | _clients: [], backend_1 | _idle: [], backend_1 | _pendingQueue: [], backend_1 | _endCallback: undefined, backend_1 | ending: false, backend_1 | ended: false, backend_1 | [Symbol(kCapture)]: false backend_1 | } 

But I am getting a 504 status on every call.

 const pgClient = new Pool({ user: keys.postgresUser, host: keys.postgresHost, database: keys.postgresDatabase, password: keys.postgresPassword, port: keys.postgresPort }); app.get('/postgres', (req, res) => { result = {}; pgClient.connect((err, client, release) => { if (err) { result['postgres'] = false; } else { result['postgres'] = true; } release(); res.send(result); }) }) 

server { listen 80; location /api { rewrite /api/(.*) /$1 break; proxy_pass http://backend; } location /sockjs-node { proxy_pass http://frontend; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; } } And the config seems to be fine version: '3' services: postgres: restart: always image: 'postgres' ports: - '5432:5432' environment: - POSTGRES_USER=postgres - POSTGRES_PASSWORD=postgres_password backend: build: dockerfile: Dockerfile.dev context: ./backend volumes: - /app/node_modules - ./backend:/app environment: - PGUSER=postgres - PGHOST=postgres - PGDATABASE=postgres - PGPASSWORD=postgres_password - PGPORT=5432 depends_on: - postgres nginx: restart: always build: dockerfile: Dockerfile.dev context: ./nginx ports: - '4050:80' stdin_open: true tty: true depends_on: - backend 

So does anyone know why it's happening. It worked with redis, but it doesn't seem to work with postgres.

submitted by /u/jackofallsnakes
[link] [comments]
Source: Reddit