Today we (@oyierphil @kitsao @mrjones & Elias) spent some time debugging directly running couch2pg from a repository clone and these are our findings:
1. NodeJS version
Couch2pg has an implicit dependency on the NodeJS version in use. We discovered that versions 10 and 12 work well, while 14 and 16 fail silently. To conveniently switch between node versions, nvm
is highly recommended. Installation instructions here.
2. Postgres authentication
Running couch2pg with the right node version may also lead to the error below being thrown:
[2022-02-28T08:11:31.910Z DEBUG]: { debug: true,
v4Mode: false,
couchdbUrl: '<cht-instance>/medic',
postgresqlUrl: '<pg-instance>/monday',
docLimit: 1000,
changesLimit: undefined,
retryCount: 5,
sleepMins: 120,
couchdbUsersMetaDocLimit: 50 }
<couch2pg path>/node_modules/couch2pg/node_modules/pg/lib/connection.js:426
throw new Error("Unknown authenticationOk message type" + util.inspect(msg));
^
Error: Unknown authenticationOk message typeMessage { name: 'authenticationOk', length: 23 }
at Connection.parseR (<couch2pg path>/node_modules/couch2pg/node_modules/pg/lib/connection.js:426:9)
at Connection.parseMessage (<couch2pg path>/node_modules/couch2pg/node_modules/pg/lib/connection.js:345:17)
at Socket.<anonymous> (<couch2pg path>/node_modules/couch2pg/node_modules/pg/lib/connection.js:105:22)
at Socket.emit (events.js:198:13)
at addChunk (_stream_readable.js:288:12)
at readableAddChunk (_stream_readable.js:269:11)
at Socket.Readable.push (_stream_readable.js:224:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
Observe the message:
Unknown authenticationOk message
This means that postgres is setup to use a different password encryption algorithm compared to what couch2pg uses. Couch2pg was made to work with md5 which is the default method in postgres v10-13. However, on postgres v14 the default method is scram-sha-256 detailed here.
The setting can be updated in the postgres configuration file which is in /etc/postgresql/14/main/postgres.conf
in Ubuntu 20.04. The key password_encryption should be set to md5. After updating the setting, the postgres service needs to be restarted for it to take effect using:
systemctl restart postgresql
To confirm that the role used with couch2pg has an md5 encrypted password use this query:
SELECT rolname, rolpassword FROM pg_authid
The role password should start with md5.
A successful run will produce logs like this:
[11:13:17 AM] table couch2pg_migrations does not exist - creating it.
[11:13:17 AM] version of database is: 0
[11:13:17 AM] migrating up to 201803202020
[11:13:17 AM] running 201606091247.do.2318-standardise-schema.sql
[11:13:17 AM] running 201606091248.do.2124-support-edit-and-delete-of-documents.sql
[11:13:17 AM] running 201607132040.do.2506-unique-id-constraint.sql
[11:13:17 AM] running 201607210832.do.2523-remove-unused-index.sql
[11:13:17 AM] running 201611271809.do.2923-couch2-support.sql
[11:13:17 AM] running 201803202020.do.3423-multiple-db-support.sql
and will continue to pull documents from CouchDB.
Following this up in #35.
Let us know if this works. Thank you for your patience.