I want to try get Rails and MSSQL talking within our CI tool, CircleCI. I work on a mac, so setting this up was fairly pain free. I installed FreeTDS locally using Homebrew. Then I spawned up a MSSQL docker image and set my config in my rails app to point to it and that all worked.
CircleCI is a little different.
I have done the following.
In my gemfile added:
# mssql database gems
gem 'tiny_tds'
gem 'activerecord-sqlserver-adapter'
Modified our database.yml file with:
default: &default
adapter: sqlserver
pool: 5
encoding: utf8
mode: dblib
development:
<<: *default
host: localhost
database: collections_development
username: sa
password: P#55w0rd
test:
<<: *default
host: localhost
database: collections_test
username: sa
password: P#55w0rd
I built a docker image with:
FROM circleci/ruby:2.4.1-node-browsers
RUN set -ex \
&& sudo apt-get install build-essential \
&& sudo apt-get install libc6-dev \
&& sudo wget -O freetds-1.00.54.tar.gz "ftp://ftp.freetds.org/pub/freetds/stable/freetds-1.00.54.tar.gz" \
&& sudo tar -xzvf freetds-1.00.54.tar.gz \
&& cd freetds-1.00.54 \
&& sudo ./configure \
&& sudo make \
&& sudo make install
This image is hosted on docker hub here.
Next I built the CircleCI config:
version: 2
jobs:
build:
working_directory: ~/collections-api
docker:
- image: legendaryrob/ruby:2.4.1-node-browser-freetds54-lib6c
environment:
RAILS_ENV: test
- image: microsoft/mssql-server-linux
environment:
ACCEPT_EULA: Y
SA_PASSWORD: P#55w0rd
environment:
RAILS_ENV: test
steps:
- checkout
- restore_cache:
name: Restore bundle cache
keys:
- collections-api-bundle-{{ checksum "Gemfile.lock" }}
- run:
name: Allow CI to read from pdg gemserver
command: bundle config https://gems.pdg.io/ $GEMS_USERNAME:$GEMS_PASSWORD
- run:
name: Bundle Install
command: bundle install --path vendor/bundle --jobs 4 --retry 3
- save_cache:
name: Store bundle cache
key: collections-api-bundle-{{ checksum "Gemfile.lock" }}
paths:
- vendor/bundle
- run:
name: Wait for DB
command: dockerize -wait tcp://localhost:1433 -timeout 1m
- run:
name: test tds connection
command: tsql -C
# Run setup
- run: ./spec/setup/circle_setup.sh
- run:
name: Create the database
command: bundle exec rake -v --trace db:create
- run:
name: Migrate the database
command: bundle exec rake -v --trace db:migrate
- run:
name: Check environment variables are present
command: bundle exec rake env_variables:check
- run:
name: Run tests
command: bundle exec rspec
The MSSQL docker image I am getting from Microsoft's docker hub account directly -> https://hub.docker.com/r/microsoft/mssql-server-linux/
Here you can see a couple things. I set ruby box I built with TDS installed and all the dependancies needed. I ensured that we are using the same version of TDS that we are using locally, because it is working locally, I have also tried a few of the other versions just incase I was dealing with a flakey version.
I also ensure that we can connect to the MSSQL docker box and ensure that we have the right tds config:
- run:
name: Wait for DB
command: dockerize -wait tcp://localhost:1433 -timeout 1m
- run:
name: test tds connection
command: tsql -C
This will result in the following:
#!/bin/bash -eo pipefail
dockerize -wait tcp://localhost:1433 -timeout 1m
enter code here
2017/09/01 09:25:40 Waiting for: tcp://localhost:1433
2017/09/01 09:25:40 Problem with dial: dial tcp 127.0.0.1:1433:
getsockopt: connection refused. Sleeping 1s
2017/09/01 09:25:41 Problem with dial: dial tcp 127.0.0.1:1433:
getsockopt: connection refused. Sleeping 1s
2017/09/01 09:25:42 Problem with dial: dial tcp 127.0.0.1:1433:
getsockopt: connection refused. Sleeping 1s
2017/09/01 09:25:48 Connected to tcp://localhost:1433
and
#!/bin/bash -eo pipefail
tsql -C
[TinyTds][v2.0.0][tsql]: /usr/local/bin/tsql
Compile-time settings (established with the "configure" script)
Version: freetds v1.00.54
freetds.conf directory: /usr/local/etc
MS db-lib source compatibility: no
Sybase binary compatibility: no
Thread safety: yes
iconv library: yes
TDS version: auto
iODBC: no
unixodbc: no
SSPI "trusted" logins: no
Kerberos: no
OpenSSL: yes
GnuTLS: no
MARS: no
But then I get timeouts. These timeouts are intermittent, they will sometimes occur when we are trying to connect to localhost:1433
But mostly it occurs when we get to the rake tasks.
Below is the stack trace I am getting, I have tried a few different versions of MSSQL docker as well with no effect. If anyone has tried doing this please let me know I would really appreciate some help around doing this.
#!/bin/bash -eo pipefail
bundle exec rake -v --trace db:create
** Invoke db:create (first_time)
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:create
TinyTds::Error: Adaptive Server connection timed out: CREATE DATABASE [collections_test]
Couldn't create database for {"adapter"=>"sqlserver", "pool"=>5, "encoding"=>"utf8", "mode"=>"dblib", "host"=>"localhost", "database"=>"collections_test", "username"=>"sa", "password"=>"P#55w0rd"}
rake aborted!
ActiveRecord::StatementInvalid: TinyTds::Error: Adaptive Server connection timed out: CREATE DATABASE [collections_test]
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/activerecord-sqlserver-adapter-5.1.1/lib/active_record/connection_adapters/sqlserver/database_statements.rb:274:in `do'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/activerecord-sqlserver-adapter-5.1.1/lib/active_record/connection_adapters/sqlserver/database_statements.rb:274:in `raw_connection_do'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/activerecord-sqlserver-adapter-5.1.1/lib/active_record/connection_adapters/sqlserver/database_statements.rb:215:in `block in do_execute'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.3/lib/active_record/connection_adapters/abstract_adapter.rb:612:in `block (2 levels) in log'
/usr/local/lib/ruby/2.4.0/monitor.rb:214:in `mon_synchronize'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.3/lib/active_record/connection_adapters/abstract_adapter.rb:611:in `block in log'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.3/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.3/lib/active_record/connection_adapters/abstract_adapter.rb:603:in `log'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/activerecord-sqlserver-adapter-5.1.1/lib/active_record/connection_adapters/sqlserver/database_statements.rb:215:in `do_execute'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/activerecord-sqlserver-adapter-5.1.1/lib/active_record/connection_adapters/sqlserver/database_tasks.rb:10:in `create_database'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/activerecord-sqlserver-adapter-5.1.1/lib/active_record/tasks/sqlserver_database_tasks.rb:22:in `create'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.3/lib/active_record/tasks/database_tasks.rb:117:in `create'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.3/lib/active_record/tasks/database_tasks.rb:137:in `block in create_current'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.3/lib/active_record/tasks/database_tasks.rb:304:in `block in each_current_configuration'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.3/lib/active_record/tasks/database_tasks.rb:303:in `each'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.3/lib/active_record/tasks/database_tasks.rb:303:in `each_current_configuration'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.3/lib/active_record/tasks/database_tasks.rb:136:in `create_current'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.3/lib/active_record/railties/databases.rake:27:in `block (2 levels) in <top (required)>'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/rake-12.0.0/lib/rake/task.rb:250:in `block in execute'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/rake-12.0.0/lib/rake/task.rb:250:in `each'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/rake-12.0.0/lib/rake/task.rb:250:in `execute'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/rake-12.0.0/lib/rake/task.rb:194:in `block in invoke_with_call_chain'
/usr/local/lib/ruby/2.4.0/monitor.rb:214:in `mon_synchronize'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/rake-12.0.0/lib/rake/task.rb:187:in `invoke_with_call_chain'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/rake-12.0.0/lib/rake/task.rb:180:in `invoke'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:152:in `invoke_task'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:108:in `block (2 levels) in top_level'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:108:in `each'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:108:in `block in top_level'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:117:in `run_with_threads'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:102:in `top_level'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:80:in `block in run'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:178:in `standard_exception_handling'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:77:in `run'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/bin/rake:23:in `load'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/bin/rake:23:in `<top (required)>'
/usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/lib/bundler/cli/exec.rb:74:in `load'
/usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/lib/bundler/cli/exec.rb:74:in `kernel_load'
/usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/lib/bundler/cli/exec.rb:27:in `run'
/usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/lib/bundler/cli.rb:362:in `exec'
/usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
/usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/lib/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
/usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/lib/bundler/cli.rb:22:in `dispatch'
/usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/lib/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
/usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/lib/bundler/cli.rb:13:in `start'
/usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/exe/bundle:30:in `block in <top (required)>'
/usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/lib/bundler/friendly_errors.rb:121:in `with_friendly_errors'
/usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/exe/bundle:22:in `<top (required)>'
/usr/local/bin/bundle:23:in `load'
/usr/local/bin/bundle:23:in `<main>'
TinyTds::Error: Adaptive Server connection timed out
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/activerecord-sqlserver-adapter-5.1.1/lib/active_record/connection_adapters/sqlserver/database_statements.rb:274:in `do'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/activerecord-sqlserver-adapter-5.1.1/lib/active_record/connection_adapters/sqlserver/database_statements.rb:274:in `raw_connection_do'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/activerecord-sqlserver-adapter-5.1.1/lib/active_record/connection_adapters/sqlserver/database_statements.rb:215:in `block in do_execute'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.3/lib/active_record/connection_adapters/abstract_adapter.rb:612:in `block (2 levels) in log'
/usr/local/lib/ruby/2.4.0/monitor.rb:214:in `mon_synchronize'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.3/lib/active_record/connection_adapters/abstract_adapter.rb:611:in `block in log'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.3/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.3/lib/active_record/connection_adapters/abstract_adapter.rb:603:in `log'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/activerecord-sqlserver-adapter-5.1.1/lib/active_record/connection_adapters/sqlserver/database_statements.rb:215:in `do_execute'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/activerecord-sqlserver-adapter-5.1.1/lib/active_record/connection_adapters/sqlserver/database_tasks.rb:10:in `create_database'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/activerecord-sqlserver-adapter-5.1.1/lib/active_record/tasks/sqlserver_database_tasks.rb:22:in `create'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.3/lib/active_record/tasks/database_tasks.rb:117:in `create'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.3/lib/active_record/tasks/database_tasks.rb:137:in `block in create_current'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.3/lib/active_record/tasks/database_tasks.rb:304:in `block in each_current_configuration'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.3/lib/active_record/tasks/database_tasks.rb:303:in `each'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.3/lib/active_record/tasks/database_tasks.rb:303:in `each_current_configuration'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.3/lib/active_record/tasks/database_tasks.rb:136:in `create_current'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.3/lib/active_record/railties/databases.rake:27:in `block (2 levels) in <top (required)>'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/rake-12.0.0/lib/rake/task.rb:250:in `block in execute'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/rake-12.0.0/lib/rake/task.rb:250:in `each'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/rake-12.0.0/lib/rake/task.rb:250:in `execute'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/rake-12.0.0/lib/rake/task.rb:194:in `block in invoke_with_call_chain'
/usr/local/lib/ruby/2.4.0/monitor.rb:214:in `mon_synchronize'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/rake-12.0.0/lib/rake/task.rb:187:in `invoke_with_call_chain'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/rake-12.0.0/lib/rake/task.rb:180:in `invoke'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:152:in `invoke_task'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:108:in `block (2 levels) in top_level'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:108:in `each'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:108:in `block in top_level'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:117:in `run_with_threads'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:102:in `top_level'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:80:in `block in run'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:178:in `standard_exception_handling'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:77:in `run'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/bin/rake:23:in `load'
/home/circleci/collections-api/vendor/bundle/ruby/2.4.0/bin/rake:23:in `<top (required)>'
/usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/lib/bundler/cli/exec.rb:74:in `load'
/usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/lib/bundler/cli/exec.rb:74:in `kernel_load'
/usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/lib/bundler/cli/exec.rb:27:in `run'
/usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/lib/bundler/cli.rb:362:in `exec'
/usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
/usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/lib/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
/usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/lib/bundler/cli.rb:22:in `dispatch'
/usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/lib/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
/usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/lib/bundler/cli.rb:13:in `start'
/usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/exe/bundle:30:in `block in <top (required)>'
/usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/lib/bundler/friendly_errors.rb:121:in `with_friendly_errors'
/usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/exe/bundle:22:in `<top (required)>'
/usr/local/bin/bundle:23:in `load'
/usr/local/bin/bundle:23:in `<main>'
Tasks: TOP => db:create
Exited with code 1
Note: The reason we are needing to connect to MSSQL is because we are going to be writing to the db for a short time, we have another team who relies on Access that is using MSSQL. I am just hoping there is someone else out there who has fought this beast and won.
EDIT: freetds.conf
# $Id: freetds.conf,v 1.12 2007-12-25 06:02:36 jklowden Exp $
#
# This file is installed by FreeTDS if no file by the same
# name is found in the installation directory.
#
# For information about the layout of this file and its settings,
# see the freetds.conf manpage "man freetds.conf".
# Global settings are overridden by those in a database
# server specific section
[global]
# TDS protocol version
tds version = auto
# Whether to write a TDSDUMP file for diagnostic purposes
# (setting this to /tmp is insecure on a multi-user system)
; dump file = /tmp/freetds.log
; debug flags = 0xffff
# Command and connection timeouts
; timeout = 10
; connect timeout = 10
# If you get out-of-memory errors, it may mean that your client
# is trying to allocate a huge buffer for a TEXT field.
# Try setting 'text size' to a more reasonable limit
text size = 64512
# If you experience TLS handshake errors and are using openssl,
# try adjusting the cipher list (don't surround in double or single quotes)
# openssl ciphers = HIGH:!SSLv2:!aNULL:-DH
# A typical Sybase server
[egServer50]
host = symachine.domain.com
port = 5000
tds version = 5.0
# A typical Microsoft server
[egServer70]
host = ntmachine.domain.com
port = 1433
tds version = 7.0
Related
While trying to deploy in the "Ruby 3.0 running on 64bit Amazon Linux 2/3.6.2" platform, both using the eb deploy command or manually uploading a zipped version of my project, it seems the Postgresql service is not running in my instance since I get the next in eb-engile.log:
2023/01/17 17:31:04.238133 [ERROR] An error occurred during execution of command [app-deploy] - [rake tasks]. Stop running the command. Error: running rake task db:migrate failed with error command bundle exec rake db:migrate failed with error Command /bin/su webapp -c bundle exec rake db:migrate failed with error exit status 1. Stderr:rake aborted!
ActiveRecord::ConnectionNotEstablished: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/postgresql_adapter.rb:83:in `rescue in new_client'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/postgresql_adapter.rb:77:in `new_client'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/postgresql_adapter.rb:37:in `postgresql_connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `public_send'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `new_connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:926:in `checkout_new_connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:905:in `try_to_checkout_new_connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:866:in `acquire_connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:588:in `checkout'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:428:in `connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:1128:in `retrieve_connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_handling.rb:327:in `retrieve_connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_handling.rb:283:in `connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/tasks/database_tasks.rb:237:in `migrate'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/railties/databases.rake:92:in `block (3 levels) in <main>'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/railties/databases.rake:90:in `each'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/railties/databases.rake:90:in `block (2 levels) in <main>'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/exe/rake:27:in `<top (required)>'
/opt/elasticbeanstalk/.rbenv/versions/3.0.5/bin/bundle:25:in `load'
/opt/elasticbeanstalk/.rbenv/versions/3.0.5/bin/bundle:25:in `<main>'
Caused by:
PG::ConnectionBad: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/pg-1.2.3/lib/pg.rb:58:in `initialize'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/pg-1.2.3/lib/pg.rb:58:in `new'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/pg-1.2.3/lib/pg.rb:58:in `connect'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/postgresql_adapter.rb:78:in `new_client'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/postgresql_adapter.rb:37:in `postgresql_connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `public_send'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `new_connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:926:in `checkout_new_connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:905:in `try_to_checkout_new_connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:866:in `acquire_connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:588:in `checkout'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:428:in `connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:1128:in `retrieve_connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_handling.rb:327:in `retrieve_connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_handling.rb:283:in `connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/tasks/database_tasks.rb:237:in `migrate'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/railties/databases.rake:92:in `block (3 levels) in <main>'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/railties/databases.rake:90:in `each'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/railties/databases.rake:90:in `block (2 levels) in <main>'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/exe/rake:27:in `<top (required)>'
/opt/elasticbeanstalk/.rbenv/versions/3.0.5/bin/bundle:25:in `load'
/opt/elasticbeanstalk/.rbenv/versions/3.0.5/bin/bundle:25:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
Although, when trying to run the /bin/su webapp -c bundle exec rake db:migrate command as root (please notice that, I am invoking bundler then as the webapp user), I get different kind of error (trying to install a missing gem?):
Bundler::PermissionError: There was an error while trying to write to
`/var/app/staging/vendor/bundle/ruby/3.0.0/cache/public_suffix-5.0.1.gem`. It is likely that you
need to grant write permissions for that path.
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/shared_helpers.rb:105:in `rescue in
filesystem_access'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/shared_helpers.rb:102:in
`filesystem_access'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/rubygems_integration.rb:479:in `block in
download_gem'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/retry.rb:40:in `run'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/retry.rb:30:in `attempt'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/rubygems_integration.rb:470:in
`download_gem'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/source/rubygems.rb:485:in `download_gem'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/source/rubygems.rb:447:in `fetch_gem'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/source/rubygems.rb:431:in
`fetch_gem_if_possible'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/source/rubygems.rb:158:in `install'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/installer/gem_installer.rb:54:in
`install'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/installer/gem_installer.rb:16:in
`install_from_spec'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/installer/parallel_installer.rb:155:in
`do_install'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/installer/parallel_installer.rb:140:in
`install_serially'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/installer/parallel_installer.rb:91:in
`call'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/installer/parallel_installer.rb:67:in
`call'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/installer.rb:244:in
`install_in_parallel'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/installer.rb:201:in `install'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/installer.rb:89:in `block in run'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/process_lock.rb:19:in `rescue in lock'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/process_lock.rb:15:in `lock'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/installer.rb:71:in `run'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/installer.rb:23:in `install'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/cli/install.rb:62:in `run'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/cli.rb:260:in `block in install'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/settings.rb:131:in `temporary'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/cli.rb:259:in `install'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/vendor/thor/lib/thor/command.rb:27:in
`run'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/vendor/thor/lib/thor/invocation.rb:127:in
`invoke_command'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/vendor/thor/lib/thor.rb:392:in
`dispatch'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/cli.rb:34:in `dispatch'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/vendor/thor/lib/thor/base.rb:485:in
`start'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/cli.rb:28:in `start'
/opt/rubies/ruby-3.0.5/lib/ruby/gems/3.0.0/gems/bundler-2.4.1/exe/bundle:45:in `block in <top
(required)>'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/friendly_errors.rb:117:in
`with_friendly_errors'
/opt/rubies/ruby-3.0.5/lib/ruby/gems/3.0.0/gems/bundler-2.4.1/exe/bundle:33:in `<top
(required)>'
/opt/elasticbeanstalk/.rbenv/versions/3.0.5/bin/bundle:25:in `load'
/opt/elasticbeanstalk/.rbenv/versions/3.0.5/bin/bundle:25:in `<main>'
An error occurred while installing public_suffix (5.0.1), and Bundler cannot
continue.
In Gemfile:
capybara was resolved to 3.38.0, which depends on
addressable was resolved to 2.8.1, which depends on
public_suffix
It also seems the postgresql service is not installed (checked installed services starting with the "post" string):
[root#ip************ staging]# systemctl list-unit-files | grep post
postfix.service enabled
So, the question is, how do I make the eb deploy command run without failing? given that:
I see one error using eb deploy that highlights a failing rake db:migrate command but, when trying to running it manually after connecting through SSH it throws a different error; the one that mentions public_suffix. This seems unexpected.
The postgresql service should be installed in AWS's managed platform, as with previous versions
Adding a database to your Elastic Beanstalk environment
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features.managing.db.html
It looks like your app is trying to connect to a local database server:
Caused by:
PG::ConnectionBad: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
What are the contents of your config/database.yml? Is it reading environment variables that elasticbeanstalk knows to pass in? Does your RDS instance have the right access rules set up to allow connections from EB?
No idea why but a current already bower-rails installed project can't do bower:install anymore !
As it worked before, I already have packages installed locally.
No idea wht is going one. NO changes as been made !
Tried to reinstall npm and bower, no changes !
rake bower:install
bower.js files generated
/usr/local/bin/bower install -p
bower ENOTFOUND Package dsl-generated dependencies=./vendor/assets/bower.json not found
rake aborted!
Command failed with status (1): [/usr/local/bin/bower install -p ...]
Tasks: TOP => bower:install:production
(See full trace by running task with --trace)
I DO have a bower.json in my /vendor/assets/ directory.
npm -v
1.4.14
bower -v
1.3.11
Here is the full trace:
rake bower:install --trace
** Invoke bower:install (first_time)
** Execute bower:install
** Invoke bower:install:production (first_time)
** Execute bower:install:production
bower.js files generated
/usr/local/bin/bower install -p
bower ENOTFOUND Package dsl-generated dependencies=./vendor/assets/bower.json not found
rake aborted!
Command failed with status (1): [/usr/local/bin/bower install -p ...]
/usr/local/var/rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/file_utils.rb:54:in `block in create_shell_runner'
/usr/local/var/rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/file_utils.rb:45:in `call'
/usr/local/var/rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/file_utils.rb:45:in `sh'
/usr/local/var/rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/bower-rails-0.8.3/lib/tasks/bower.rake:36:in `block (4 levels) in <top (required)>'
/usr/local/var/rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/bower-rails-0.8.3/lib/bower-rails/performer.rb:32:in `instance_exec'
/usr/local/var/rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/bower-rails-0.8.3/lib/bower-rails/performer.rb:32:in `block in perform'
/usr/local/var/rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/bower-rails-0.8.3/lib/bower-rails/performer.rb:57:in `block (2 levels) in dsl_perform_command'
/usr/local/var/rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/bower-rails-0.8.3/lib/bower-rails/performer.rb:56:in `chdir'
/usr/local/var/rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/bower-rails-0.8.3/lib/bower-rails/performer.rb:56:in `block in dsl_perform_command'
/usr/local/var/rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/bower-rails-0.8.3/lib/bower-rails/performer.rb:55:in `each'
/usr/local/var/rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/bower-rails-0.8.3/lib/bower-rails/performer.rb:55:in `dsl_perform_command'
/usr/local/var/rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/bower-rails-0.8.3/lib/bower-rails/performer.rb:31:in `perform'
/usr/local/var/rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/bower-rails-0.8.3/lib/bower-rails/performer.rb:10:in `perform'
/usr/local/var/rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/bower-rails-0.8.3/lib/tasks/bower.rake:35:in `block (3 levels) in <top (required)>'
/usr/local/var/rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/task.rb:240:in `call'
/usr/local/var/rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/task.rb:240:in `block in execute'
/usr/local/var/rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/task.rb:235:in `each'
/usr/local/var/rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/task.rb:235:in `execute'
/usr/local/var/rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/usr/local/var/rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
/usr/local/var/rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/task.rb:172:in `invoke_with_call_chain'
/usr/local/var/rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/task.rb:165:in `invoke'
/usr/local/var/rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/bower-rails-0.8.3/lib/tasks/bower.rake:11:in `block (2 levels) in <top (required)>'
/usr/local/var/rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/task.rb:240:in `call'
/usr/local/var/rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/task.rb:240:in `block in execute'
/usr/local/var/rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/task.rb:235:in `each'
/usr/local/var/rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/task.rb:235:in `execute'
/usr/local/var/rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/usr/local/var/rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
/usr/local/var/rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/task.rb:172:in `invoke_with_call_chain'
/usr/local/var/rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/task.rb:165:in `invoke'
/usr/local/var/rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:150:in `invoke_task'
/usr/local/var/rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/usr/local/var/rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:106:in `each'
/usr/local/var/rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:106:in `block in top_level'
/usr/local/var/rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:115:in `run_with_threads'
/usr/local/var/rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:100:in `top_level'
/usr/local/var/rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:78:in `block in run'
/usr/local/var/rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:176:in `standard_exception_handling'
/usr/local/var/rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:75:in `run'
./bin/rake:4:in `<main>'
Tasks: TOP => bower:install:production
Same when I try to rake bower:list
rake bower:list
/usr/local/bin/bower list
bower check-new Checking for new versions of the project dependencies..
bower ENOTFOUND Package dsl-generated dependencies=./vendor/assets/bower.json not found
rake aborted!
Command failed with status (1): [/usr/local/bin/bower list...]
Tasks: TOP => bower:list
(See full trace by running task with --trace)
Maybe too late, but I'll leave it here, since I had similar issues using bower-rails, when running:
rake bower:install.
The solution I found on the web is running:
sudo apt-get install nodejs-legacy
Hope it's helpful for someone else in the same situation.
you can install nodejs by nvm, apt-get can't install all packages of nodejs.
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.26.1/install.sh | bash
source ~/.profile
nvm install v0.12.7
npn install bower -g
rake bower:install
In my case, our codebase used private Bower packages hosted on Gemfury. We enabled this by adding
"resolvers": [
"fury-bower-resolver"
]
to the repo's .bowerrc. This setting is only supported in Bower 1.7.x. My global bower binary was 1.7.2, so I had no problems running bower install, but the rake bower:install tasks doesn't use my global bower; it uses my_repo/node_modules/.bin/bower instead, and that one was version 1.4.2, which didn't understand the resolvers setting, hence the 'package not found' error. You can see which binary it's using in one of the first log output lines; then you can invoke that binary with -v to see which version it's on. The fix was to upgrade the Bower binary that bower-rails uses with npm upgrade bower (needless to say, don't add the -g option!)
Try deleting the vendor directory and re-running rake bower:install.
P.S. Before deleting please check what else is inside vendor directory besides bower_components - you may have to reinstall those as well.
I'm using rails 4.1.5 with postgresql 9.1 under Debian 7, and I'm not able to create a database in my development environment. When I run
bin/rake db:create
I get
home/rs/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.5/lib/active_record/connection_adapters/postgresql_adapter.rb:898:in `rescue in connect': FATAL: database "direct-dev" does not exist
Run `$ bin/rake db:create db:migrate` to create your database (ActiveRecord::NoDatabaseError)
from /home/rs/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.5/lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `connect'
from ...
I am trying to create the database so, naturally, it does not exist. However rails should create it ... Here's my config/database.yml:
default: &default
adapter: postgresql
encoding: unicode
pool: 5
development:
<<: *default
database: direct-dev
And here's a part of the postgresql log:
2014-09-01 19:30:40 CEST LOG: connection received: host=[local]
2014-09-01 19:30:40 CEST LOG: connection authorized: user=rs database=direct-dev
2014-09-01 19:30:40 CEST FATAL: database "direct-dev" does not exist
Do you have any pointers? I've been at this for more than an hour, and still can't understand why this is happening ...
Thanks!
Rails 4.1 ships with spring preloader, and
New Rails 4.1 applications will ship with "springified" binstubs. This means that bin/rails and bin/rake will automatically take advantage of preloaded spring environments.
which means that the "springified" bin/rake will attempt to preload the app, which in turn will attempt to run the initilizers resulting in the problem you're seeing.
To fix / work around this you want to run the initial setup rake tasks without spring. One way to achieve that is to run it with bundler instead:
bundle exec rake db:create
I found the issue ...
It has to do with Rails initializers: Rails seems to load all the initializers before executing bin/rake db:create.
And, in this particular application, there are a few custom initializers which depend on an ActiveRecord model (which, in turn, depends on the database being created, available and with the corresponding table).
Therefore rake never gets to actually execute the task, it fails when executing the initializers. I should have known if I had carefully read the full error message log. This is the full log (see below, in bold, the offending lines):
/home/rs/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.5/lib/active_record/connection_adapters/postgresql_adapter.rb:898:in `rescue in connect': FATAL: database "ds-dev" does not exist
Run `$ bin/rake db:create db:migrate` to create your database (ActiveRecord::NoDatabaseError)
from /home/rs/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.5/lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `connect'
from /home/rs/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.5/lib/active_record/connection_adapters/postgresql_adapter.rb:568:in `initialize'
from /home/rs/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.5/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `new'
from /home/rs/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.5/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `postgresql_connection'
from /home/rs/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:435:in `new_connection'
from /home/rs/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:445:in `checkout_new_connection'
from /home/rs/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:416:in `acquire_connection'
from /home/rs/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:351:in `block in checkout'
from /home/rs/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
from /home/rs/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:350:in `checkout'
from /home/rs/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
from /home/rs/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
from /home/rs/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
from /home/rs/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:541:in `retrieve_connection'
from /home/rs/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.5/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
from /home/rs/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.5/lib/active_record/connection_handling.rb:87:in `connection'
from /home/rs/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.5/lib/active_record/model_schema.rb:209:in `table_exists?'
from /home/rs/pr/ds/app/models/property.rb:32:in `get'
from /home/rs/pr/ds/config/initializers/custom/setup_mail.rb:3:in `'
from /home/rs/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:241:in `load'
from /home/rs/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:241:in `block in load'
from /home/rs/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:232:in `load_dependency'
from /home/rs/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:241:in `load'
from /home/rs/.rvm/gems/ruby-2.1.2/gems/railties-4.1.5/lib/rails/engine.rb:648:in `block in load_config_initializer'
from /home/rs/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.5/lib/active_support/notifications.rb:161:in `instrument'
from /home/rs/.rvm/gems/ruby-2.1.2/gems/railties-4.1.5/lib/rails/engine.rb:647:in `load_config_initializer'
from /home/rs/.rvm/gems/ruby-2.1.2/gems/railties-4.1.5/lib/rails/engine.rb:612:in `block (2 levels) in '
from /home/rs/.rvm/gems/ruby-2.1.2/gems/railties-4.1.5/lib/rails/engine.rb:611:in `each'
from /home/rs/.rvm/gems/ruby-2.1.2/gems/railties-4.1.5/lib/rails/engine.rb:611:in `block in '
from /home/rs/.rvm/gems/ruby-2.1.2/gems/railties-4.1.5/lib/rails/initializable.rb:30:in `instance_exec'
from /home/rs/.rvm/gems/ruby-2.1.2/gems/railties-4.1.5/lib/rails/initializable.rb:30:in `run'
from /home/rs/.rvm/gems/ruby-2.1.2/gems/railties-4.1.5/lib/rails/initializable.rb:55:in `block in run_initializers'
from /home/rs/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:226:in `block in tsort_each'
from /home/rs/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
from /home/rs/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:418:in `block (2 levels) in each_strongly_connected_component_from'
from /home/rs/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:427:in `each_strongly_connected_component_from'
from /home/rs/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:417:in `block in each_strongly_connected_component_from'
from /home/rs/.rvm/gems/ruby-2.1.2/gems/railties-4.1.5/lib/rails/initializable.rb:44:in `each'
from /home/rs/.rvm/gems/ruby-2.1.2/gems/railties-4.1.5/lib/rails/initializable.rb:44:in `tsort_each_child'
from /home/rs/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:411:in `call'
from /home/rs/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:411:in `each_strongly_connected_component_from'
from /home/rs/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:347:in `block in each_strongly_connected_component'
from /home/rs/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:345:in `each'
from /home/rs/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:345:in `call'
from /home/rs/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:345:in `each_strongly_connected_component'
from /home/rs/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:224:in `tsort_each'
from /home/rs/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:205:in `tsort_each'
from /home/rs/.rvm/gems/ruby-2.1.2/gems/railties-4.1.5/lib/rails/initializable.rb:54:in `run_initializers'
from /home/rs/.rvm/gems/ruby-2.1.2/gems/railties-4.1.5/lib/rails/application.rb:300:in `initialize!'
from /home/rs/pr/ds/config/environment.rb:5:in `'
from /home/rs/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:247:in `require'
from /home/rs/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:247:in `block in require'
from /home/rs/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:232:in `load_dependency'
from /home/rs/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:247:in `require'
from /home/rs/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/application.rb:92:in `preload'
from /home/rs/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/application.rb:140:in `serve'
from /home/rs/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/application.rb:128:in `block in run'
from /home/rs/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/application.rb:122:in `loop'
from /home/rs/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/application.rb:122:in `run'
from /home/rs/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/application/boot.rb:18:in `'
from /home/rs/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /home/rs/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from -e:1:in `'
I will work on refactoring the code, in order to get rid of any model dependencies in the initializers (which I'm pretty sure it must be a very bad practice).
You might try running this command-
bin/rake db:create RAILS_ENV=development
Or this command-
bin/rake db:migrate RAILS_ENV=development
Had the same issue today (in OS X).
Solved with:
psql -U postgres
CREATE ROLE rolename WITH CREATEDB LOGIN;
Use \du to check if it's created.
Use \password rolename to create a password for that user/role.
Then you can setup DB with bundle exec rake db:migrate
None of the solutions worked for me, but this worked for me.
$ brew services list
$ brew services restart postgresql
None of the solutions worked for me, but then I saw that some answers mentioned preloading as part of the problem. I realized I had
config.eager_load = true in config/environments/development.rb. I changed it to false and it solved the problem.
I see two issues, as is04 pointed out you probably need at least a username value in your database.yml.
You also need to create the postgres role:
su - postgres
create role direct-dev with createdb login password 'password1'
I had the same problem and in my case, I had used Answer.column_name in a validation in the Answer model itself. Because test database was already created on my local so RAILS_ENV=test rails db:create was working fine on local, but giving the same error in CI/CD pipeline
It was due to the reason that Rails load all the files inside app/ directory before running db:create command, and at that time as no database is there Answer.column_names failed.
I used something like this:
validates_uniqueness_of :content, scope: (Answer.column_names - %w[id created_at updated_at]).map(&:to_sym), message: 'Duplicate answer'
which is wrong. Then I changed to:
DUPLICATE_ANSWER_SCOPE = %i[content question_id session_id]
validates_uniqueness_of :content, scope: DUPLICATE_ANSWER_SCOPE, message: 'Duplicate answer'
Here is my Dockerfile for the rails project.
Take a look at this part:
CMD mkdir -p tmp/pids && \
bundle exec rake db:create && \
bundle exec rails db:migrate && \
bundle exec rake db:seed && \
bundle exec puma -C config/puma.rb
Bundler 2.1.4, ruby 2.7.2, rails 6.0.3 compatible.
Docker compose part:
server:
container_name: server
build:
context: Server
dockerfile: Dockerfile
args:
ENV: 'development'
restart: unless-stopped
depends_on:
- db
env_file:
- ./Server/.env
ports:
- '9090:3000'
volumes:
- ./Server:/app
- ./Server/Docker/usr/.gemrc:/root/.gemrc
networks:
- app-network
FROM ruby:2.7.2-alpine3.12
# env and arg variables setup
ARG APP_HOME='/app'
ARG ENV
ENV RAILS_ENV=$ENV \
RACK_ENV=$ENV \
RAILS_ROOT=$APP_HOME
# timezone setup
RUN apk add --update tzdata && \
cp /usr/share/zoneinfo/Europe/London /etc/localtime && \
echo "Europe/London" > /etc/timezone
# building in tmp dir
WORKDIR /tmp
ADD Gemfile ./
#install dependencies (bundler 2.1.4, ruby 2.7.2, rails 6.0.3 compatible)
RUN apk add --update --virtual runtime-deps postgresql-client nodejs libffi-dev readline sqlite xz && \
apk add --virtual build-deps build-base openssl postgresql-dev libc-dev linux-headers libxml2-dev libxslt-dev readline-dev && \
gem install bundler -v 2.1.4 && \
bundle install --jobs=4 && \
apk del build-deps
# /app
WORKDIR $APP_HOME
# create dbs if no such, migrate, seed, start
CMD mkdir -p tmp/pids && \
bundle exec rake db:create && \
bundle exec rails db:migrate && \
bundle exec rake db:seed && \
bundle exec puma -C config/puma.rb
Here is the list of commands I run at each deployment (including the first one)
//create pids folder if no yet
mkdir -p tmp/pids
//create dbs if no yet
bundle exec rake db:create
//run all new migrations
bundle exec rails db:migrate
//seed db with data if required
bundle exec rake db:seed
//start the server with config
bundle exec puma -C config/puma.rb
Super stumped by why Postgres isn't working on a new app I just started. I've got it working for one app already. I'm using postgres.app, and it's running.
I started a new app with
rails new depot -d postgresql
and then I went into the database.yml file and changed username to my $USER (which is what it is for the other app, which is working). So now my database.yml file has this development section:
development:
adapter: postgresql
encoding: unicode
database: depot_development
pool: 5
username: <username>
password:
But when I run "rake db:create" or "rake db:create:all" I still got this error (in full, cause I don't know what's relevant):
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "database"=>"depot_development", "pool"=>5, "username"=>"<username>", "password"=>nil}
could not connect to server: Permission denied
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
/Users/<username>/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:1213:in `initialize'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:1213:in `new'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:1213:in `connect'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:329:in `initialize'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `new'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `postgresql_connection'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:309:in `new_connection'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:319:in `checkout_new_connection'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:241:in `block (2 levels) in checkout'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:236:in `loop'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:236:in `block in checkout'
/Users/<username>/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:233:in `checkout'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:96:in `block in connection'
/Users/<username>/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:95:in `connection'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:404:in `retrieve_connection'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_specification.rb:170:in `retrieve_connection'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_specification.rb:144:in `connection'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/railties/databases.rake:107:in `rescue in create_database'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/railties/databases.rake:51:in `create_database'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/railties/databases.rake:40:in `block (3 levels) in <top (required)>'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/railties/databases.rake:40:in `each'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/railties/databases.rake:40:in `block (2 levels) in <top (required)>'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/<username>/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194#global/bin/rake:19:in `load'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194#global/bin/rake:19:in `<main>'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194/bin/ruby_noexec_wrapper:14:in `eval'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194/bin/ruby_noexec_wrapper:14:in `<main>'
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "database"=>"depot_test", "pool"=>5, "username"=>"<username>", "password"=>nil}
I have tried
createdb depot_development
I have tried going into the psql environment and listing users (which included my username among them). In the same psql environment, I tried
CREATE DATABASE depot;
I've made sure that the pg gem is installed with bundle install, I've run "pg_ctl start", to which I got this response:
pg_ctl: no database directory specified and environment variable PGDATA unset
I ran "ps aux | grep postgres" to make sure postgres was running, to which I got this in return (which looks like it's doing OK, right?):
<username> 10390 0.4 0.0 2425480 180 s000 R+ 6:15PM 0:00.00 grep postgres
<username> 2907 0.0 0.0 2441604 464 ?? Ss 6:17PM 0:02.31 postgres: stats collector process
<username> 2906 0.0 0.0 2445520 1664 ?? Ss 6:17PM 0:02.33 postgres: autovacuum launcher process
<username> 2905 0.0 0.0 2445388 600 ?? Ss 6:17PM 0:09.25 postgres: wal writer process
<username> 2904 0.0 0.0 2445388 1252 ?? Ss 6:17PM 0:12.08 postgres: writer process
<username> 2902 0.0 0.0 2445388 3688 ?? S 6:17PM 0:00.54 /Applications/Postgres.app/Contents/MacOS/bin/postgres -D /Users/<username>/Library/Application Support/Postgres/var -p5432
The short of it, is I've been troubleshooting for a WHILE and have NO idea what's wrong. Any ideas? I'd really appreciate it, cause I'm pretty new to Rails, and this is a pretty disheartening roadblock.
Thanks!
EDIT -- Per request, posting the successful database.yml . It seems the difference is the inclusion of a password:
development:
adapter: postgresql
encoding: unicode
database: *******_development
pool: 5
username: *******
password: *******
EDIT2 -- When I add a password to the .yml file, then run rake db:create again, I get the same error. And I'm running Mac OSX Lion, and I did initdb and stuff when I first installed PostgreSQL.
In order to create a database , before starting the command pg_ctl start
you have to initialize the database cluster then only pg_ctl start shall be success full*
this can be done in many ways
if you are running on Linux / centos with postgres 9.1
service postgresql-9.1 initdb
service postgresql-9.1 start
or you can do like this
$ mkdir -p /var/pgsql/data; chown -R postgres /var/pgsql
$ su - postgres
$ initdb -D /var/pgsql/data
# Starting, testing:
$ postgres -D /var/pgsql/data > /var/pgsql/logfile 2>&1 &
$ createdb test
$ psql test
Initializing postgres initb differes from os to os and postgres versions , if the above command did not work please have a look at
Adding
host: localhost
to development works for me.
I have problems with getting db:structure:dump to work.
I and getting this error:
C:\Sites\care>rake db:structure:dump --trace
Creating scope :search. Overwriting existing method PgSearch::Document.search.
** Invoke db:structure:dump (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:structure:dump
rake aborted!
Permission denied - pg_dump -i -s -x -O -f C:/Sites/care/db/structure.sql care_development
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.1/lib/active_support/core_ext/kernel/agnostics.rb:7:in ``'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.1/lib/active_support/core_ext/kernel/agnostics.rb:7:in ``'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.1/lib/active_record/railties/databases.rake:389:in `block (3 levels) in <top (required)>'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
C:/RailsInstaller/Ruby1.9.3/bin/rake:19:in `load'
C:/RailsInstaller/Ruby1.9.3/bin/rake:19:in `<main>'
Tasks: TOP => db:structure:dump
If I run it like this in CMD, it works:
cd C:\Program Files (x86)\PostgreSQL\9.1\bin
pg_dump.exe -i -s -x -O -f C:/Sites/care/db/structure.sql care_development
I have tried changing the permission on both the pg_dump.exe folder/file and the rails folder/files. But doesn't seem to make any different. Tried adding full permissions for Users, System and even Everyone.
I also tried adding --username params to the pg_dump call (in the rake code) and adding Login Roles that match my windows user in pgAdminIII.
(I'm on Windows 7, Rails 3 and postgreSQL 9)
Do anyone know what the problem can be?
I have same problem on my Linux machine:
Then i used the following command to make it run:
su
>> I logged in first with my Admin user
su -postgres
I save my .sql file in my /tmp folder
For dumping the .sql file in database i run the command
psql -u postgres -d my_db_name -a -f /tmp/path_to_sql_file
It works greatly for me. Hope it may help you.