rake aborted! PG::ConnectionBad: fe_sendauth: no password supplied sinatra - ruby

I can't seem to get this to work. I try to run bundle exec rake db:migrate after running bundle exec rake db:create and it gives me this error:
rake aborted!
PG::ConnectionBad: fe_sendauth: no password supplied
/home/david/DBC/survey-gorilla-challenge/Rakefile:106:in block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
I've tried looking around, but it all seems like a solution for rails, whereas I'm using this with Sinatra and activerecord. I'm not sure if that makes any difference. I even tried changing my pg_hba.conf, which looks like this currently:
IPv4 local connections:
host all all 127.0.0.1/32 md5
IPv6 local connections:
host all all ::1/128 md5
I'm not sure how to get this working. Any help is appreciated.

I solved it. I changed my pg_hba.conf to
TYPE DATABASE USER ADDRESS METHOD
"local" is for Unix domain socket connections only
host all all 127.0.0.1/32 trust
IPv4 local connections:
host all PC 127.0.0.1/32 trust
IPv6 local connections:
host all all ::1/128 trust
and then restarted postgres with sudo nano /etc/postgresql/9.3/main/pg_hba.conf. This gets the migration going.

Related

Trying to start Ruby on Rails app with Postgresql --noob

This is my 3rd day in a row trying to start a new app using Postgresql w/ Ruby on rails with wsl ubuntu.....(i'm on windows)
I'm a beginner. I've learned the basic syntax, but getting a practice app running on Postgres i just cant seem to do it. ill literally pay for help if someone can help me out.
Everytime i try to start the database i get
chronokross#DESKTOP-V7DS5HD:/mnt/c/code/nathantest$ rake db:create
Database 'chrono_development' already exists
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"?
Couldn't create 'chrono_test' database. Please check your configuration.
rake aborted!
ActiveRecord::NoDatabaseError: 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"?
Caused by:
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"?
Tasks: TOP => db:create
(See full trace by running task with --trace)
chronokross#DESKTOP-V7DS5HD:/mnt/c/code/nathantest
I've followed millions of guides. I dont know how to connect postgresql on windows to my ubunix server ROR app.
my discord is ChronoKross#1560.
They say to edit my databse yml file. This is how i did it
# PostgreSQL. Versions 9.3 and up are supported.
#
# Install the pg driver:
# gem install pg
# On macOS with Homebrew:
# gem install pg -- --with-pg-config=/usr/local/bin/pg_config
# On macOS with MacPorts:
# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
# On Windows:
# gem install pg
# Choose the win32 build.
# Install PostgreSQL and put its /bin directory on your path.
#
# Configure Using Gemfile
# gem 'pg'
#
default: &default
adapter: postgresql
encoding: unicode
# For details on connection pooling, see Rails configuration guide
# https://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
development:
<<: *default
database: chrono_development
# The specified database role being used to connect to postgres.
# To create additional roles in postgres see `$ createuser --help`.
# When left blank, postgres will use the default role. This is
# the same name as the operating system user running Rails.
username: chronokross
# The password associated with the postgres role (username).
password: *****
# Connect on a TCP socket. Omitted by default since the client uses a
# domain socket that doesn't need configuration. Windows does not have
# domain sockets, so uncomment these lines.
host: localhost
# The TCP port the server listens on. Defaults to 5432.
# If your server runs on a different port number, change accordingly.
#port: 5432
# Schema search path. The server defaults to $user,public
#schema_search_path: myapp,sharedapp,public
# Minimum log levels, in increasing order:
# debug5, debug4, debug3, debug2, debug1,
# log, notice, warning, error, fatal, and panic
# Defaults to warning.
#min_messages: notice
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: chrono_test
# As with config/credentials.yml, you never want to store sensitive information,
# like your database password, in your source code. If your source code is
# ever seen by anyone, they now have access to your database.
#
# Instead, provide the password or a full connection URL as an environment
# variable when you boot the app. For example:
#
# DATABASE_URL="postgres://myuser:mypass#localhost/somedatabase"
#
# If the connection URL is provided in the special DATABASE_URL environment
# variable, Rails will automatically merge its configuration values on top of
# the values provided in this file. Alternatively, you can specify a connection
# URL environment variable explicitly:
#
# production:
# url: <%= ENV['MY_APP_DATABASE_URL'] %>
#
# Read https://guides.rubyonrails.org/configuring.html#configuring-a-database
# for a full overview on how database connection configuration can be specified.
#
production:
<<: *default
database: chrono_production
username: chronokross
password: *****
PLEASE PLEASE I BEG FOR HELP. I've been studying 8hrs a day but this is a HUGE road block, i need someone to tell me what to do in noob terms or screenshare with me.
again my discord is ChronoKross#1560

heroku pg:psql --app error CLI FATAL: no pg_hba.conf entry for host "hostIp", user "user name", database "Name", SSL off

I added the data base PostgreSQL on my Heroku app, I am trying to connect through CLI and pgadmin I getting the same error as below:
FATAL: no pg_hba.conf entry for host "hostIp", user "user name", database "Name", SSL off
I tried adding pg_hba.conf below entries:
# IPv4 local connections:
host all all 127.0.0.1/32 md5
host all all all md5
# IPv6 local connections:
host all all ::1/128 md5
host all all all md5
still no luck, Hope anyone can assist me in that.
For this answer, I made an assumption that you are on Windows.
I ran into this problem as well and soon found out that I missed an important step which is to add the binaries of the PostgreSQL to the PATH environment variable.
This is where I found out:
Remember to update your PATH environment variable to add the bin directory of your Postgres installation. The directory will be similar to this: C:\Program Files\PostgreSQL<VERSION>\bin. If you forget to update your PATH, commands like heroku pg:psql won’t work.

Install rails with WSL and postgresql

I'm trying to setup a rails environment development on a Windows 10.
I follow the tutorial of 'go_rails' (https://gorails.com/setup/windows/10)
Most of the installation seems to worked fine (when i type rby -v or rails -v in the bash it's return the expected result).
My issue is with postresql which is used for the project i work on it.
Following the instructions of the tutorial i install Postgresql (10) directly on Windows. It's seems to work since in can login using the pgadmin on windows or by typing 'psql -p 5432 -h localhost -U postgres' in the bash.
So it's look like postgresql is working, but when i do a rake db:create in bash, i got an error : could not connect to the server: No such file or directory. Is the server running locally and accepting connections on Unix domain socket '/var/run/postgresql/.s.PGSQL.5432'
In the postgresql.conf (C:/Programms/.../Data/postgresql.conf) the listen_addresses is set to '*'.
A bit after there is a line named '#unix_socket_directoris = ''', do you thing i should set something in there?
I really need to get that project work.
Thanks for your help
The problem is likely that you've installed the Windows binary for PostgreSQL, but you're trying to connect to it from Windows Subsystem for Linux using a Unix socket, which doesn't exist.
You need to use TCP/IP to connect rather than a Unix socket. When typing psql on the command line, add the option --host=127.0.0.1 to connect via TCP/IP.
I just went through the entire Go Rails tutorial and I also had trouble at the rake db:create step. All you need to do is add host: 127.0.0.1 to your database.yml as shown below. Make sure to Start PostgreSQL before you run rake db:create.
default: &default
host: 127.0.0.1
adapter: postgresql
encoding: unicode
username: postgres
password: ENV['POSTGRESQL_PASSWORD']
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
development:
<<: *default
database: app_development
test:
<<: *default
database: app_test
production:
<<: *default
database: app_production
username: app_username
password: <%= ENV['APP_DATABASE_PASSWORD'] %>
Add host: localhost to your default: in database.yml. Without something telling rails where to look for the host, it looks for the process in linux, which, of course, won't work, since windows processes are not exposed to the wsl layer.

ruby - check ssh connection to a remote through another machine

I am using aws sdk in order to create machines, and as soon as the machines are created, i want to check ssh connection to those machines.
the problem is - from my machines, i don't have access to EC2 machines, but there is another machine on my network, which i have access to through ssh, and this machine do have access to the EC2 machines.
Now, is there a simple way through ruby to check ssh to EC2 machine ?
I've tried the following:
proxy = Net::SSH::Proxy::HTTP.new('<proxy ip>', 22)
Net::SSH.start('<EC2 machine's IP>', '<USER>', :proxy => proxy) do |ssh|
end
Errno::ECONNRESET: Connection reset by peer
from /home/galt/.rvm/gems/ruby-1.9.3-p484/gems/net-ssh-2.7.0/lib/net/ssh/proxy/http.rb:76:in `gets'
from /home/galt/.rvm/gems/ruby-1.9.3-p484/gems/net-ssh-2.7.0/lib/net/ssh/proxy/http.rb:76:in `parse_response'
from /home/galt/.rvm/gems/ruby-1.9.3-p484/gems/net-ssh-2.7.0/lib/net/ssh/proxy/http.rb:62:in `open'
from /home/galt/.rvm/gems/ruby-1.9.3-p484/gems/net-ssh-2.7.0/lib/net/ssh/transport/session.rb:67:in `block in initialize'
from /home/galt/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/1.9.1/timeout.rb:55:in `timeout'
from /home/galt/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/1.9.1/timeout.rb:100:in `timeout'
from /home/galt/.rvm/gems/ruby-1.9.3-p484/gems/net-ssh-2.7.0/lib/net/ssh/transport/session.rb:67:in `initialize'
from /home/galt/.rvm/gems/ruby-1.9.3-p484/gems/net-ssh-2.7.0/lib/net/ssh.rb:200:in `new'
from /home/galt/.rvm/gems/ruby-1.9.3-p484/gems/net-ssh-2.7.0/lib/net/ssh.rb:200:in `start'
from (irb):12
from /home/galt/.rvm/rubies/ruby-1.9.3-p484/bin/irb:12:in `<main>'
thanks !
The Net::SSH::Proxy::HTTP class is meant to point to a HTTP proxy for your ssh connections. So, you will need to set up a HTTP proxy on that machine to be able to proxy your connections through it.
If you can't do that, I suggest you use SSH reverse tunnels. We will achieve this by opening the port 8080 on the local machine, forward the traffic sent there to Server using the SSH tunnel and make Server forward it to the EC2 instance on port 22. The net-ssh ruby gem already provide commands to help us with that, but we will need to run 2 sessions in parallel, using threads:
proxy_thread = Thread.new do
Net::SSH.start('<proxy ip>', '<user>') do |ssh|
ssh.forward.remote(8080, "<AWS ip>", 22)
ssh.loop { true }
end
end
proxy_thread.start
Net::SSH.start('localhost', '<localhost user>', port: 8080) do |ssh|
#done
end
proxy_thread.kill

Cassandra on EC2

I followed this http://www.datastax.com/documentation/cassandra/2.0/cassandra/install/installAMI.html and then I try to use this ruby gem (https://github.com/iconara/cql-rb) to connect to my EC2 instance but i get the following error:
irb(main):013:0> Cql::Client.connect(host: 'PUBLIC_DNS', port: 9160)
Cql::Io::ConnectionError: end of file reached from
/Users/damien/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/cql-rb-2.0.0.pre0/lib/cql/client/synchronous_client.rb:32:in
connect' from
/Users/damien/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/cql-rb-2.0.0.pre0/lib/cql/client.rb:118:in
connect' from (irb):13 from
/Users/damien/.rbenv/versions/1.9.3-p392/bin/irb:12:in `'
If I SSH to the box and use cqlsh to connect to localhost it works fine.
Any idea?
You should use the native_transport_port which defaults to 9042, not the rpc_port which defaults to 9160. However, both ports are configurable inside of cassandra.yaml after a Cassandra server restart.

Resources