misskey-dev / misskey

🌎 A completely free and open interplanetary microblogging platform πŸš€
https://misskey-hub.net/
GNU Affero General Public License v3.0
9.99k stars 1.36k forks source link

Error during migration run: Error: connect ECONNREFUSED 127.0.0.1:5432 #11111

Open Ria-Fox opened 1 year ago

Ria-Fox commented 1 year ago

Currently attempting to open a server with Docker. Most of the runs are successful, but I am getting an error during DB initialization after the misskey build.

I went through a lot of issue pages to troubleshoot this, but most of the time it was a case of unhealthy postgresql or trying to initialize outside of docker. #9054 #9058 I believe this is not the case, so create an issue.

πŸ’‘ Summary

Error occurs during server initialize

πŸ₯° Expected Behavior

Initialize success, and can be run server

🀬 Actual Behavior

Error occur:

# docker compose run --rm web pnpm run init
[+] Building 0.0s (0/0)
[+] Creating 4/0
 βœ” Network misskey_internal_network  Created                                                                    0.0s
 βœ” Network misskey_external_network  Created                                                                    0.0s
 βœ” Container misskey-db-1            Created                                                                    0.0s
 βœ” Container misskey-redis-1         Created                                                                    0.0s
[+] Running 2/2
 βœ” Container misskey-db-1     Started                                                                           0.6s
 βœ” Container misskey-redis-1  Started                                                                           0.3s
[+] Building 0.0s (0/0)

> misskey@13.13.2 init /misskey
> pnpm migrate

> misskey@13.13.2 migrate /misskey
> cd packages/backend && pnpm migrate

> backend@ migrate /misskey/packages/backend
> pnpm typeorm migration:run -d ormconfig.js

Error during migration run:
Error: connect ECONNREFUSED 127.0.0.1:5432
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16) {
  errno: -111,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 5432
}
 ELIFECYCLE  Command failed with exit code 1.
 ELIFECYCLE  Command failed with exit code 1.
 ELIFECYCLE  Command failed with exit code 1.

postgresql container log:

# docker logs misskey-db-1
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /var/lib/postgresql/data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... UTC
creating configuration files ... ok
running bootstrap script ... ok
sh: locale: not found
2023-07-04 17:14:45.833 UTC [31] WARNING:  no usable system locales were found
performing post-bootstrap initialization ... ok
initdb: warning: enabling "trust" authentication for local connections
initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.
syncing data to disk ... ok

Success. You can now start the database server using:

    pg_ctl -D /var/lib/postgresql/data -l logfile start

waiting for server to start....2023-07-04 17:14:46.308 UTC [37] LOG:  starting PostgreSQL 15.3 on x86_64-pc-linux-musl, compiled by gcc (Alpine 12.2.1_git20220924-r10) 12.2.1 20220924, 64-bit
2023-07-04 17:14:46.310 UTC [37] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2023-07-04 17:14:46.316 UTC [40] LOG:  database system was shut down at 2023-07-04 17:14:46 UTC
2023-07-04 17:14:46.320 UTC [37] LOG:  database system is ready to accept connections
 done
server started
CREATE DATABASE

/usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*

waiting for server to shut down....2023-07-04 17:14:46.492 UTC [37] LOG:  received fast shutdown request
2023-07-04 17:14:46.495 UTC [37] LOG:  aborting any active transactions
2023-07-04 17:14:46.497 UTC [37] LOG:  background worker "logical replication launcher" (PID 43) exited with exit code 1
2023-07-04 17:14:46.497 UTC [38] LOG:  shutting down
2023-07-04 17:14:46.499 UTC [38] LOG:  checkpoint starting: shutdown immediate
2023-07-04 17:14:46.548 UTC [38] LOG:  checkpoint complete: wrote 918 buffers (5.6%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.021 s, sync=0.022 s, total=0.052 s; sync files=250, longest=0.002 s, average=0.001 s; distance=4222 kB, estimate=4222 kB
2023-07-04 17:14:46.564 UTC [37] LOG:  database system is shut down
 done
server stopped

PostgreSQL init process complete; ready for start up.

2023-07-04 17:14:46.617 UTC [1] LOG:  starting PostgreSQL 15.3 on x86_64-pc-linux-musl, compiled by gcc (Alpine 12.2.1_git20220924-r10) 12.2.1 20220924, 64-bit
2023-07-04 17:14:46.617 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2023-07-04 17:14:46.617 UTC [1] LOG:  listening on IPv6 address "::", port 5432
2023-07-04 17:14:46.621 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2023-07-04 17:14:46.626 UTC [53] LOG:  database system was shut down at 2023-07-04 17:14:46 UTC
2023-07-04 17:14:46.630 UTC [1] LOG:  database system is ready to accept connections
2023-07-04 17:19:46.726 UTC [51] LOG:  checkpoint starting: time
2023-07-04 17:19:50.859 UTC [51] LOG:  checkpoint complete: wrote 44 buffers (0.3%); 0 WAL file(s) added, 0 removed, 0 recycled; write=4.118 s, sync=0.008 s, total=4.133 s; sync files=12, longest=0.004 s, average=0.001 s; distance=252 kB, estimate=252 kB

πŸ“ Steps to Reproduce

  1. Follow instruction for installation via docker

πŸ“Œ Environment

πŸ›° Backend (for server admin)

akibasocial commented 1 year ago

Same problem trying to run it locally with docker compose on macOS (13.4.1 M1).

The first command docker compose build runs fine.
But docker compose run --rm web pnpm run init fails with the output:

> misskey@13.13.2 init /misskey
> pnpm migrate

> misskey@13.13.2 migrate /misskey
> cd packages/backend && pnpm migrate

> backend@ migrate /misskey/packages/backend
> pnpm typeorm migration:run -d ormconfig.js

Error during migration run:
Error: connect ECONNREFUSED 127.0.0.1:5432
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16) {
  errno: -111,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 5432
}
 ELIFECYCLE  Command failed with exit code 1.
 ELIFECYCLE  Command failed with exit code 1.
 ELIFECYCLE  Command failed with exit code 1.

I didn't change any other settings besides the url, so I can't have put the wrong port anywhere.

Also tried removing the internal: true from the docker-compose.yml, but got the same error

ZerglingGo commented 1 year ago

You must change .config/default.yml database host with postgres container


#   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
#β”€β”€β”€β”˜ PostgreSQL configuration └────────────────────────────────

db:
  host: db
  port: 5432
Ria-Fox commented 1 year ago

Thanks for answer @ZerglingGo ! I've solved this problem with network_mode: "host" on docker-compose.yml. But also I've noticed there are docker_example.yml in .config directory, and this file already solved this problem.

In Misskey-hub's installation guide(en, kr), it directed copy default.yml, but I think it must be edited to copy docker_default.yml. This resolve all problems for the docker installation.