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

Hello,

Having already done a merge of two forums in April, on a test server, which went very well. We decided to merge the two forums for good.

Following my procedure of the time, I find myself with a connection error to Postgres, when launching the merge script.

I’ve been at it for four days now, but not being a developer, I’m a bit limited in finding the problem.

Thanks for advance

Here is the error:

discourse@serveur-app:/var/www/discourse$ IMPORT=1 DB_NAME=copyme DB_PASS=passwdDB SOURCE_BASE_URL=http://old.forum.fr UPLOADS_PATH=/var/www/discourse/public/uploads/default bundle exec ruby script/bulk_import/discourse_merger.rb
Loading application...
Traceback (most recent call last):
	5: from script/bulk_import/discourse_merger.rb:817:in `<main>'
	4: from script/bulk_import/discourse_merger.rb:817:in `new'
	3: from script/bulk_import/discourse_merger.rb:22:in `initialize'
	2: from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/pg-1.4.2/lib/pg.rb:69:in `connect'
	1: from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/pg-1.4.2/lib/pg/connection.rb:661:in `new'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/pg-1.4.2/lib/pg/connection.rb:708:in `connect_to_hosts': could not match 0 port numbers to 1 hosts (PG::ConnectionBad)


I take this opportunity to put the complete merger procedure.

This procedure is based on the original post and the problems encountered during my tests

This procedure worked in April (see this topic).

  • Start with updated backups of the two forums,
  • Install a discourse,
  • Import the two backups,
  • Restore the forum to keep.

In SSH :

  • Go to the /var/discourse folder
  • Enter the app ./launcher enter app.

Create the DB.

su postgres
psql
CREATE DATABASE copyme ENCODING='utf8';

Change the password of the postgres user

\postgres password

Exit postgres

\q

Exit the postgres user

exit

Switch to the discourse user

su discourse

OLD forum save decompression
Go to the latter folder cd public/backups/default
Extract the OLD backup via the command tar xvzf old.forum.tar.gz

Copy from BDD.lu to BDD copyme.

gunzip < dump.sql.gz | psql -d copyme

Exit user discourse

exit

Dependencies

nano, sqlite3 and mysql2 dependencies
(with root user in /var/www/discourse)

apt update && apt upgrade -y
apt-get install -y nano sqlite3 libsqlite3-dev mariadb-server libmariadb-dev -y
gem install sqlite3 mysql2

ruby bbcode to md

git clone https://github.com/nlalonde/ruby-bbcode-to-md.git
cd ruby-bbcode-to-md/
gem build ruby-bbcode-to-md.gemspec
gem install ruby-bbcode-to-md-*.gem
cd ./..

Installing Tiny_tds
You have to install FreeTDS then Tiny_tds.
For FreeTDS:

wget http://www.freetds.org/files/stable/freetds-1.3.12.tar.gz
tar -xzf freetds-1.3.12.tar.gz
cd freetds-1.3.12
./configure --prefix=/usr/local --with-tdsver=7.3
make
make install

For Tiny_tds :

gem install tiny_tds
gem install ruby-bbcode-to-md
cd ./..

The script

su discourse
bundle config unset deployment
IMPORT=1 bundle install
IMPORT=1 DB_NAME=copyme DB_PASS=passwdDB SOURCE_BASE_URL=http://old.forum.fr UPLOADS_PATH=/var/www/discourse/public/uploads/default bundle exec ruby script/bulk_import/discourse_merger.rb

Translated with www.DeepL.com/Translator (free version)
1 Like

Hi,

Postgres does use port 5432 (check via \conninfo in psql command), but I’m afraid in the connection.rb file it calls port 5433.

The password is good checked with the command psql postgres://postgres:password@127.0.0.1:5432

Can anyone confirm that there is no error in the port?

Thanks in advance

1 Like

I got the same error. Seems like the port is not being loaded in the DB configs here: discourse/discourse_merger.rb at main · discourse/discourse · GitHub

If you run that from a rails console:

[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/discourse_merger.rb at main · discourse/discourse · GitHub

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

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

use:

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

Thnaks thanks thanks

I tryed with port = 5432 but not port = 5432

by dint of having our head in the handlebars we miss things

thanks again

2 Likes