JRuby: JNDI vs JDBCMYSQL - ruby-on-rails

Not sure if these two can be compared, to bear with me. But what is the advantage (in a JRuby application) to run a configuration that's similar to:
production:
adapter: jdbc
encoding: utf8
jndi: java:comp/env/app
pool: 200
versus:
production:
adapter: jdbcmysql
encoding: utf8
database: tgc
#socket: /var/lib/mysql/mysql.sock
host: localhost
port: 3306
username: mysql
password: notarealpassword
Is one more flexible than the other? Can I better tune with JNDI? The reason I ask is because my Resque workers cannot access the DB when I use the JNDI version above. I have to use the latter configuration for things to work properly.

JNDI abstracts DB configuration into the app server. Benefits include being able to deploy the same app across servers utilizing different DBs and/or DB characteristics without changing the application itself.
It's often more a matter of policy/administration than anything else--keeping DB stuff isolated in this way gives more flexibility on the administrative side of things; things can be re-jiggered without the app (necessarily) being aware. (It doesn't always work like that in real life, naturally.) If the people managing the DBs/servers aren't the same people writing/deploying the app, JNDI can be very helpful.
That abstraction is manageable in other ways--Rails uses the DB config file, Spring might use server-specific config files, system properties, whatever. The differences are less technical, more managerial.

Related

Rails & TinyTDS - connecting to local database

On our Ruby on Rails applications, we use tinytds to connect to Azure SqlServer databases. Sample configuration would be as below (and in general, it all works fine)
development:
adapter: sqlserver
host: mytestsite.database.windows.net
mode: DBLIB
port: 1433
database: mytestdb
username: myusername
password: mypassword
azure: true
At the moment, working remotely, I find this very slow. So I would like to take a local copy (as I would do with my .Net applications) and attach to that.
Finding connecting to (localdb)\MSSQLLocalDB a problem with tinyTDS.
Would anyone have done this before?

Rails trying to connect to postgresql on port 5432, but it's configured for 5433

I am attempting to get rails running in an ubuntu subsystem on Windows 10.
I have installed everything needed, but rails is unable to access postgres.
In both /etc/postgresql/9.5/main/postgresql.conf and the rails config/database.yml, I have port: 5433 instead of 5432. See [1] below for why I'm using 5433.
When trying to do a database operation through rails (e.g. rails db:setup), I get this:
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"?
database.yml:
default: &default
adapter: postgresql
encoding: unicode
pool: 5
development:
<<: *default
database: some_database
username: 'postgres'
password: 'postgres'
I cannot figure out how to make rails try to start postgres on port 5433... I'm also not sure if there is a better way to solve the issue here.
Thanks for your time.
Further details:
[1] I am using port 5433 simply because I've been unable to figure out a way to make it use 5432. I have removed all postgres libraries and made sure to reinstall one using a specified version number, but it defaults to port 5433. When changing the port to 5432 in the config, starting it yields the error that some other process is using it, but netstat, lsof, and ps aux disagree. Not sure what else to do there.
For me, I believe this issue was somehow caused by something being cached by spring or some other service. After doing the following, the problem was resolved, though I'm not sure what all was required.
Killing all spring processes
restarting the machine
deleting and re-creating database.yml
changes the port from 5433 to 9854 (basically just anything else)
changing database user and name

Is it possible to run rails app from a remote database?

I have been searching for a solution couple of days and done with nothing.
Is it really impossible to run rails app from a remote database?
My case:
I have a database located on one of my offices as a local server.
I need my rails app(hosted on some hosting service) to connect and run from this private database on this private server.
Is there really a solution or workaround?
And not related to rails but is it possible with django framework. just out of curiosity.
Thank you all very much for the answers!
You can set host in your databasey.yml like:
production:
adapter: postgresql
encoding: utf8
database: prod_db
username: prod_user
password: prod_pwd
host: 10.10.10.10
port: 5432
pool: 3
But you should have static ip or you can create VPN between two servers

Rails Oracle enhanced adapter ignores pool size

I use 3 thin servers (behind an Nginx proxy) for my productive Rails app. Each of the thin servers produces 5 connections to the database. So my app has 15 connections in total. My Oracle admin complains that I use too many connections.
I do not know how to reduce the number of connections. I tried pool: 2 in database.yml, and restarted all thin servers, but my app still produces 15 connections. It seems that the pool setting is not used at all.
Of course, I could reduce the number of thin server, but I would like to know how to use pool.
I have another Rails app using PostgreSQL. Here, this parameter works as expected.
I use Rails 4.1 and Ruby 2.1
production:
adapter: oracle_enhanced
database: "(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=xxx)(PORT=12345)))(CONNECT_DATA=(SID=yyy)))"
pool: 2
username: ORACLE_USER
password: ORACLE_PASSWORD
I'd suggest you to open issue at https://github.com/rsim/oracle-enhanced - the maintainers check that more often.
After a reboot of the database server, everything works as expected ...

Configure a remote sqlite3 database on rails

I programmed an application using rails and I can deploy it on a single machine. It uses a sqlite3 database that is created in the local machine.
Now I need to put that db on another machine, but I have no idea how. I installed a rails environment on the other machine and sqlite3. I configured the database.yml file this way:
development:
adapter: sqlite3
database: db/development.sqlite3
host: 172.**.**.**
pool: 5
timeout: 10000
username: username
password: password
However nothing happens. Do I need to configure something on the other machine? Am I missing something? Sorry if I seem ignorant, is the first time I do something like this.
Out of the box, no, you cannot, and it's actually discouraged in SQLite own manual:
If you have many client programs accessing a common database over a
network, you should consider using a client/server database engine
instead of SQLite.
You can take a look at various solutions built around SQLite to solve this problem here.
However, a much better solution would be to switch to another RDBMS such as MySQL or Postgresql. It should not impact your app much (as ActiveRecord does a nice job of isolating you of the DB specific instruction).

Resources