Create connection with postres user with superuser role and unknown password

46 Views Asked by At

In an attempt to create a connection to a database for blazer over the ahoy_matey gem, from within a rails application, the configuration requires to connect to postgres as such, first attempted directly rather than through an ENV variable

data_sources:
  main:
#    url: <%= ENV["BLAZER_DATABASE_URL"] %>
    url: "postgres://[email protected]:5432/databasename_production"

where the syntax should be ENV["BLAZER_DATABASE_URL"] = "postgres://user:password@hostname:5432/databasename_production"

the user deploy_root exists for postgres with SUPERUSER privileges, however, the database.yml was erroneously populated :

production:
  <<: *default
  database: databasename_production
  username: deploy_root
  password: <%= ENV["DATABASENAME_DATABASE_PASSWORD"] %>

where the console confirms that

> ENV["DATABASENAME_DATABASE_PASSWORD"]
=> nil

the application runs as expected, connecting to the database. The replication of those connections for blazer is however failing as such:
"postgres://[email protected]:5432/databasename_production"

ActiveRecord cannot connect  
`ActiveRecord::ConnectionNotEstablished (could not connect to server: Connection refused
        Is the server running on host "111.222.333.44" and accepting
        TCP/IP connections on port 5432?`

Blazer requires the setting of data_sources/main (pity it does not have a mechanism to rely on the rails app connection...) This raises the question of how to connect, given there is uncertainty with the password (that is used for another application on this server).

• how to recover the encrypted password for the postgres USER?
• if it is nil how to establish the connection?

1

There are 1 best solutions below

0
On BEST ANSWER

@dbugger has the proper perspective. Additionally, the gem does document a useful strategy for creating a read-only user for blazer's accessing the Ahoy data

at which point, however the connection on a self-enclosed rails app connects to the local ip "postgres://blazer:[email protected]:5432/databasename_production"