Ruby on Rails: How can I edit database.yml for postgresql?

63,594

Solution 1

Simply:

development:
  adapter: postgresql
  encoding: unicode
  database: blog_development
  pool: 5
  username: blog
  password:
  host: localhost

Source: Configuring Rails Applications

Solution 2

development:
  adapter: postgresql
  encoding: utf8
  database: name
  username: hading
  password: my_db_password
  pool: 5 # not mandatory
  timeout: 5000 # not mandatory
  host: localhost
  port: your postgresql port number (5432 or 5433)

Solution 3

As Zabba said it's

development:
  adapter: postgresql
  encoding: unicode
  database: blog_development
  pool: 5
  username: blog
  password:

As mentioned in the Configuring Rails Applications. But you might want an additional min_messages: WARNING, to get rid of the nasty NOTICE messages postgresql gives you during a migration. So my database.yml entry looks like this

development:
  adapter: postgresql
  encoding: unicode
  database: blog_development
  pool: 5
  username: blog
  password:
  min_messages: WARNING

Solution 4

You might be interested in generating new app with postgres default:

rails new myapp --database=postgresql

as mentioned here: https://devcenter.heroku.com/articles/getting-started-with-rails4

Solution 5

Simply use

rails new app_name --database=postgresql

or if existing application try

 development:
  adapter: postgresql
  encoding: unicode
  database: app_dev
  pool: 5
  username: username
  password: password
  host: localhost
Share:
63,594

Related videos on Youtube

shibly
Author by

shibly

Updated on July 09, 2022

Comments

  • shibly
    shibly almost 2 years

    Rails new app.

    The current database.yml is like that:

    # SQLite version 3.x
    #   gem install sqlite3
    #
    #   Ensure the SQLite 3 gem is defined in your Gemfile
    #   gem 'sqlite3'
    development:
      adapter: sqlite3
      database: db/development.sqlite3
      pool: 5
      timeout: 5000
    
    # Warning: The database defined as "test" will be erased and
    # re-generated from your development database when you run "rake".
    # Do not set this db to the same as development or production.
    test:
      adapter: sqlite3
      database: db/test.sqlite3
      pool: 5
      timeout: 5000
    
    production:
      adapter: sqlite3
      database: db/production.sqlite3
      pool: 5
      timeout: 5000
    

    I need to edit this for postgresql database.

    How can I do this?