I'm on a new-ish macbook: MacOs Big Sur.
I installed a local development environment via https://rails.new/.
For my day-job, we run everything in Docker, but I'm also doing ruby/rails develpment within that docker context.
I've had a beast of a time trying to connect to a local working postgres service.
Any time I try to run migrations, or connect via the terminal with psql, I get a similar error message, that makes me wonder if I fat-fingered a value into a text file somewhere, and don't know where:
rails db:migrate
rails aborted!
ActiveRecord::ConnectionNotEstablished: invalid integer value "5432export" for connection option "port"
Caused by:
PG::ConnectionBad: invalid integer value "5432export" for connection option "port"
Or when I run psql:
$ psql
psql: error: invalid integer value "5432export" for connection option "port
This happens even when I do rails new, so I think I messed up with something in a plist file or postgres config somewhere. It's not happening on my other laptop. This string doesn't exist in the results of rails new, so I assume it's inside of a postgres config file somewhere.
$ which psql
/usr/local/bin/psql
$ brew list postgres
/usr/local/Cellar/postgresql/14.3/bin/clusterdb
/usr/local/Cellar/postgresql/14.3/bin/createdb
/usr/local/Cellar/postgresql/14.3/bin/createuser
/usr/local/Cellar/postgresql/14.3/bin/dropdb
/usr/local/Cellar/postgresql/14.3/bin/dropuser
/usr/local/Cellar/postgresql/14.3/bin/ecpg
/usr/local/Cellar/postgresql/14.3/bin/initdb
/usr/local/Cellar/postgresql/14.3/bin/oid2name
/usr/local/Cellar/postgresql/14.3/bin/pg_amcheck
/usr/local/Cellar/postgresql/14.3/bin/pg_archivecleanup
/usr/local/Cellar/postgresql/14.3/bin/pg_basebackup
/usr/local/Cellar/postgresql/14.3/bin/pg_checksums
/usr/local/Cellar/postgresql/14.3/bin/pg_config
/usr/local/Cellar/postgresql/14.3/bin/pg_controldata
/usr/local/Cellar/postgresql/14.3/bin/pg_ctl
/usr/local/Cellar/postgresql/14.3/bin/pg_dump
/usr/local/Cellar/postgresql/14.3/bin/pg_dumpall
/usr/local/Cellar/postgresql/14.3/bin/pg_isready
/usr/local/Cellar/postgresql/14.3/bin/pg_receivewal
/usr/local/Cellar/postgresql/14.3/bin/pg_recvlogical
/usr/local/Cellar/postgresql/14.3/bin/pg_resetwal
/usr/local/Cellar/postgresql/14.3/bin/pg_restore
/usr/local/Cellar/postgresql/14.3/bin/pg_rewind
/usr/local/Cellar/postgresql/14.3/bin/pg_test_fsync
/usr/local/Cellar/postgresql/14.3/bin/pg_test_timing
/usr/local/Cellar/postgresql/14.3/bin/pg_upgrade
/usr/local/Cellar/postgresql/14.3/bin/pg_verifybackup
/usr/local/Cellar/postgresql/14.3/bin/pg_waldump
/usr/local/Cellar/postgresql/14.3/bin/pgbench
/usr/local/Cellar/postgresql/14.3/bin/postgres
/usr/local/Cellar/postgresql/14.3/bin/postmaster
/usr/local/Cellar/postgresql/14.3/bin/psql
/usr/local/Cellar/postgresql/14.3/bin/reindexdb
/usr/local/Cellar/postgresql/14.3/bin/vacuumdb
/usr/local/Cellar/postgresql/14.3/bin/vacuumlo
/usr/local/Cellar/postgresql/14.3/homebrew.mxcl.postgresql.plist
/usr/local/Cellar/postgresql/14.3/homebrew.postgresql.service
/usr/local/Cellar/postgresql/14.3/include/libpq/libpq-fs.h
/usr/local/Cellar/postgresql/14.3/include/postgresql/ (827 files)
/usr/local/Cellar/postgresql/14.3/include/ (23 files)
/usr/local/Cellar/postgresql/14.3/lib/libecpg.6.14.dylib
/usr/local/Cellar/postgresql/14.3/lib/libecpg_compat.3.14.dylib
/usr/local/Cellar/postgresql/14.3/lib/libpgtypes.3.14.dylib
/usr/local/Cellar/postgresql/14.3/lib/libpq.5.14.dylib
/usr/local/Cellar/postgresql/14.3/lib/pkgconfig/ (4 files)
/usr/local/Cellar/postgresql/14.3/lib/postgresql/ (91 files)
/usr/local/Cellar/postgresql/14.3/lib/ (17 other files)
/usr/local/Cellar/postgresql/14.3/share/doc/ (1143 files)
/usr/local/Cellar/postgresql/14.3/share/man/ (294 files)
/usr/local/Cellar/postgresql/14.3/share/postgresql/ (860 files)
I've reinstalled postgres via brew
and postgres seems to be running:
$ brew services
Name Status User File
postgresql none
postgresql@13 started username ~/Library/LaunchAgents/homebrew.mxcl.postgresql@13.plist
When I switch the running service, I get the same problem:
$ brew services stop postgresql@13
Stopping `postgresql@13`... (might take a while)
==> Successfully stopped `postgresql@13` (label: homebrew.mxcl.postgresql@13)
$ brew services start postgresql
==> Successfully started `postgresql` (label: homebrew.mxcl.postgresql)
$ psql
psql: error: invalid integer value "5432export" for connection option "port"
I am starting to try to run find commands, in my terminal, looking through the bin directory for the string 5432export but have not found it, and really don't know much about what lives inside of bin/psql, or even even if I'm looking in the correct general location.
I've tried different versions of ruby and rails, as well. Just can't get away from this error on this laptop!
Update:
When I run psql -p 5432, I get:
$ psql -p 5432
psql: error: connection to server at "127.0.0.1", port 5432 failed: FATAL: role "postgres" does not exist
And:
$ psql -p 5432 -U postgres
psql: error: connection to server at "127.0.0.1", port 5432 failed: FATAL: role "postgres" does not exist
Update 2:
Solved below! It was an environment variable issue, phew, thank you so much, this was driving me bonkers:
$ env | grep PG
PGHOST=127.0.0.1
PGPORT=5432export
PGUSER=postgres