Setting the connection pool (and other database options) using Heroku - ruby-on-rails

From this page, it looks like Heroku does most of the work in building your database.yml file on deployment, meaning that all I have to have is my development and test environment configurations.
Is there a way I can also specify production values? For example, if I wanted to set pool: 25 on production, can I include that in my database.yml as follows?
development: &default
adapter: postgresql
database: my_app_development
encoding: utf8
host: localhost
min_messages: warning
pool: 2
timeout: 5000
test:
<<: *default
database: my_app_test
-- Can I add this, or will it get overwritten?
production:
<<: *default
pool: 25

Actually, found the answer to exactly my question on the Heroku documentation
https://devcenter.heroku.com/changelog-items/426
Looks like whatever options you set will be merged in and preserved, so I can indeed set connection pool in my database.yml

Related

For pushing a rails app to Heroku, what is the correct way to configure my databases in config/database.yml?

I'm trying to push my Rails app to Heroku and running into difficulty.
In the config/database.yml file I've seen examples like this, where the database name is prefixed with 'db/':
production:
<<: *default
database: db/the_business_casual_pro
As well as examples like this, without the prefix:
development:
<<: *default
database: FullstackProject_development
Is one way preferred over the other, or is one an older way of doing it?
Right now my database.yml file is just this:
default: &default
adapter: postgresql
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
development:
<<: *default
database: db/the_business_casual_dev
test:
<<: *default
database: db/the_business_casual_test
production:
<<: *default
database: db/the_business_casual_pro
I've seen the code below in a previous project but am unsure what I'd need to do first to add these lines.
production:
<<: *default
database: FullstackProject_production
username: FullstackProject
password: <%= ENV['FULLSTACKPROJECT_DATABASE_PASSWORD'] %>
Any insights very much appreciated!
Usually when you locally develop a Rails application you're not using a Postgres instance for development, but a SQLite database. Rails stores these databases in a folder called db. You can actually check the db for your project if there are any files in it.
With Heroku, you're using a Postgres instance and you're defining the database in another way.
So I would keep the db/ for development (including the SQLite adapter) and for production you probably want to use ENV["DATABASE_URL"] as Heroku suggests it.

Changing database names from SQlite3 to Postgres

I am currently trying to switch from SQlite3 to Postgres, and was wondering how I can change my database name? According to Heroku, they say this:
Note the adapter name is postgresql not postgres or pg. You will also
need to change the database: to a custom name. A final version might
look something like this:
development:
adapter: postgresql
database: my_database_development
pool: 5
timeout: 5000
test:
adapter: postgresql
database: my_database_test
pool: 5
timeout: 5000
production:
adapter: postgresql
database: my_database_production
pool: 5
timeout: 5000
I see right now that I have the following for my database name for test environment:
test:
<<: *default
database: db/test.sqlite3
For this (and dev and production environments) do I need to simply change the name of the database, or do I need to do something more than this. Because for the SQLite3 files, it has a .sqlite3 extension. Does postgres have a similar situation?
Yes, you can just change the database name for each additional environment.
The
<<: *default
means that is the part of the configuration that will be used in the other environments, so you don't have to duplicate your code (DRY).
For postgres you don't have to give extensions (as I remember).
Just give the databases clear names, and that should work.

Can I easily and safely reset Rails database to Postgres from SQlite after building the app?

I'm a beginner in Rails and I'm curious whether I'm better off setting the database to Postgres from the beginning or I can just use SQLite and forget about it until later. And if setting it in the beginning is better, should I simply follow the 3.12 in http://guides.rubyonrails.org/configuring.html#configuring-a-database or are there more things to be done? It seems like I need to do more but it's not really clear. For example, other than adapter, which the instruction says to change, there are more code with SQLite built-in and I'm not sure whether I need to do anything to them as well:
default: &default
adapter: postgresql
pool: 5
timeout: 5000
development:
<<: *default
database: db/development.sqlite3
test:
<<: *default
database: db/test.sqlite3
production:
<<: *default
database: db/production.sqlite3
If you intend to use Postgres than it makes sense to setup the application to use it from the get go.
While it is possible migrate data from SQLite to Postgres and vice-versa you would be better off not having to deal with the potential issues that can occur.
In general you want to develop and test on the same database system you are deploying to as they have different features and subtile differences in how they interpret the SQL standards. You don't want to find them out by pushing to the production server and then getting a very angry phone call.
This can definitely can bite you in the *rse when deploying to Postgres as it is rather strict (its a good thing).
A decent config would be:
default: &default
adapter: postgresql
pool: 5
timeout: 5000
development:
<<: *default
database: my_app_dev
test:
<<: *default
database: my_app_test
production:
<<: *default
database: my_app_production
Note that on Heroku and other Platform-as-a-Service (PaaS) services you can simply leave out the production section as it will be overwritten in a post commit hook.
See also:
http://12factor.net/dev-prod-parity
You can install the Postgresql gem using either:
gem install pg in your terminal
or
gem 'pg' in your Gemfile.
Then you just need to go into config/database.yml and set up something similar to this:
development:
adapter: postgresql
encoding: unicode
database: myapp_development
pool: 5
test:
adapter: postgresql
encoding: unicode
database: myapp_test
pool: 5
From there, just run your migrations, and you should be all set up!

Is it possible to configure (Thinking) Sphinx on a separate database from the Rails app?

Is it possible to have my app use (in development mode) a SQLite3 adapter, while Sphinx uses Postgres?
I tried to do it by adding the file config/thinking_sphinx.yml below, but I get an error message telling me that SQLite3 is not supported. My config/database.yml has SQLite3 in development, of course.
default: &default
encoding: utf8
host: localhost
adapter: postgresql
port: 5432
pool: 5
timeout: 5000
development:
<<: *default
database: ts_development
test:
<<: *default
database: ts_test
production:
<<: *default
database: ts_production
If you want to use Sphinx, then you need to use either PostgreSQL or MySQL for that environment. So, technically yes, you can use SQLite in development, that will mean you can't use Sphinx or Thinking Sphinx in development, which is I think is a very bad move: I would recommend using the same database in all environments generally (whether or not Sphinx is involved), and especially so in this case, otherwise you won't be able to do anything search-related in your development environment.

Issue with Postgresql `initialize` ... Socket .s.PGSQL.5432

There have been a few post on this issue, unfortunately none of the solutions have worked for me.
My suspicion is that my postgresql is either not running or not configured correctly.
Here is where I am at, I have a development project I have joined, they are using postgresql. Here are the step I have take to get here:
Cloned Repo
Changed name of config/ database.yml.sample -> database.yml
Changed name of config/ s3.yml.sample -> s3.yml
Ran bundle install
Ran Rake db:migrate
resulting in this error:
rake aborted!
could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
Here is what my files currently look like:
Database.yml
development:
adapter: postgresql
encoding: unicode
database: rentsnapper_development
pool: 5
username: user
password:
test: &test
adapter: postgresql
encoding: unicode
database: rentsnapper_test
pool: 5
username: user
password:
cucumber:
<<: *test
And My s3.yml
defaults: &defaults
access_key_id:
secret_access_key:
development:
<<: *defaults
photos_bucket: rentsnapper-photos-development
Solutions Tried:
https://stackoverflow.com/a/14887090/2066855
No File listed
https://stackoverflow.com/a/14225289/2066855
No Change, when I run rake db:migrate I get the same error
https://stackoverflow.com/a/15788389/2066855
Nothing happened
Also as a side question that may or may not be relevant linux is telling me that "ruby-1.9.3-p385 is not installed", I'm running ruby-1.9.3-p362, I suspect this is unrelated. Is this something I need to update or can I get by with my current version.
Thank you in advanced...
SOLVED: I had to fix my database.yml file. Added "host: localhost" took out user & password lines.
development:
adapter: postgresql
encoding: unicode
database: rentsnapper_development
pool: 5
host: localhost
test: &test
adapter: postgresql
encoding: unicode
database: rentsnapper_test
pool: 5
host: localhost
cucumber:
<<: *test

Resources