Postgres connection error on 'bundle exec rails c'

AI-generated summary

The user helmi is experiencing a Postgres connection error when running bundle exec rails c. JammyDodger suggests using cd /var/discourse, ./launcher enter app, and then rails c to access the rails console.

After accessing the console, helmi tries to change the IP regex for the Prometheus exporter plugin but encounters a syntax issue. helmi realizes it’s not a syntax issue and asks for help from sam.

Falco explains that the setting must be configured as an environment variable DISCOURSE_PROMETHEUS_TRUSTED_IP_ALLOWLIST_REGEX in the app.yml file. helmi asks for clarification on the syntax and whether runtime changes are possible.

Falco confirms that only environment variable changes are allowed, not runtime changes, and provides a link to Ruby Regex documentation. The correct syntax for the environment variable is indeed DISCOURSE_PROMETHEUS_TRUSTED_IP_ALLOWLIST_REGEX: 123.145.167.189.

I’m trying to change some forum settings through the console. I didn’t do that a lot yet so I searched for similar questions on the forum.

Unfortunately when executing ‘bundle exec rails c’ i get an error trace that ends with this line

/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.7/lib/active_record/connection_adapters/postgresql_adapter.rb:81:in `rescue in new_client': connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL: Peer authentication failed for user "discourse" (ActiveRecord::NoDatabaseError)

Any idea what’s going on there? Forum itself runs fine - just updated to the latest version the other day.

I get to the rails console from the server by using:

cd /var/discourse
./launcher enter app
rails c

There’s an example of changing a site setting in this topic, Enable setting to allow admins to permanently delete data (this one is a hidden one, but the method is the same)

Thanks, I guess I mixed up both - I was doing bundle exec from within the app.

Still struggling though. I’m looking to change the IP regex for the prometheus exporter plugin.

Not sure which syntax is good to use. I tried

SiteSetting.prometheus_trusted_ip_allowlist_regex=1.2.3.4 with escaping backslashes and quotes around it but nothing worked. 1.2.3.4 being a placeholder of my real IP.

Actually I just noticed it’s probably not a syntax issue

SiteSetting.prometheus_trusted_ip_allowlist_regex="123.145.167.189"
NoMethodError: undefined method `prometheus_trusted_ip_allowlist_regex=' for #<Class:0x000055a8093e7dd8>

Maybe @sam can help with that. Or I’m really just making a mistake here. :thinking:

You must set DISCOURSE_PROMETHEUS_TRUSTED_IP_ALLOWLIST_REGEX and a ENV variable on your app.yml file.

Correct me if I’m wrong but I thought I could set it on runtime first. So I need to set it on app.yml first to then be able to modify it on runtime?

The forum is quite busy so I was hoping to be able to set it on runtime first before setting it permanently in the ENV.

Any hints about the syntax? Can this just be

DISCOURSE_PROMETHEUS_TRUSTED_IP_ALLOWLIST_REGEX: 123.145.167.189

No runtime changes, only via the ENV.

It’s a Ruby Regex object, see https://rubular.com/

Yes, that works.