# PG::UnableToSend: server closed the connection unexpectedly

**URL:** https://meta.discourse.org/t/pg-server-closed-the-connection-unexpectedly/121531
**Category:** Self-hosting
**Created:** [6월 27, 2019, 8:59오후 UTC](https://meta.discourse.org/t/pg-server-closed-the-connection-unexpectedly/121531 "2019-06-27T20:59:59Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![yanokwa](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/yanokwa/32/105083_2.png) [@yanokwa](https://meta.discourse.org/u/yanokwa)
#### Post date: [6월 27, 2019, 9:00오후 UTC](https://meta.discourse.org/t/pg-server-closed-the-connection-unexpectedly/121531/1 "2019-06-27T21:00:00Z")

</div>

Running v2.4.0.beta1 +29

```plaintext
/var/www/discourse# rake uploads:recover_from_tombstone --trace

** Invoke uploads:recover_from_tombstone (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute uploads:recover_from_tombstone
** Invoke uploads:recover (first_time)
** Invoke environment
** Execute uploads:recover
rake aborted!
ActiveRecord::StatementInvalid: PG::UnableToSend: server closed the connection unexpectedly
	This probably means the server terminated abnormally
	before or while processing the request.
: SELECT "uploads".* FROM "uploads" WHERE "uploads"."sha1" = '25448339cd2057cd70b9b28ae64a1019bff12b34' LIMIT 1
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rack-mini-profiler-1.0.2/lib/patches/db/pg.rb:69:in `async_exec_params'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rack-mini-profiler-1.0.2/lib/patches/db/pg.rb:69:in `exec_params'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:611:in `block (2 levels) in exec_no_cache'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies/interlock.rb:48:in `block in permit_concurrent_loads'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/concurrency/share_lock.rb:187:in `yield_shares'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies/interlock.rb:47:in `permit_concurrent_loads'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:610:in `block in exec_no_cache'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract_adapter.rb:581:in `block (2 levels) in log'
/usr/local/lib/ruby/2.6.0/monitor.rb:230:in `mon_synchronize'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract_adapter.rb:580:in `block in log'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/notifications/instrumenter.rb:23:in `instrument'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract_adapter.rb:571:in `log'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:609:in `exec_no_cache'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:596:in `execute_and_clear'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql/database_statements.rb:81:in `exec_query'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/database_statements.rb:478:in `select'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/database_statements.rb:70:in `select_all'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/query_cache.rb:106:in `select_all'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/querying.rb:41:in `find_by_sql'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/statement_cache.rb:108:in `execute'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/core.rb:208:in `find_by'
/var/www/discourse/lib/upload_creator.rb:70:in `block in create_for'
/var/www/discourse/lib/distributed_mutex.rb:42:in `synchronize'
/var/www/discourse/lib/distributed_mutex.rb:12:in `synchronize'
/var/www/discourse/lib/upload_creator.rb:37:in `create_for'
/var/www/discourse/lib/upload_recovery.rb:178:in `create_upload'
/var/www/discourse/lib/upload_recovery.rb:124:in `block in recover_from_local'
/var/www/discourse/lib/upload_recovery.rb:117:in `each'
/var/www/discourse/lib/upload_recovery.rb:117:in `recover_from_local'
/var/www/discourse/lib/upload_recovery.rb:84:in `recover_post_upload_from_local'
/var/www/discourse/lib/upload_recovery.rb:62:in `recover_post_upload'
/var/www/discourse/lib/upload_recovery.rb:25:in `block (2 levels) in recover'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/nokogiri-1.10.3/lib/nokogiri/xml/node_set.rb:238:in `block in each'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/nokogiri-1.10.3/lib/nokogiri/xml/node_set.rb:237:in `upto'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/nokogiri-1.10.3/lib/nokogiri/xml/node_set.rb:237:in `each'
/var/www/discourse/lib/upload_recovery.rb:14:in `block in recover'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/relation/batches.rb:70:in `block (2 levels) in find_each'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/relation/batches.rb:70:in `each'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/relation/batches.rb:70:in `block in find_each'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/relation/batches.rb:136:in `block in find_in_batches'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/relation/batches.rb:238:in `block in in_batches'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/relation/batches.rb:222:in `loop'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/relation/batches.rb:222:in `in_batches'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/relation/batches.rb:135:in `find_in_batches'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/relation/batches.rb:69:in `find_each'
/var/www/discourse/lib/upload_recovery.rb:9:in `recover'
/var/www/discourse/lib/tasks/uploads.rake:906:in `block (2 levels) in <top (required)>'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rails_multisite-2.0.7/lib/rails_multisite/connection_management.rb:63:in `with_connection'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rails_multisite-2.0.7/lib/rails_multisite/connection_management.rb:73:in `each_connection'
/var/www/discourse/lib/tasks/uploads.rake:905:in `block in <top (required)>'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:273:in `block in execute'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:273:in `each'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:273:in `execute'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:214:in `block in invoke_with_call_chain'
/usr/local/lib/ruby/2.6.0/monitor.rb:230:in `mon_synchronize'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:194:in `invoke_with_call_chain'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:183:in `invoke'
/var/www/discourse/lib/tasks/uploads.rake:894:in `block in <top (required)>'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:273:in `block in execute'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:273:in `each'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:273:in `execute'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:214:in `block in invoke_with_call_chain'
/usr/local/lib/ruby/2.6.0/monitor.rb:230:in `mon_synchronize'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:194:in `invoke_with_call_chain'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:183:in `invoke'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:160:in `invoke_task'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:116:in `block (2 levels) in top_level'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:116:in `each'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:116:in `block in top_level'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:125:in `run_with_threads'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:110:in `top_level'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:83:in `block in run'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:186:in `standard_exception_handling'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:80:in `run'
bin/rake:13:in `<top (required)>'
/usr/local/lib/ruby/2.6.0/bundler/cli/exec.rb:74:in `load'
/usr/local/lib/ruby/2.6.0/bundler/cli/exec.rb:74:in `kernel_load'
/usr/local/lib/ruby/2.6.0/bundler/cli/exec.rb:28:in `run'
/usr/local/lib/ruby/2.6.0/bundler/cli.rb:463:in `exec'
/usr/local/lib/ruby/2.6.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/usr/local/lib/ruby/2.6.0/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
/usr/local/lib/ruby/2.6.0/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
/usr/local/lib/ruby/2.6.0/bundler/cli.rb:27:in `dispatch'
/usr/local/lib/ruby/2.6.0/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
/usr/local/lib/ruby/2.6.0/bundler/cli.rb:18:in `start'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-1.17.2/exe/bundle:30:in `block in <top (required)>'
/usr/local/lib/ruby/2.6.0/bundler/friendly_errors.rb:124:in `with_friendly_errors'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-1.17.2/exe/bundle:22:in `<top (required)>'
/usr/local/bin/bundle:23:in `load'
/usr/local/bin/bundle:23:in `<main>'

Caused by:
PG::UnableToSend: server closed the connection unexpectedly
	This probably means the server terminated abnormally
	before or while processing the request.
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rack-mini-profiler-1.0.2/lib/patches/db/pg.rb:69:in `async_exec_params'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rack-mini-profiler-1.0.2/lib/patches/db/pg.rb:69:in `exec_params'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:611:in `block (2 levels) in exec_no_cache'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies/interlock.rb:48:in `block in permit_concurrent_loads'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/concurrency/share_lock.rb:187:in `yield_shares'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies/interlock.rb:47:in `permit_concurrent_loads'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:610:in `block in exec_no_cache'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract_adapter.rb:581:in `block (2 levels) in log'
/usr/local/lib/ruby/2.6.0/monitor.rb:230:in `mon_synchronize'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract_adapter.rb:580:in `block in log'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/notifications/instrumenter.rb:23:in `instrument'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract_adapter.rb:571:in `log'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:609:in `exec_no_cache'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:596:in `execute_and_clear'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql/database_statements.rb:81:in `exec_query'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/database_statements.rb:478:in `select'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/database_statements.rb:70:in `select_all'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/query_cache.rb:106:in `select_all'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/querying.rb:41:in `find_by_sql'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/statement_cache.rb:108:in `execute'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/core.rb:208:in `find_by'
/var/www/discourse/lib/upload_creator.rb:70:in `block in create_for'
/var/www/discourse/lib/distributed_mutex.rb:42:in `synchronize'
/var/www/discourse/lib/distributed_mutex.rb:12:in `synchronize'
/var/www/discourse/lib/upload_creator.rb:37:in `create_for'
/var/www/discourse/lib/upload_recovery.rb:178:in `create_upload'
/var/www/discourse/lib/upload_recovery.rb:124:in `block in recover_from_local'
/var/www/discourse/lib/upload_recovery.rb:117:in `each'
/var/www/discourse/lib/upload_recovery.rb:117:in `recover_from_local'
/var/www/discourse/lib/upload_recovery.rb:84:in `recover_post_upload_from_local'
/var/www/discourse/lib/upload_recovery.rb:62:in `recover_post_upload'
/var/www/discourse/lib/upload_recovery.rb:25:in `block (2 levels) in recover'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/nokogiri-1.10.3/lib/nokogiri/xml/node_set.rb:238:in `block in each'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/nokogiri-1.10.3/lib/nokogiri/xml/node_set.rb:237:in `upto'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/nokogiri-1.10.3/lib/nokogiri/xml/node_set.rb:237:in `each'
/var/www/discourse/lib/upload_recovery.rb:14:in `block in recover'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/relation/batches.rb:70:in `block (2 levels) in find_each'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/relation/batches.rb:70:in `each'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/relation/batches.rb:70:in `block in find_each'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/relation/batches.rb:136:in `block in find_in_batches'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/relation/batches.rb:238:in `block in in_batches'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/relation/batches.rb:222:in `loop'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/relation/batches.rb:222:in `in_batches'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/relation/batches.rb:135:in `find_in_batches'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/relation/batches.rb:69:in `find_each'
/var/www/discourse/lib/upload_recovery.rb:9:in `recover'
/var/www/discourse/lib/tasks/uploads.rake:906:in `block (2 levels) in <top (required)>'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rails_multisite-2.0.7/lib/rails_multisite/connection_management.rb:63:in `with_connection'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rails_multisite-2.0.7/lib/rails_multisite/connection_management.rb:73:in `each_connection'
/var/www/discourse/lib/tasks/uploads.rake:905:in `block in <top (required)>'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:273:in `block in execute'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:273:in `each'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:273:in `execute'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:214:in `block in invoke_with_call_chain'
/usr/local/lib/ruby/2.6.0/monitor.rb:230:in `mon_synchronize'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:194:in `invoke_with_call_chain'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:183:in `invoke'
/var/www/discourse/lib/tasks/uploads.rake:894:in `block in <top (required)>'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:273:in `block in execute'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:273:in `each'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:273:in `execute'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:214:in `block in invoke_with_call_chain'
/usr/local/lib/ruby/2.6.0/monitor.rb:230:in `mon_synchronize'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:194:in `invoke_with_call_chain'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/lib/rake/task.rb:183:in `invoke'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:160:in `invoke_task'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:116:in `block (2 levels) in top_level'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:116:in `each'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:116:in `block in top_level'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:125:in `run_with_threads'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:110:in `top_level'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:83:in `block in run'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:186:in `standard_exception_handling'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:80:in `run'
bin/rake:13:in `<top (required)>'
/usr/local/lib/ruby/2.6.0/bundler/cli/exec.rb:74:in `load'
/usr/local/lib/ruby/2.6.0/bundler/cli/exec.rb:74:in `kernel_load'
/usr/local/lib/ruby/2.6.0/bundler/cli/exec.rb:28:in `run'
/usr/local/lib/ruby/2.6.0/bundler/cli.rb:463:in `exec'
/usr/local/lib/ruby/2.6.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/usr/local/lib/ruby/2.6.0/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
/usr/local/lib/ruby/2.6.0/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
/usr/local/lib/ruby/2.6.0/bundler/cli.rb:27:in `dispatch'
/usr/local/lib/ruby/2.6.0/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
/usr/local/lib/ruby/2.6.0/bundler/cli.rb:18:in `start'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-1.17.2/exe/bundle:30:in `block in <top (required)>'
/usr/local/lib/ruby/2.6.0/bundler/friendly_errors.rb:124:in `with_friendly_errors'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-1.17.2/exe/bundle:22:in `<top (required)>'
/usr/local/bin/bundle:23:in `load'
/usr/local/bin/bundle:23:in `<main>'
Tasks: TOP => uploads:recover
```

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [6월 27, 2019, 10:11오후 UTC](https://meta.discourse.org/t/pg-server-closed-the-connection-unexpectedly/121531/2 "2019-06-27T22:11:26Z")

</div>

Did you try it more than once and get the same error at the same place?

---

<div class="post-metadata">

### Author: ![yanokwa](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/yanokwa/32/105083_2.png) [@yanokwa](https://meta.discourse.org/u/yanokwa)
#### Post date: [6월 28, 2019, 12:11오전 UTC](https://meta.discourse.org/t/pg-server-closed-the-connection-unexpectedly/121531/3 "2019-06-28T00:11:02Z")

</div>

Great question, @pfaffman.

Same error, but crashes in a different spot.

```plaintext
ActiveRecord::StatementInvalid: PG::ConnectionBad: PQconsumeInput() server closed the connection unexpectedly
	This probably means the server terminated abnormally
	before or while processing the request.
: SELECT "user_uploads".* FROM "user_uploads" WHERE "user_uploads"."user_id" = 1221 AND "user_uploads"."upload_id" = 28216 LIMIT 1

```

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [6월 28, 2019, 1:03오전 UTC](https://meta.discourse.org/t/pg-server-closed-the-connection-unexpectedly/121531/4 "2019-06-28T01:03:00Z")

</div>

How did you install discourse?

---

<div class="post-metadata">

### Author: ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)
#### Post date: [6월 28, 2019, 1:33오전 UTC](https://meta.discourse.org/t/pg-server-closed-the-connection-unexpectedly/121531/5 "2019-06-28T01:33:51Z")

</div>

This is not a crash per se:

> [@yanokwa](#):
>
> Caused by: PG::UnableToSend: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request.

The postgres DB going away is not something that we normally see.

How did you install? What is different/custom about your setup?

---

<div class="post-metadata">

### Author: ![yanokwa](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/yanokwa/32/105083_2.png) [@yanokwa](https://meta.discourse.org/u/yanokwa)
#### Post date: [6월 28, 2019, 2:01오전 UTC](https://meta.discourse.org/t/pg-server-closed-the-connection-unexpectedly/121531/6 "2019-06-28T02:01:56Z")

</div>

Very stock [cloud install](https://github.com/discourse/discourse/blob/master/docs/INSTALL-cloud.md).  
Here’s discourse-doctor’s output.

```plaintext
DISCOURSE DOCTOR Fri Jun 28 02:00:11 UTC 2019
OS: Linux community.example.org 4.4.0-151-generic #178-Ubuntu SMP Tue Jun 11 08:30:22 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

Found containers/app.yml

==================== YML SETTINGS ====================
DISCOURSE_HOSTNAME=community.example.org
SMTP_ADDRESS=smtp.mailgun.org
DEVELOPER_EMAILS=REDACTED 
SMTP_PASSWORD=REDACTED 
SMTP_PORT=587
SMTP_USER_NAME=postmaster@community.example.org
LETSENCRYPT_ACCOUNT_EMAIL=REDACTED 

==================== DOCKER INFO ====================
DOCKER VERSION: Docker version 18.09.6, build 481bc77

DOCKER PROCESSES (docker ps -a)

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c8d61fb69150 local_discourse/app "/sbin/boot" 2 months ago Up About a minute 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp app
612da87d4e61 local_discourse/mail-receiver "/sbin/boot" 14 months ago Up About a minute 0.0.0.0:25->25/tcp mail-receiver

Discourse container app is running

==================== PLUGINS ====================
          - git clone https://github.com/discourse/docker_manager.git
          - git clone https://github.com/angusmcleod/discourse-legal-tools.git
          - git clone https://github.com/angusmcleod/discourse-custom-wizard.git
          - git clone https://github.com/discourse/discourse-solved.git

WARNING:
You have what appear to be non-official plugins.
If you are having trouble, you should disable them and try rebuilding again.

See https://github.com/discourse/discourse/blob/master/lib/plugin/metadata.rb for the official list.

========================================
Discourse version at community.example.org: Discourse 2.4.0.beta1 
Discourse version at localhost: Discourse 2.4.0.beta1 

==================== MEMORY INFORMATION ====================
OS: Linux
RAM (MB): 4046

              total used free shared buff/cache available
Mem: 3951 1226 1359 64 1364 2356
Swap: 0 0 0

==================== DISK SPACE CHECK ====================
---------- OS Disk Space ----------
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 60G 14G 43G 24% /

---------- Container Disk Space ----------
Filesystem Size Used Avail Use% Mounted on
overlay 60G 14G 43G 24% /
/dev/vda1 60G 14G 43G 24% /shared
/dev/vda1 60G 14G 43G 24% /var/log

==================== DISK INFORMATION ====================
Disk /dev/vda: 60 GiB, 64424509440 bytes, 125829120 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xc4c394c3

Device Boot Start End Sectors Size Id Type
/dev/vda1 * 2048 125829086 125827039 60G 83 Linux

==================== END DISK INFORMATION ====================

==================== MAIL TEST ====================
For a robust test, get an address from http://www.mail-tester.com/
Mail test skipped.

==================== DONE! ====================

```

---

<div class="post-metadata">

### Author: ![yanokwa](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/yanokwa/32/105083_2.png) [@yanokwa](https://meta.discourse.org/u/yanokwa)
#### Post date: [6월 28, 2019, 3:38오전 UTC](https://meta.discourse.org/t/pg-server-closed-the-connection-unexpectedly/121531/7 "2019-06-28T03:38:34Z")

</div>

Reboot seems to have solve the problem. Thanks for the hints everyone!

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [12월 19, 2022, 12:47오후 UTC](https://meta.discourse.org/t/pg-server-closed-the-connection-unexpectedly/121531/8 "2022-12-19T12:47:10Z")

</div>



---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [12월 19, 2022, 1:14오후 UTC](https://meta.discourse.org/t/pg-server-closed-the-connection-unexpectedly/121531/9 "2022-12-19T13:14:03Z")

</div>


