How to connect to a remote database in a digital ocean server - ruby-on-rails

I have a rails application in a windows local machine and i have a postgresql remote database in digital ocean server [ubuntu server]. How to connect it, I tried like this:
database.yml
default: &default
adapter: postgresql
encoding: unicode
host: xxx.xxx.xxx.xx
username: username
password: password
schema_search_path: "public,shared_extensions"
# For details on connection pooling, see Rails configuration guide
# http://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
development:
<<: *default
database: database_name
When i restarted my server i get error
could not connect to server: Connection timed out (0x0000274C/10060) Is the server running on host "xxx.xxx.xxx.xx" and accepting TCP/IP connections on port 5432?
am i doing the right procedure? can anyone get me through this?

Related

Deploying a Rails 5 app to EC2- RDS DB Instance connectivity error

I have created DB instance and gone through the config process of aws rds instance as per the documentation.
created an instance of db successfully.
also changed the connection params in database.yml accordingly.
I ran the following commands in ngnix server installed on ubuntu 16.04 at aws and also rebooted the db instance several times.
RAILS_ENV=production rake db:create
and db created successfully
and then ran
RAILS_ENV=production rake db:migrate
and database migrated successfully.
an then ran the command
sudo service nginx restart
after all of the process
when I am visiting my app its says
PG::ConnectionBad
could not connect to server: Connection refused Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP
connections on port 5432?
here is my database.yml
development:
host: localhost
database: ups_developement_db
adapter: postgresql
encoding: unicode
port: 5432
username: postgres
password: postgres
production:
host: dbcustom.cjocvmnblsa4.us-east-2.rds.amazonaws.com
database: ups_db
adapter: postgresql
encoding: unicode
port: 5432
username: dbmasteruser
password: dbmasterPassword
I am open to provide any kind of information required.
Thanks a lot for your time and solution in advance
It's almost certain that you have not configured the security groups on the RDS instance correctly.
Log into your EC2 and issue the command
telnet <rds hostname> 5432
You should see something like
Trying 10.1.1.2...
Connected to 10.1.1.2.
Escape character is '^]'.
which means that TCP can flow between your EC2 and your RDS.
If not, you need to permit your EC2 to connect to your RDS instance by adding the correct security group configuration.
You should create Environment variables in your AWS RDS instance you should use them in your rails app config file. Check here
database.yml should look like this
production:
adapter: mysql2
encoding: utf8
database: <%= ENV['RDS_DB_NAME'] %>
username: <%= ENV['RDS_USERNAME'] %>
password: <%= ENV['RDS_PASSWORD'] %>
host: <%= ENV['RDS_HOSTNAME'] %>
port: <%= ENV['RDS_PORT'] %>

"could not save history to file "/Library/PostgreSQL/9.6/.psql_history": No such file or directory"

I am building a Rails project with Devise and Postgres.
When trying to migrate, I get this error message:
PG::ConnectionBad: FATAL: password authentication failed for user "kala.wetzler".
I have tried this process a few times: https://www.cyberciti.biz/faq/howto-add-postgresql-user-account/ & after what seems like a success (no error messages) & I \q out, I get this message:
could not save history to file "/Library/PostgreSQL/9.6/.psql_history": No such file or directory.
After this, if I try to migrate again I see that it does not recognize my password (as seen in the first error message listed in this post). Is it not working because of this lack of a file to save to or is that just telling me that this process of assigning a user to the database is not being logged? If it is because of a lack of the file to save to, how do I make sure that file gets created?
My config/database.yml:
default: &default
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
host: localhost
username: kala.wetzler
password: <%= ENV['LIT_DATABASE_PASSWORD'] %>
development:
<<: *default
database: lit_development
test:
<<: *default
database: lit_test
production:
<<: *default
database: lit_production
username: kala.wetzler
password: <%= ENV['LIT_DATABASE_PASSWORD'] %>
& then in my .env file I have LIT_DATABASE_PASSWORD assigned.
My pg_hba.conf:
TYPE DATABASE USER ADDRESS METHOD
"local" is for Unix domain socket connections only
local all all trust
IPv4 local connections:
host all all 127.0.0.1/32 trust
IPv6 local connections:
host all all ::1/128 trust
Allow replication connections from localhost, by a user with the replication privilege.
local replication kala.wetzler trust
host replication kala.wetzler 127.0.0.1/32 trust
host replication kala.wetzler ::1/128 trust

PostgreSQL: could not connect to server: Connection timed out

I've been trying to make the switch to PostgreSQL (from SQLite). I'm developing in the environment of Cloud9. However, on db migration I get the error message:
PG::ConnectionBad: could not connect to server: Connection timed out.
Is the server running on host "mydomain.c9.io" (IP address) and
accepting TCP/IP connections on port 5432?
I've been reading all sorts of previously asked questions on this topic but without success. Does anyone see what might be going wrong?
Do I perhaps need to makes change to the pg_hba.conf file? The current version of the file:
# Database administrative login by Unix domain socket
local all postgres peer
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all xxx.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres peer
#host replication postgres xxx.0.0.1/32 md5
#host replication postgres ::1/128 md5
database.yml:
default: &default
adapter: postgresql
encoding: unicode
host: 'mydomain.c9.io'
pool: 5
username: my_username
password: my_password
development:
<<: *default
database: app_development
test:
<<: *default
database: app_test
production:
<<: *default
database: app_production
I have gem 'pg' in the Gemfile and have run bundle install. Also, I have created the database app_development (used sudo service postgresql start, sudo sudo -u postgres psql and then create database "app_development";) as well as the database app_test. And lastly, I created a new user in psql with CREATE USER my_username SUPERUSER PASSWORD 'my_password';.
Using sudo nano /etc/postgresql/9.3/main/postgresql.conf I also set listen_addresses = '*' but that made no difference.
What might be causing the error message?
Are you sure that your cloud 9's has postgres port(5432) open for access? I assume the cloud 9 host is not listening on port 5432. You can check out this link for detais
http://www.cyberciti.biz/tips/postgres-allow-remote-access-tcp-connection.html

Postgres database has no password - can't get into pgadmin

I have a rails app using postgres. When I made the app, I never created a password. In my database.yml file, no password is listed. My application works, but I am trying to connect to the db using pg_admin so I can see the tables. When I try to connect, I am given the following:
Server doesn't listen
The server doesn't accept connections: the connection library reports
could not connect to server: Connection refused Is the server running on host
"localhost" (::1) and accepting TCP/IP connections on port 3000?
How can i fix this? If it helps, here is the code from my database.yml file for development:
development:
adapter: postgresql
encoding: unicode
database: supersmart_dev
pool: 5
username: postgres
host: localhost

rake db:create:all FATAL : password authentication failed

I am trying to follow this railscast tutorial. Now I am in the step, where you create the database with rake db:create:all, but I got this error message :
FATAL: password authentication failed for user aldila
I made the user aldila through pgAdmin, by right-clicking the login role and add user aldila with password.
So, here is my database.yml :
development:
adapter: postgresql
host: localhost
encoding: unicode
database: my_app_development
pool: 5
username: aldila
password: *mypass*
test:
adapter: postgresql
host: localhost
encoding: unicode
database: my_app_test
pool: 5
username: aldila
password: *mypass*
production:
adapter: postgresql
host: localhost
encoding: unicode
database: my_app_production
pool: 5
username: aldila
password: *mypass*
Here is my pg_hba.conf
# TYPE DATABASE USER ADDRESS METHOD
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#host replication postgres 127.0.0.1/32 md5
#host replication postgres ::1/128 md5
Maybe there is something's wrong with the installing of PostreSQL, because if I type
psql --version on my command, this is what I got :
'psql' is not recognized as an internal or external command,
operable program or batch file.
But I have no idea what went wrong. I install it from here and pick download the installer from EnterpriseDB for all supported versions.
I know there are already similar questions like this, but I follow this one and this one, but I still get the same error message. I would be really appreciated, if anyone could help. Thanks
Your postgresSQL password didn't match your database.rb's password.. it depends on what environment you are using..

Resources