Looking for any guidance on how to troubleshoot a failed Postgresql connection to a remote FreeBSD machine. Don’t have much experience with PostgresQL and a bit rusty on FreeBSD. This is a NodeJS application that connects to a database via TypeORM.
It appears to be a permissions or firewall problem on the remote FreeBSD machine. Previously the application connected flawlessly to a remote Postgres-as-a-service database provided by ElephantSQL. When the attempt was made to manage the database independently it suddenly stopped working.
It appears to be a permissions or firewall problem on the remote FreeBSD machine. Previously the application connected flawlessly to a remote Postgres-as-a-service database provided by ElephantSQL. When the attempt was made to manage the database independently it suddenly stopped working.
Code:
FreeBSD version:
13.0-RELEASE-p12
Postgresql error:
ERROR [TypeOrmModule] Unable to connect to the database.
Error: connect ETIMEDOUT XX.XX.XX.XXX:5432
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1187:16)
Steps to create database:
Configure remote machine
# freebsd-update fetch install
# reboot
# freebsd-update install
# freebsd-version
# pkg bootstrap
# pkg install sudo vim postgresql14-server
# pkg update
# pkg upgrade
Configure PF
ext_if="vtnet0"
set block-policy return
scrub in on $ext_if all fragment reassemble
set skip on lo
block in all
pass out quick keep state
antispoof for $ext_if inet
pass in inet proto tcp from any to any port { 22 5432 } flags S/SA keep state
Enable services
# sysrc pf_enable="yes"
# sysrc pflog_enable="yes"
# sysrc postgres_enable="yes"
# reboot
Initiate database
# /usr/local/etc/rc.d/postgresql initdb
# /usr/local/etc/rc.d/postgresql start
Create postgres database password
# su - postgres
$ psql
\password // Enter password
$ exit
Postgresql database url
postgresql://postgres:secret_password@XX.XX.XX.XXX/postgres
Ensure database processes are owned by user postgres
# top
output:
PID USERNAME THR PRI NICE SIZE RES STATE TIME WCPU COMMAND
642 root 1 20 0 11M 948K select 0:10 0.00% devd
915 root 1 20 0 17M 3560K select 0:10 0.00% ntpd
401 _pflogd 1 20 0 13M 1980K bpf 0:07 0.00% pflogd
847 root 1 20 0 13M 1980K select 0:06 0.00% syslogd
14350 postgres 1 20 0 174M 30M select 0:04 0.00% postgres
14355 postgres 1 20 0 174M 30M kqread 0:02 0.00% postgres
14356 postgres 1 20 0 32M 19M kqread 0:02 0.00% postgres
946 root 1 20 0 20M 5660K select 0:01 0.00% sshd
928 root 1 20 0 13M 1948K nanslp 0:01 0.00% cron
14353 postgres 1 20 0 174M 30M kqread 0:01 0.00% postgres
14354 postgres 1 20 0 174M 30M kqread 0:01 0.00% postgres
14357 postgres 1 20 0 174M 30M kqread 0:00 0.00% postgres
14352 postgres 1 20 0 174M 30M kqread 0:00 0.00% postgres
18520 root 1 20 0 21M 7796K select 0:00 0.00% sshd
18524 root 1 20 0 13M 2772K wait 0:00 0.00% sh
395 root 1 20 0 13M 1808K kqread 0:00 0.00% rtsold
636 _dhcp 1 20 0 13M 2176K select 0:00 0.00% dhclient
556 root 1 45 0 13M 1984K select 0:00 0.00% dhclient