# Problem PG::ConnectionBad when merging two forums despite several previous successes

**URL:** <https://meta.discourse.org/t/problem-pg-connectionbad-when-merging-two-forums-despite-several-previous-successes/235173>\
**Category:** Self-hosting\
**Created:** [August 4, 2022, 10:03pm UTC](https://meta.discourse.org/t/problem-pg-connectionbad-when-merging-two-forums-despite-several-previous-successes/235173 "2022-08-04T22:03:18Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![cocococosti](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cocococosti/32/231474_2.png) [@cocococosti](https://meta.discourse.org/u/cocococosti)\
**Post date:** [August 5, 2022, 9:41pm UTC](https://meta.discourse.org/t/problem-pg-connectionbad-when-merging-two-forums-despite-several-previous-successes/235173/3 "2022-08-05T21:41:50Z")

</div>

I got the same error. Seems like the port is not being loaded in the DB configs here: [discourse/script/bulk\_import/discourse\_merger.rb at main · discourse/discourse · GitHub](https://github.com/discourse/discourse/blob/main/script/bulk_import/discourse_merger.rb#L21)

If you run that from a rails console:

```plaintext
[1] pry(main)> ActiveRecord::Base.connection_db_config.configuration_hash
=> {:prepared_statements=>false,
 :adapter=>"postgresql",
 :database=>"discourse_development",
 :min_messages=>"warning",
 :pool=>5,
 :timeout=>5000,
 :checkout_timeout=>5,
 :advisory_locks=>false,
 :host_names=>["localhost"],
 :variables=>{}}

```

The port is not in the config, but the code assumes it is: [discourse/script/bulk\_import/discourse\_merger.rb at main · discourse/discourse · GitHub](https://github.com/discourse/discourse/blob/main/script/bulk_import/discourse_merger.rb#L22)

While this is fixed in core, you can put the port manually, so instead of

```plaintext
 @raw_connection = PG.connect(dbname: local_db[:database], host: 'localhost', port: local_db[:port], user: 'postgres', password: db_password)

```

use:

```plaintext
@raw_connection = PG.connect(dbname: local_db[:database], host: 'localhost', port: 5432, user: 'postgres', password: db_password)

```

---

_[View the full topic](https://meta.discourse.org/t/problem-pg-connectionbad-when-merging-two-forums-despite-several-previous-successes/235173)._
