A solution that does not require explicit port configuration in database.yml
Some errors during database creation and migration:
Invalid Redis connection to a specific port / connection refusal
bundle exec rake db:create
rake aborted!
Redis::CannotConnectError: Error connecting to Redis on localhost:6379 (Errno::ECONNREFUSED)
...
Caused by:
Errno::ECONNREFUSED: Connection refused - connect(2) for 127.0.0.1:6379
...
Caused by:
IO::EINPROGRESSWaitWritable: Operation now in progress - connect(2) would block
...
Tasks: TOP => db:create => db:load_config => environment
(See full trace by running task with --trace)
From this error we can see that the port Redis uses is 6379, and we can fix this by starting the Redis server via that port.
By default, redis-server --daemonize yes should work, but if not, use:
redis-server --daemonize yes --port 6379
Check status of Redis instance:
redis-cli
127.0.0.1:6379> ping
PONG
Invalid connection to psql port
bundle exec rake db:migrate
PG::ConnectionBad: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
From this error we can see that PostgreSQL is having trouble connecting to port 5432. Usually starting the service should work
sudo service postgresql start
If this still doesn’t work and the error persists, try checking to see which port the service is listening from, and if necessary, change the port to the one you want in postgresql.conf:
pg_isready
/var/run/postgresql:5432 - no response
or
/var/run/postgresql:5432 - accepting connections
The Result
Once we have done the above or executed the start-discourse command, the two instances should run on their default/specified ports. To check their status via the default Windows cmd terminal, we can run:
netstat -anop tcp
which will show something like this:
Proto Local Address Foreign Address State PID
TCP 127.0.0.1:5432 0.0.0.0:0 LISTENING 17768
TCP 127.0.0.1:6379 0.0.0.0:0 LISTENING 17768
We have now confirmed that both our postgresql and redis-server instances are running.
We can also check the status of the instances on Ubuntu or WSL, with the following commands:
lsof -i
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mailcatch 3244 rickyc0626 7u IPv4 36127 0t0 TCP localhost:1025 (LISTEN)
mailcatch 3244 rickyc0626 8u IPv4 36128 0t0 TCP *:socks (LISTEN)
redis-ser 3287 rickyc0626 6u IPv6 29352 0t0 TCP *:6379 (LISTEN)
redis-ser 3287 rickyc0626 7u IPv6 29353 0t0 TCP *:6379 (LISTEN)
sudo ss -plunt | grep postgres
tcp LISTEN 0 128 127.0.0.1:5432 0.0.0.0:* users:(("postgres",pid=3070,fd=7))
pg_lsclusters
Ver Cluster Port Status Owner Data directory Log file
10 main 5432 online postgres /var/lib/postgresql/10/main /var/log/postgresql/postgresql-10-main.log
From here, these commands should work with no major issues, without needing to modify the database.yml file:
bundle exec rake db:create
bundle exec rake db:migrate
RAILS_ENV=test bundle exec rake db:create db:migrate
Any further issues that show up can be addressed in the future.