Everything when I start a new Ruby on Rails project on a new machine I am running into issues getting everything to work with Postgresql. This is not a Postgresql issue, but simply a memory problem. I don’t do this that often, so I simply forget. This has lead me to write this blog, because it will be my ‘extended memory’ next time I need it.
This blogpost was written while using the following tools:
- Postgresql 9.3 configured on localhost on port 5432
- Ruby 2.0.0-p0
- Rails 3.2.13 (nope… not the latest)
- RubyMine 6
The purpose of this blogpost is to give you a workflow that will help you do the least amount of work to get your new Rails app working with Postgresql. My assumption is that you have installed Postgresql and are sure it is properly running. I use pgAdmin to check that.
Step 1 – First create a new role in Login Roles. In this example we’ll call the role TestProject.
Step 2 – In the tab Role privileges check Can create database
Step 3 – Create a new Ruby on Rails project in RubyMine. This step will also run rake and try to create databases. This will fail for three reasons:
By default RubyMine does not have the Postgresql driver installed. You’ll need to do that manually using the database menus in RubyMine. Later more about that.
Postgresql allows you to create new roles without setting a password, but this is misleading, because it won’t allow connections without a password login. You have to set a password in the Definition tab. Warning: once you do that the Account expires field will be set to the current date. As a result of that you may still not be able to use the new role. Make sure to set the date to a future date.
You may receive this error:
could not connect to server: Permission denied
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
Using Google Search you’ll find suggestions that require messing around with file system soft links or moving files. Don’t do that! That won’t be necessary. Just add host: localhost to each database configuration in database.yml and that will do the job. Your configuration should now look something like depicted below.
Step 4 – Run rake db:setup followed by rake db:migrate. This will create both your development database and your test database. This will leave the production database untouched for obvious reasons.
You are now set to go and start developing your application and use the regular database migration steps from Rails.