4

So I started working on a Rails app recently and we decided (well not me, the person working on it with me) that we should switch from Sqlite3 to Postgresql. I've installed Postgresql on our server properly, created the databases for dev, prod, and test, and updated my Gemfile and database.yml files with the code for Postgres. The thing I'm unsure of now, is how to switch out all the files in the db directory with the Postgres databases. Do I just delete the contents of the db directory in my app and run rake db:create?

Jake Stevens
  • 157
  • 4
  • 13
  • See: http://stackoverflow.com/questions/6710654/change-from-sqlite-to-postgresql-in-a-fresh-rails-project – tgrrr Aug 22 '15 at 01:25

1 Answers1

4

You'll want to edit config/database.yml to use postgresql instead of sqlite.

The migrations in db/migrate/*.rb are hopefully cross-database compatible, and wont need to be changed.

Running rake db:create db:migrate with the new database.yml should create the PostgreSQL database and you'll be up and running.

In reality, you'll probably run into various problems, but this will be a starting point.

Paul Annesley
  • 3,387
  • 22
  • 23
  • 1
    Note that unlike SQLite, the PostgreSQL data will live in the PostgreSQL database server itself, not in a file within your Rails project. You may or may not delete the sqlite files; it shouldn't matter once `database.yml` is using postgres instead. – Paul Annesley Jun 05 '13 at 05:04
  • Also note that PostgreSQL is much more secure so you might need to create the USER and DATABASE on the server and skip the db:create. And if you have problems connecting to it try looking at bottom of the /etc/postgresql/9.1/main/pg_hba.conf file. the `trust` METHOD is what I'm using. – complistic Jun 05 '13 at 05:17