Converting Rails app from sqlite3 to postgresql

rails
sqlite
ruby

#1

Hi, I"m following the C9 instructions to get postgres installed on my rails app instead of sqlite3 and it isn’t working.

https://community.c9.io/t/setting-up-postgresql

I’ve gotten all the way down to here:
sudo sudo -u postgres psql
postgres-# \password postgres
Enter new password:

Then you can connect with username “postgres” and the password you set. Here’s an example in PHP:
PHP

<?php $link = pg_connect("host=localhost dbname=groceries user=postgres password=cloud9isawesome"); ?>

But that’s it. Nothing for rails and I can’t get this conversion done. In my rails app, I get this PG::ConnectionBad: FATAL:
or this:
FATAL: Peer authentication failed for user “username”

I’ve tried documentation from two other sources and am getting nowhere. Please update your documentation for ruby on rails specifically or provide instructions here.

I’ve also tried this: https://github.com/Aerogami/guides/wiki/Cloud9-workspace-setup-with-Rails-and-Postgresql and it has failed as well.


#2

here is my database.yml file contents:

default: &default
adapter: postgresql
encoding: unicode
pool: 5
username: username
password: password

development:
<<: *default
database: app_development

test:
<<: *default
database: app_test

production:
<<: *default
database: app_production


#3

If I remember correctly, you need to create a new Postgres user called ubuntu as a Superuser and use that in your application.

Edit: Take a look at this guide and see if it helps:


#4

I figured it out late last night working and reviewing 5 or so different sites for configuring and adding ubuntu as the postgres superuser and making it the database owner.

So instead of trying to bookmark the various sites that do it a certain way, I wrote this up today: Converting A Cloud9 Rails App from Sqlite3 to Postgresql


#5

Hey,

However another issue came up, I was following Converting Rails App by @JohnnyBurst which helped… Thanks @JohnnyBurst by the way.

When I get to run rake db: create the following error comes up…

DEPRECATION WARNING: Passing a string to ActiveRecord::Base.establish_connection for a configuration lookup is deprecated, please pass a symbol (:postgresql) instead. (called from mon_synchronize at /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/monitor.rb:214)
rake aborted!
ActiveRecord::AdapterNotSpecified: ‘postgresql’ database is not configured.

Why is this coming up?..

By the way, I copied verbatim, what @JohnnyBurst had… I configured the database.yml as well as the pg gem…

Thanks,
Bryan G


#6

Hello. I am getting the same error as Bryan G.

Any suggestions?


#7

Hi. I found an article on Stack Overflow that basically indicated that the indentation syntax of the database.yml file must be followed for this to work. I changed the indentation format, and it worked!