How do I connect to a postgres database with Sequel? How do I connect to a postgres database with Sequel? sqlite sqlite

How do I connect to a postgres database with Sequel?


The database mydatabase.db doesn't exist, as per the error message from Pg. Likely reasons:

  • You probably meant mydatabase without the SQLite-specific .db filename suffix
  • It's possible you created the db with different case, eg "Mydatabase.db";
  • You might be connecting to a different Pg server than you think you are
  • You never created the database. Unlke SQLite's default behaviour, Pg doesn't create databases when you try to connect to a database that doesn't exist yet.

If in doubt, connect to Pg with psql and run \l to list databases, or connect via PgAdmin-III.

The PostgreSQL documentation and tutorial are highly recommended, too. They're well written and will teach you a lot about SQL in general as well as Pg in particular.

BTW, the postgres user is a superuser. You should not be using it for your application; it's like running your server as root, ie a really bad idea. Create a new PostgreSQL user without superuser, createdb or createuser rights and use that for your application. You can either CREATE DATABASE somedb WITH OWNER myappuser - or preferably, create the database owned by a different user to your webapp user and then expicitly GRANT the webapp user the minimum required permissions. See user management and GRANT.


On heroku all you need to do is tell Sequel to connect to the content of the DATABASE_URL environment variable (which is a properly formed url that Sequel understands):

DB = Sequel.connect(ENV['DATABASE_URL'])