1

When I create the database manually and try to use them, for example: rake db:create I get the following error:

FATAL:  database "postgres" does not exist
Couldn't create 'test_app_development' database. Please check your configuration.
rake aborted!
ActiveRecord::NoDatabaseError: FATAL:  database "postgres" does not exist

Caused by:
PG::ConnectionBad: FATAL:  database "postgres" does not exist

Tasks: TOP => db:create
(See full trace by running task with --trace)

I have another database rails_articles_development and It's working perfectly but I couldn't be creating a new database

Here's my Gemfile

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '3.0.1'

gem 'rails', '~> 6.1.3', '>= 6.1.3.1'
# gem 'sqlite3', '~> 1.4'
gem 'pg'
gem 'bootsnap', '>= 1.4.4', require: false
gem 'jbuilder', '~> 2.7'
gem 'puma', '~> 5.0'
gem 'sass-rails', '>= 6'
gem 'turbolinks', '~> 5'
gem 'webpacker', '~> 5.0'

group :development, :test do
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end

group :development do
  gem 'listen', '~> 3.3'
  gem 'rack-mini-profiler', '~> 2.0'
  gem 'spring'
  gem 'web-console', '>= 4.1.0'
end

group :test do
  gem 'capybara', '>= 3.26'
  gem 'selenium-webdriver'
  gem 'webdrivers'
end

gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

Here's my database.yml

default: &default
  adapter: postgresql
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  timeout: 5000

development:
  <<: *default
  database: test_app_development

test:
  <<: *default
  database: test_app_test

production:
  <<: *default
  database: test_app_production

Already postgresql is running on my Linux machine

psql (PostgreSQL) 12.6 (Ubuntu 12.6-0ubuntu0.20.04.1)

template1=# \l
                                          List of databases
            Name            |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
----------------------------+----------+----------+-------------+-------------+-----------------------
 rails_articles_development | akash    | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 template0                  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
                            |          |          |             |             | postgres=CTc/postgres
 template1                  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
                            |          |          |             |             | postgres=CTc/postgres
(3 rows)

Here are my database users

                                   List of roles
 Role name |                         Attributes                         | Member of 
-----------+------------------------------------------------------------+-----------
 akash     | Superuser                                                  | {}
 postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
 rc        | Superuser, Create role, Create DB                          | {}

I couldn't be understanding where is the specific problem. I am a very noob in postgresql. All help appreciated.

5
  • In psql do \l to see what databases are in cluster and update your question with this information. Commented May 12, 2021 at 16:20
  • yes...I have done it and updated my question @AdrianKlaver Commented May 12, 2021 at 16:33
  • Does this answer your question? FATAL: database "postgres" does not exist Commented May 12, 2021 at 16:54
  • 2
    Well, my problem has been solved at last. From the terminal, just run the command: createdb postgres (Not inside psql) and it's created a postgres named database in my postgresql. Now it's working properly. Thanks to all! Commented May 12, 2021 at 20:05
  • Had the same problem. Found this. Fixed my problem. Want to answer your own question and accept it? Commented Feb 14, 2022 at 20:22

0

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.