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?

1

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.