Can not connect Rails app with PostgreSQL on ubuntu - ruby

i am unable to connect My rails app with PostgreSQL database which is running on my Ubuntu server running on certain instance.I created new user and password by using the following command.
1-sudo -u postgres createuser -s user1
2-sudo -u postgres psql.
3-postgres=\\password userpass
Check my database.yml file which is given below.
database.yml:
development:
adapter: postgresql
encoding: unicode
database: 100sallon_development
pool: 5
username: user1
password: *******
host: 10.*.*.*
test:
adapter: postgresql
encoding: unicode
database: 100sallon_test
pool: 5
username: user1
password: *******
host: 10.*.*.*
production:
adapter: postgresql
encoding: unicode
database: 100sallon_production
pool: 5
username: user1
password: ******
host: 10.*.*.*
When i tried to create the database using the below command rake db:create it gave me the below error.
Error:
could not connect to server:connection refused
Is the server running on the host:10.*.*.* and accepting
TCP/IP connections on the port 5432
My Ubuntu server is running on given IP.But still face problem to connect with the PostgreSQL database.Please help me to resolve this error.Thank you.

Related

Issue implementing Sql_tracker_store

I want to use sql tracker store to store the conversation history in db but it seems it is not working for me.
I am having MySQL database which i want to connect for that i am using below code in my endpoint.yml
tracker_store:
type: SQL
dialect: "sqlite" # the dialect used to interact with the db
url: "localhost" # (optional) host of the sql db
db: "chatbot" # path to your db
username: "root" # username used for authentication
password: "test" # password used for authentication
when i am running rasa shell -m models --endpoints endpoints.yml
i am getting below error.
" sqlite:////absolute/path/to/file.db" % (url,)
sqlalchemy.exc.ArgumentError: Invalid SQLite URL: sqlite://root:test#localhost/c
hatbot
Valid SQLite URL forms are:
sqlite:///:memory: (or, sqlite://)
sqlite:///relative/path/to/file.db
sqlite:////absolute/path/to/file.db
When i tried to connect the same db using python code it worked for me. Below is my python code.
import mysql.connector
mydb = mysql.connector.connect(host="localhost",port="3306",user="root",database="chatbot",password="test")
mycursor = mydb.cursor()
sql = "Show tables;"
mycursor.execute(sql)
myresult = mycursor.fetchall()
print(myresult)
for x in myresult:
print(x)
Please help me how can i resolve this.
You need to change the dialect to use MySQL and db to include the .db suffix in your endpoint.yml:
tracker_store:
type: SQL
dialect: "mysql" # the dialect used to interact with the db
url: somewhere
db: "chatbot.db"
username: "root"
password: "test"
More info in the SQLALchemy docs 😊
You need to install pymysql using pip.
tracker_store:
type: SQL
dialect: "mysql+pymysql"
url: "localhost"
db: "Rasabot"
username: "root"
password: "xyz"

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.

Database.yml file for activerecord-jdbcvertica-adapter for jruby on rails application

I am using activerecord-jdbcvertica-adapter connector but have no luck creating a new database and migrating tables to vertica database.
My database yaml file looks like:
development:
adapter: Vertica
database: #####
username: #####
password: ####
host: ####
port: 5433
encoding: UTF8
This throws below error when I do bundle exec rake db:create db:migrate db:seed:
Rake tasks not supported by 'Vertica' adapter
Does anyone know how to use this adapter? Am I doing anything wrong?

Heroku: database configuration does not specify adapter

I have an app deployed in heroku that uses postgresql as database. I have created a new model that will connect to a remote mysql database like the following:
# other_database.rb(apps/models/)
class OtherDatabase < ActiveRecord::Base
self.abstract_class = true
establish_connection "remote_#{Rails.env}"
end
# other_model.rb(apps/models/)
class OtherModel < OtherDatabase
self.table_name = "users"
end
i have also edited the database.yml file and added these entries:
remote_development:
adapter: mysql2
encoding: utf8
reconnect: false
database: app_development
pool: 5
username: root
password:
socket: /var/run/mysqld/mysqld.sock
remote_production:
adapter: mysql2
encoding: utf8
reconnect: true
database: app_production
pool: 40
username: root
password: secretpassword
socket: /var/run/mysqld/mysqld.sock
host: 12.34.56.78
The remote database uses mysql as its database.
It works fine in my local machine, but when I deploy it to heroku, it creates an error page so I looked up on the heroku logs, and I found this one out:
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0.beta1/lib/active_record/connection_adapters/connection_specification.rb:52:in `resolve_hash_connection': database configuration does not specify adapter (ActiveRecord::AdapterNotSpecified)
from /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0.beta1/lib/active_record/connection_adapters/connection_specification.rb:46:in `resolve_string_connection'
I am spent almost all my time searching for some answers but to no avail. Hope anyone can help out with this issue.
TIA.
Eralph
Heroku deletes and recreates the database.yml file. This means that what ever you put in your database.yml file will be totally ignored by heroku.
Pop your db credentials in your establish_connection method call like so:
establish_connection(
adapter: 'mysql2',
encoding: 'utf8',
reconnect: true,
database: 'app_production',
pool: 40,
username: 'root',
password: 'secretpassword',
socket: '/var/run/mysqld/mysqld.sock',
host: '12.34.56.78'
)
However it would be better to use a database URL and store it in an environment variable in heroku.
heroku config:set MYSQL_DB_URL=http://example.com/rest_of_the_url
then use
establish_connection(ENV['MYSQL_DB_URL'])
Example and docs for a url can be found here: http://forums.mysql.com/read.php?39,10734,10750

First ruby and postgreSql application - getting could not connect to server: No such file or directory

Ruby 1.9.3 on Mac OS X Lion
Followed several posts on SO about this topic. Neither helped.
Trying to run my first rails and postgreSQL app here.
Following this:
http://guides.rubyonrails.org/getting_started.html
When I do:
"rake db:create"
I get:
could not connect to server: No such file or directory Is the server
running locally and accepting connections on Unix domain socket
"/tmp/.s.PGSQL.5432"?
Some facts:
Not sure what /tmp/ is it referring to but, if it is the one from root, then:
1)
Permissions:
drwxrwxrwx 11 root wheel 374B Jan 4 17:33 tmp
2)
Also, I see no file .s.PGSQL.5432.
3)
I've tried to force the socket location by adding to database.yml the following:
development:
adapter: postgresql
encoding: unicode
database: testblog_development
pool: 5
username: blog
password:
socket: /var/pgsql_socket # <-- this line
(it stills shows me the same error with the /tmp/ path).
4) When I do, which postgres I get:
/usr/local/bin/postgres
(I've used homebrew installation)
5) When I do: brew info postgres I get:
postgresql: stable 9.2.2 http://www.postgresql.org/ Depends on:
readline, ossp-uuid Conflicts with: postgres-xc
/usr/local/Cellar/postgresql/9.2.2 (2819 files, 39M) *
https://github.com/mxcl/homebrew/commits/master/Library/Formula/postgresql.rb
and other bunch of information.
That seems to me like the server isn't running. Do you see anything when you run ps aux | grep postgres from the command line? If all you see is something along the lines of grep postgres in the output, it's not running.
Since you installed PostgreSQL with Homebrew, try brew info postgres for information on how to start up the server if that is indeed the case.
You don't need to specify a socket. Here's a configuration that works for Postgres. You only need to change the database password.
development:
adapter: postgresql
host: localhost
pool: 5
timeout: 5000
username: postgres
password: postgres
database: testblog_development
template: template0

Resources