I am new to Phoenix and actually working on my first project in it.
When deploying the project on production server, I am getting a Database Connection error for mySql. For some reason, it is not considering the username/password values provided in config/prod.exs
import Config
config :g_plus, GPlusWeb.Repo,
username: "root",
password: "Somepassword",
database: "db_name",
hostname: "localhost",
load_from_system_env: true,
pool_size: 20
I also tried with environment variable (DATABSE_URL), but it is still not working.
ecto://root:Somepassword#localhost:3306/db_name
Am I missing any setting/config somewhere?
I couldn't find anything in Google search as well.
Most deployment guides are for apps without DB.
I found the issue. I was using GPlusWeb instead of just GPlus in the following line.
config :g_plus, GPlusWeb.Repo,
I changed it to config :g_plus, GPlus.Repo, and it worked.
Related
I want to connect my laravel 5.7 application(I used the 3.4 version of jenssegers/mongodb) with a mongodb in atlas, I tried in localhost(I isntalled the mongo extension) and everything is ok but with atlas i got an error message:
Failed to parse MongoDB URI:
'mongodb://root%3Acluster0.xxx.mongodb.net%3A27017%2Fhddatabase%3FretryWrites%3Dtrue%26w%3Dmajority'.
Invalid host string in URI.
My env file:
DB_CONNECTION=mongodb
DB_DSN="mongodb://root:password#cluster0.xxx.mongodb.net:27017/hddatabase?retryWrites=true&w=majority"
DB_DATABASE=hddatabase
My database config:
'mongodb' => [
'driver' => 'mongodb',
'dsn' => env('DB_DSN'),
'database' => env('DB_DATABASE'),
],
TL;DR: The url is wrong. "+srv" part is missing.
Please copy the url from the Atlas Connection Wizard:
You can open the connection from the Cluster View:
Details
Atlas provides a replica set cluster of 3 mongo db instances by default. Your local database is standalone.
There are 2 formats to connect to mongodb:
mongodb:// is the legacy one that requires all members of the replica set to be explicitly present in the url. E.g.: mongodb://<username>:<password>#cluster0-shard-00-00.xxx.mongodb.net:27017,cluster0-shard-00-01.xxx.mongodb.net:27017,cluster0-shard-00-02.xxx.mongodb.net:27017/<dbname>?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin&retryWrites=true&w=majority
mongodb+srv:// is the "srv" format which lets the driver to retrieve replica set configuration from mongodb itself, so the url is much simpler: mongodb+srv://<username>:<password>#cluster0.xxx.mongodb.net/<dbname>?retryWrites=true&w=majority
You are using the later format and the legacy schema so the driver complains.
As a side note it is advisable to use configuration options username and password as documented in https://github.com/jenssegers/laravel-mongodb#configuration rather than pass them in the url. URL format requires special characters like #, /, etc in the password to be escaped, which unnecessarily complicates credentials management.
Try with this DNS maybe :
mongodb://root:password#cluster0.xxx.mongodb.net:27017
Even with the 'srv' format I'm getting the same error, The problem is that I'm using the version 3.4.0 of jenssegers/mongodb, I upgraded to version 3.4.6 and used the 'srv' format and problem is solved now !
I have a mongo 3.4 instance with a cfg file thus:
systemLog:
destination: file
path: D:\Mongo\log\mongod.log
storage:
dbPath: D:\Mongo\db
Using robomongo version 0.9.0 I've added a user:
Now when I try and connect to the DB I get an error:
I've checked passwords etc all seems correct:
Without using auth all works as expected.
I've ran though a similar issue Mongodb & Robomongo: Can't connect (authentication) but because I have a newer version of the client (0.9) which supports SCRAM-SHA-1 this should work.
What am I missing here?
Looks like there's a bug in robobmongo. If I add the user using the console:
db.createUser({user:"mongoUser", pwd:"***", roles:["userAdminAnyDatabase"]})
Authentication works. But I now get an error from robomongo:
when I try and expand the list of users in admin.
I am trying to get a site set up on Heroku using Sinatra and PostgreSQL. It worked locally (connecting to local database), but after pushing it to Heroku and changing my PG.connect to reflect that, I get an Internal Server Error the moment a page tries to access the database.
require 'uri'
require 'pg'
uri = URI.parse(ENV['DATABASE_URL'])
def db(uri)
begin
connection = PG.connect(uri.hostname, uri.port, nil, nil, uri.path[1..-1], uri.user, uri.password)
yield(connection)
ensure
connection.close
end
end
I am pretty sure these are parsing correctly, because ENV['DATABASE_URL'] displays the full postgres://user:password#host:port/database information that I'm expecting, and if I do the same in IRB uri.hostname, ui.port, etc all return what's expected .
This is my first time trying to get a site working on Heroku, so I am not even sure how to troubleshoot this. (And I googled for about all of yesterday.)
Results for heroku pg:
=== DATABASE_URL
Plan: Hobby-dev
Status: Available
Connections: 0/20
PG Version: 9.4.2
Created: 2015-05-30 19:24 UTC
Data Size: 17.7 MB
Tables: 5
Rows: 9320/10000 (In compliance, close to row limit)
Fork/Follow: Unsupported
Rollback: Unsupported
And all the tables show up when when I do heroku pg:psql <database> from the cli.
Some answers I've seen said to add database.yml to my root app directory, so:
production:
adapter: 'postgresql'
database: '<database>'
host: ENV['DATABASE_URL']
username: '<username>'
There's probably something simple I'm missing, but I haven't seen a complete guide for Sinatra/PSQL on Heroku - nothing that goes specifically into setting up and connecting to your database. (Everything seems Rails-related.)
In your database.yml file you need to specify the correct host for the host entry. You are passing what is stored in DATABASE_URL (something like postgres://user:password#host:port/database) but it should just be the host.
You will also need to specify a port if it isn't the default for PostgreSQL.
Edit: should also point out if you plan to store the host (or anything else - you definitely should for username and password) in an environment variable you'll need to wrap it, e.g. <%= ENV['HOST'] %>, not just ENV['HOST'] (i.e. how you have in the database.yml excerpt above)
We're using dropwizard 0.7.1 which comes with jetty 9.0.7 and the jersey http client 1.18.1 (yes, it's old...). The os is linux, we're using Java 1.8.
I'm running an integration test locally inside eclipse, which makes a rest call using jersey to a dropwizard application running inside a vagrant box.
One of the tests should verify if I can send non-latin characters to the server.
I'm sending the string "Владимир Արման" inside a String field of a POJO using jersey:
req.type(MediaType.APPLICATION_JSON + "; charset=utf-8")//
.post(ClientResponse.class, user);
The resource I'm sending this too looks like this:
#Path("/users")
#Produces(MediaType.APPLICATION_JSON + "; charset=utf-8")
#Consumes(MediaType.APPLICATION_JSON + "; charset=utf-8")
public class UserServiceResource{
[...]
#POST
public Response createUser(UserCreate user) {...}
(you see we're both on the client and on the server side enforcing the utf-8 charset, which in my opinion, should actually not be necessary?)
This works perfectly locally, the name arrives correctly.
On jenkins, however, this does not work, I only receive "??????" in the service instead of the correct characters. In the log of the client that posts the pojo I still see the correct characters.
The setup is quite similar: jenkins builds a vagrant box, and then runs the tests using maven against this box (the integration test code runs outside the vagrant box, the service runs inside vagrant).
Jenkins uses maven, but when running the integration test locally using maven, it still works fine.
The vagrant box I'm using locally is also build and provisioned by jenkins, in a different job.
We are now trying to investigate if the environment settings might be slightly different, already tried setting
LANG=en_US.UTF-8
LC_ALL=en_US.UTF-8
MAVEN_OPTS="-Dfile.encoding=UTF-8"
but that didn't help.
What mainly puzzles me is that I would expect to work this under any environment settings, as we explicitly enforce UTF-8.
Are there know issues how the environment overrides the encodings set in the client and the server?
This problem just ate my soul. The root issue ended up being with the JDBC configuration. Originally my config looked like this:
database:
driverClass: com.mysql.jdbc.Driver
user: ...
password: ...
url: jdbc:mysql://...
properties:
charSet: UTF-8
hibernate.dialect: org.hibernate.dialect.MySQL5InnoDBDialect
maxWaitForConnection: 1s
validationQuery: "/* DropWizard Health Check */ SELECT 1"
minSize: 5
maxSize: 25
checkConnectionWhileIdle: false
checkConnectionOnBorrow: true
The solution was to update the properties block to define a characterEncoding and useUnicode property. Like this:
properties:
charSet: UTF-8
characterEncoding: UTF-8
useUnicode: true
hibernate.dialect: org.hibernate.dialect.MySQL5InnoDBDialect
Updating my YAML config, in addition to adding a charset parameter to the Content-Type header, fixed the issue for me.
Current System: Windows XP / Windows 7 (problem occuring for both)
After following the guidelines for deployment from the following:
https://devcenter.heroku.com/articles/python
and by testing by using a simple poll application I am successfully able to push the application through heorku except that after checking the logs the following error appears:
2012-04-27T08:14:42+00:00 app[web.1]: django.core.exceptions.ImproperlyConfigure
d: Error loading either pysqlite2 or sqlite3 modules (tried in that order): No m
odule named _sqlite3
This also occurs when attempting to sync the database.
Here is the current configuration of the database in the settings.py file:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'database.sqlite', # Or path to database file if using sqlite3.
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
I am aware is it a sqlite3 database, and I have been told that it should still allow heroku to deploy the app without any errors.
I have followed through using the following potential solutions that are related to this problem:
No module named _sqlite3
How do I set up SQLite with a Django project?
http://groups.google.com/group/django-users/browse_thread/thread/185f981f432346f1
Any help will be appreciated! Please let me know if additional Information is needed.
Heroku does not support sqlite, since it only provides a read-only filesystem.
I had the same error with the settings file. Looking through the Heroku logs, it turned out that my settings.py file was failing for various reasons. Once I fixed those issues, Django stopped complaining about missing database settings.
One of the things that caused this issue was a monkey patch I was using to allow sub-selects as tables in QuerySet extra(). This patch is at the end of my settings file.
# Override default behaviour of compiler to quote table names when table name is a sub-query
from django.db.models.sql.compiler import SQLCompiler
_quote_name_unless_alias = SQLCompiler.quote_name_unless_alias
SQLCompiler.quote_name_unless_alias = lambda self,name: name if name.startswith('(') else _quote_name_unless_alias(self,name)
This patch apparently requires that DATABASES already be correctly specified at that point. Since Heroku appends the magic DATABASES configuration to the end of the settings file (i.e. after the monkey patch), I had to manually insert their configuration above my monkey patch.