[Solved] Postgresql connexion error

Hello,

I’m trying to install Fabmanager with Docker, but I’m having this problem.

could not connect to server: Connection refused
        Is the server running on host "postgres" (172.18.0.4) and accepting
        TCP/IP connections on port 5432?
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `initialize'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `new'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `connect'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/connection_adapters/postgresql_adapter.rb:242:in `initialize'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `new'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `postgresql_connection'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/connection_adapters/abstract/connection_pool.rb:438:in `new_connection'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/connection_adapters/abstract/connection_pool.rb:448:in `checkout_new_connection'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
/usr/local/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'
/usr/local/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/connection_adapters/abstract/connection_pool.rb:571:in `retrieve_connection'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/connection_handling.rb:87:in `connection'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/tasks/postgresql_database_tasks.rb:6:in `connection'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/tasks/postgresql_database_tasks.rb:15:in `create'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/tasks/database_tasks.rb:93:in `create'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/tasks/database_tasks.rb:107:in `block in create_current'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/tasks/database_tasks.rb:278:in `block in each_current_configuration'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/tasks/database_tasks.rb:277:in `each'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/tasks/database_tasks.rb:277:in `each_current_configuration'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/tasks/database_tasks.rb:106:in `create_current'
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/railties/databases.rake:17:in `block (2 levels) in <top (required)>'
/usr/local/bundle/gems/rake-12.2.1/lib/rake/task.rb:251:in `block in execute'
/usr/local/bundle/gems/rake-12.2.1/lib/rake/task.rb:251:in `each'
/usr/local/bundle/gems/rake-12.2.1/lib/rake/task.rb:251:in `execute'
/usr/local/bundle/gems/rake-12.2.1/lib/rake/task.rb:195:in `block in invoke_with_call_chain'
/usr/local/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/usr/local/bundle/gems/rake-12.2.1/lib/rake/task.rb:188:in `invoke_with_call_chain'
/usr/local/bundle/gems/rake-12.2.1/lib/rake/task.rb:181:in `invoke'
/usr/local/bundle/gems/rake-12.2.1/lib/rake/application.rb:160:in `invoke_task'
/usr/local/bundle/gems/rake-12.2.1/lib/rake/application.rb:116:in `block (2 levels) in top_level'
/usr/local/bundle/gems/rake-12.2.1/lib/rake/application.rb:116:in `each'
/usr/local/bundle/gems/rake-12.2.1/lib/rake/application.rb:116:in `block in top_level'
/usr/local/bundle/gems/rake-12.2.1/lib/rake/application.rb:125:in `run_with_threads'
/usr/local/bundle/gems/rake-12.2.1/lib/rake/application.rb:110:in `top_level'
/usr/local/bundle/gems/rake-12.2.1/lib/rake/application.rb:83:in `block in run'
/usr/local/bundle/gems/rake-12.2.1/lib/rake/application.rb:186:in `standard_exception_handling'
/usr/local/bundle/gems/rake-12.2.1/lib/rake/application.rb:80:in `run'
/usr/local/bundle/gems/rake-12.2.1/exe/rake:27:in `<top (required)>'
/usr/local/bundle/bin/rake:23:in `load'
/usr/local/bundle/bin/rake:23:in `<top (required)>'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.16.5/lib/bundler/cli/exec.rb:74:in `load'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.16.5/lib/bundler/cli/exec.rb:74:in `kernel_load'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.16.5/lib/bundler/cli/exec.rb:28:in `run'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.16.5/lib/bundler/cli.rb:424:in `exec'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.16.5/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.16.5/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.16.5/lib/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.16.5/lib/bundler/cli.rb:27:in `dispatch'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.16.5/lib/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.16.5/lib/bundler/cli.rb:18:in `start'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.16.5/exe/bundle:30:in `block in <top (required)>'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.16.5/lib/bundler/friendly_errors.rb:124:in `with_friendly_errors'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.16.5/exe/bundle:22:in `<top (required)>'
/usr/local/bin/bundle:23:in `load'
/usr/local/bin/bundle:23:in `<main>'
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "pool"=>25, "username"=>"postgres", "password"=>nil, "host"=>"postgres", "database"=>"fablab_production"}

Do you know what is wrong?

I give you below a copy of my configuration files.

Thank you in advance for your help.
Sincerely,

Simon


docker-compose.yml

version: '2'
services:
  fabmanager:
    image: sleede/fab-manager
    environment:
      RAILS_ENV: production
      RACK_ENV: production
    env_file:
      - ./config/env
    volumes:
      - ./public/assets:/usr/src/app/public/assets
      - ./public/uploads:/usr/src/app/public/uploads
      - ./invoices:/usr/src/app/invoices
      - ./exports:/usr/src/app/exports
      - ./log:/var/log/supervisor
      - ./plugins:/usr/src/app/plugins
    depends_on:
      - postgres
      - redis
      - elasticsearch
    restart: always

  postgres:
    image: postgres:9.4
    volumes:
      - ./postgresql:/var/lib/postgresql/data
    restart: always

  elasticsearch:
    image: elasticsearch:5.6
    environment:
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - ./elasticsearch:/usr/share/elasticsearch/data
    restart: always

  redis:
    image: redis:3.0
    volumes:
      - ./redis:/data
    restart: always

  nginx:
    image: nginx:1.9
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./config/nginx:/etc/nginx/conf.d
      - ./letsencrypt/etc:/etc/letsencrypt
      - ./log:/var/log/nginx
    volumes_from:
      - fabmanager:ro
    links:
      - fabmanager:fabmanager
    restart: always

config/env

POSTGRES_HOST=postgres
REDIS_HOST=redis
ELASTICSEARCH_HOST=elasticsearch

SECRET_KEY_BASE=

STRIPE_API_KEY=
STRIPE_PUBLISHABLE_KEY=
STRIPE_CURRENCY=eur

INVOICE_PREFIX=Demo-FabLab-facture
FABLAB_WITHOUT_PLANS=false
FABLAB_WITHOUT_SPACES=true

DEFAULT_MAIL_FROM=Fab Manager Demo <noreply@fab-manager.com>
DEFAULT_HOST=localhost
DEFAULT_PROTOCOL=http

DELIVERY_METHOD=smtp
SMTP_ADDRESS=smtp.sendgrid.net
SMTP_PORT=587
SMTP_USER_NAME=
SMTP_PASSWORD=
SMTP_AUTHENTICATION=plain
SMTP_ENABLE_STARTTLS_AUTO=true
SMTP_OPENSSL_VERIFY_MODE=

GA_ID=

DISQUS_SHORTNAME=

TWITTER_NAME=FablabGrenoble
TWITTER_CONSUMER_KEY=
TWITTER_CONSUMER_SECRET=
TWITTER_ACCESS_TOKEN=
TWITTER_ACCESS_TOKEN_SECRET=

FACEBOOK_APP_ID=

RAILS_LOCALE=fr
APP_LOCALE=fr
MOMENT_LOCALE=fr
SUMMERNOTE_LOCALE=fr-FR
ANGULAR_LOCALE=fr-fr
MESSAGEFORMAT_LOCALE=fr
FULLCALENDAR_LOCALE=fr

ELASTICSEARCH_LANGUAGE_ANALYZER=french

TIME_ZONE=Paris
WEEK_STARTING_DAY=monday
D3_DATE_FORMAT=%d/%m/%y
UIB_DATE_FORMAT=dd/MM/yyyy
EXCEL_DATE_FORMAT=dd/mm/yyyy

OPENLAB_APP_SECRET=
OPENLAB_APP_ID=
OPENLAB_BASE_URI=https://openprojects.fab-manager.com

NAVINUM_API_LOGIN=
NAVINUM_API_PASSWORD=

LOG_LEVEL=debug


ALLOWED_EXTENSIONS=pdf ai eps cad math svg stl dxf dwg obj step iges igs 3dm 3dmf doc docx png ino scad fcad skp sldprt sldasm slddrw slddrt tex latex ps
ALLOWED_MIME_TYPES=application/pdf application/postscript application/illustrator image/x-eps image/svg+xml application/sla application/dxf application/acad application/dwg application/octet-stream > application/step application/iges model/iges x-world/x-3dmf application/ application/vnd.openxmlformats-officedocument.wordprocessingml.document image/png text/x-arduino text/plain application/scad > application/vnd.sketchup.skp application/x-koan application/vnd-koan koan/x-skm application/vnd.koan application/x-tex application/x-latex

 # 10485760 = 10 megabytes
MAX_IMAGE_SIZE=10485760

config/nginx/fabmanager.conf

upstream puma {
  server fabmanager:3000;
}

server {
  listen 80;
  server_name localhost;
  root /usr/src/app/public;

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  try_files $uri/index.html $uri @puma;
  location @puma {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://puma;
  }

  client_max_body_size 4G;
  keepalive_timeout 10;

  error_page 500 502 504 /500.html;
  error_page 503 @503;

  # Return a 503 error if the maintenance page exists.
  if (-f /usr/src/app/public/maintenance.html) {
    return 503;
  }

  location @503 {
    # Serve static assets if found.
    if (-f $request_filename) {
      break;
    }

    # Set root to the shared directory.
    root /usr/src/app/public/;
    rewrite ^(.*)$ /maintenance.html break;
  }
  
  location /.well-known/acme-challenge {
    root /etc/letsencrypt/webrootauth;
    default_type "text/plain";
  }

  # no spam bot
  if ($http_referer ~* (guardlink.org|free-share-buttons|social-buttons|buy-cheap-online.info|social-buttons.com|free-share-buttons.com|darodar.com|blackhatworth.com|hulfingtonpost.com|priceg.com|semalt> .com|imaspammer.com|iedit.ilovevitaly.com|7makemoneyonline.com|iedit.ilovevitaly.com|7makemoneyonline.com|gamersyde.com|iloveitaly.com|econom.co|semalt.com|forum.topic44637676.darodar.com|darodar.com|> iskalko.ru|ilovevitaly.ru|ilovevitaly.com|ilovevitaly.co|o-o-8-o-o.ru|o-o-6-o-o.ru|buttons-for-website.com|semalt.semalt.com|cenoval.ru|priceg.com|darodar.com|cenokos.ru|seoexperimenty.ru|gobongo.info> |vodkoved.ru|adcash.com|websocial.me|cityadspix.com|luxup.ru|ykecwqlixx.ru|superiends.org|slftsdybbg.ru|edakgfvwql.ru|socialseet.ru|screentoolkit.com|econom.co|semalt.com|savetubevideo.com|shopping.il> ovevitaly.com|iedit.ilovevitaly.com|forum.topic52548358.darodar.com|forum.topic53813291.darodar.com|share-buttons.com|event-tracking.com|success-seo.com|free-floating-buttons.com|get-free-social-traff> ic.com|chinese-amezon.com|get-free-traffic-now.com|free-social-buttons.com|videos-for-your-business.com)) { return 403; }

}

Hi Simon,
What does the following command tells you?

cd /apps/fabmanager
docker-compose ps

Hi Sylvain,

It gives me that:

         Name                       Command               State         Ports
------------------------------------------------------------------------------------
docker_elasticsearch_1   /docker-entrypoint.sh elas ...   Up      9200/tcp, 9300/tcp
docker_postgres_1        docker-entrypoint.sh postgres    Up      5432/tcp
docker_redis_1           docker-entrypoint.sh redis ...   Up      6379/tcp

I’m not sure this is an issue but it’s strange that your containers are prefixed with « docker_ » … They should have been prefixed with « fabmanager_ ». Have you changed something about this?

What does the following command tells you?

docker logs docker_postgres_1

Also, your nginx and fabmanager containers does not appear in the list, can you see them with the following:

docker ps -a

?

My containers was prefixed by « docker_ » because they was in a folder named « docker ». I changed that and they have now the standars tree structure /apps/fabmanager.

That gives me that:

/home/docker/apps/fabmanager # docker-compose ps
           Name                         Command               State         Ports
----------------------------------------------------------------------------------------
fabmanager_elasticsearch_1   /docker-entrypoint.sh elas ...   Up      9200/tcp, 9300/tcp
fabmanager_postgres_1        docker-entrypoint.sh postgres    Up      5432/tcp
fabmanager_redis_1           docker-entrypoint.sh redis ...   Up      6379/tcp

And for the other commands:

/home/docker/apps/fabmanager # docker logs fabmanager_postgres_1
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /var/lib/postgresql/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
creating template1 database in /var/lib/postgresql/data/base/1 ... ok
initializing pg_authid ... ok
setting password ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... ok
creating collations ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
loading PL/pgSQL server-side language ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... ok
initdb: could not fsync file "/var/lib/postgresql/data/base/1": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/base/12136": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/base/12141": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/base": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/global": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/pg_clog": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/pg_dynshmem": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/pg_logical/mappings": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/pg_logical/snapshots": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/pg_logical": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/pg_multixact/members": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/pg_multixact/offsets": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/pg_multixact": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/pg_notify": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/pg_replslot": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/pg_serial": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/pg_snapshots": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/pg_stat": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/pg_stat_tmp": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/pg_subtrans": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/pg_tblspc": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/pg_twophase": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/pg_xlog/archive_status": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/pg_xlog": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/pg_tblspc": Invalid argument

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.
syncing data to disk ... ok

Success. You can now start the database server using:

    postgres -D /var/lib/postgresql/data
or
    pg_ctl -D /var/lib/postgresql/data -l logfile start

****************************************************
WARNING: No password has been set for the database.
         This will allow anyone with access to the
         Postgres port to access your database. In
         Docker's default configuration, this is
         effectively any other container on the same
         system.

         Use "-e POSTGRES_PASSWORD=password" to set
         it in "docker run".
****************************************************
waiting for server to start....FATAL:  data directory "/var/lib/postgresql/data" has wrong ownership
HINT:  The server must be started by the user that owns the data directory.
 stopped waiting
pg_ctl: could not start server
Examine the log output.
FATAL:  data directory "/var/lib/postgresql/data" has wrong ownership
HINT:  The server must be started by the user that owns the data directory.
FATAL:  data directory "/var/lib/postgresql/data" has wrong ownership
HINT:  The server must be started by the user that owns the data directory.
FATAL:  data directory "/var/lib/postgresql/data" has wrong ownership
HINT:  The server must be started by the user that owns the data directory.
FATAL:  data directory "/var/lib/postgresql/data" has wrong ownership
HINT:  The server must be started by the user that owns the data directory.
FATAL:  data directory "/var/lib/postgresql/data" has wrong ownership
HINT:  The server must be started by the user that owns the data directory.
FATAL:  data directory "/var/lib/postgresql/data" has wrong ownership
HINT:  The server must be started by the user that owns the data directory.
FATAL:  data directory "/var/lib/postgresql/data" has wrong ownership
HINT:  The server must be started by the user that owns the data directory.
FATAL:  data directory "/var/lib/postgresql/data" has wrong ownership
HINT:  The server must be started by the user that owns the data directory.
FATAL:  data directory "/var/lib/postgresql/data" has wrong ownership
HINT:  The server must be started by the user that owns the data directory.
FATAL:  data directory "/var/lib/postgresql/data" has wrong ownership
HINT:  The server must be started by the user that owns the data directory.
FATAL:  data directory "/var/lib/postgresql/data" has wrong ownership
HINT:  The server must be started by the user that owns the data directory.
FATAL:  data directory "/var/lib/postgresql/data" has wrong ownership
HINT:  The server must be started by the user that owns the data directory.
/home/docker/apps/fabmanager # docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                NAMES
4770863c54cf        elasticsearch:5.6   "/docker-entrypoint.…"   6 minutes ago       Up 6 minutes        9200/tcp, 9300/tcp   fabmanager_elasticsearch_1
9ccc55df139c        redis:3.0           "docker-entrypoint.s…"   6 minutes ago       Up 6 minutes        6379/tcp             fabmanager_redis_1
8c49b00c352c        postgres:9.4        "docker-entrypoint.s…"   6 minutes ago       Up 1 second         5432/tcp             fabmanager_postgres_1

Thank you very much for your help !

The problem may probably be the following:

If you look into your docker-compose.yml file, /var/lib/postgresql/data is mapped to your local folder ./postgresql. Check the existance and the access rights for this directory…

I found it!

I work on docker for Windows and apparently mounted volumes generate problems. I use COPY now and I can execute this command normaly.

Thanks Sylvain!

1 « J'aime »