Read-only replica of couchDB docs into postgres for data-visualization

@cliff - Thanks for your follow up on your progress!

As you may have noticed, just last week we finished updating the readme you linked to. The updates were needed because we improved a lot of the logic in the entry point of the docker image and renamed some of the environment variables to be clear of what their use is. These changes were completed 11th of March (see tickets 1, 2 and 3 and 1 PR).

Given these changes, I suspect you have both an out of date compose file and out of date containers. Can you please ensure you have this new compose file? That compose file references the new tag on the image (master-node-10main-node-10), so when you run docker-compose up, the command will force your docker to download the new image. Finally, if you don’t have any important data in postgres, can you delete the postgres container and data volume? If you want to be thorough, you can delete all the couch2pg containers and images. For me, a complete reset looks like this:

  1. first list your images with ps
    $ docker ps --format="{{.Names}} {{.Status}}"
    
    cht-couch2pg_postgres_1 Up About a minute
    cht-couch2pg_cht-couch2pg_1 Up About a minute
    helper_test_medic-os_1 Up 14 minutes
    helper_test_haproxy_1 Up 14 minutes
    
  2. we want to delete the first to, so we’ll do an rm with the force flag (be sure you want to do this!)
    docker rm -f cht-couch2pg_postgres_1 cht-couch2pg_cht-couch2pg_1
    
    cht-couch2pg_postgres_1
    cht-couch2pg_cht-couch2pg_1
    
  3. Then we want to list the volumes to find the postgres one:
    $ docker volume ls
    
    DRIVER    VOLUME NAME
    local     cht-postgres-data
    local     helper_test_medic-data
    
  4. we want to delete the postgres one, so we’ll call rm again passing the force flag (and again, be sure you want to do this!):
    $ docker volume rm -f cht-postgres-data
    cht-postgres-data
    
  5. Let’s fetch and pull in git to make sure we’re up to date
    $ git fetch&&git pull origin main
    From github.com:medic/cht-couch2pg
     * branch            main       -> FETCH_HEAD
    Already up to date.
    
  6. Finally, let’s restart our compose services, passing in the URL for our couch instance via COUCHDB_URL, ensuring it starts with the login and password and ends in /medic with out the trailing slash:
    $ cht-couch2pg git:(main) COUCHDB_URL=https://medic:password@192-168-68-17.my.local-ip.co:8443/medic docker-compose up
    
    

To give you an idea of the happy path result, this is what we should expect if it all works:

Creating volume "cht-postgres-data" with default driver
Creating cht-couch2pg_postgres_1 ... done
Creating cht-couch2pg_cht-couch2pg_1 ... done
Attaching to cht-couch2pg_postgres_1, cht-couch2pg_cht-couch2pg_1
postgres_1      | The files belonging to this database system will be owned by user "postgres".
postgres_1      | This user must also own the server process.
postgres_1      | 
postgres_1      | The database cluster will be initialized with locale "en_US.utf8".
postgres_1      | The default database encoding has accordingly been set to "UTF8".
postgres_1      | The default text search configuration will be set to "english".
postgres_1      | 
postgres_1      | Data page checksums are disabled.
postgres_1      | 
postgres_1      | fixing permissions on existing directory /var/lib/postgresql/data ... ok
postgres_1      | creating subdirectories ... ok
postgres_1      | selecting dynamic shared memory implementation ... posix
cht-couch2pg_1  | Starting couch2pg process
cht-couch2pg_1  | Set postgres URL to postgres://cht_couch2pg:cht_couch2pg_password@postgres:5432/cht
cht-couch2pg_1  | START Checking for cht couchdb at https://medic:password@192-168-68-17.my.local-ip.co:8443/medic
postgres_1      | selecting default max_connections ... 100
postgres_1      | selecting default shared_buffers ... 128MB
postgres_1      | selecting default time zone ... Etc/UTC
postgres_1      | creating configuration files ... ok
postgres_1      | running bootstrap script ... ok
postgres_1      | performing post-bootstrap initialization ... ok
postgres_1      | syncing data to disk ... ok
postgres_1      | 
postgres_1      | 
postgres_1      | Success. You can now start the database server using:
postgres_1      | 
postgres_1      |     pg_ctl -D /var/lib/postgresql/data -l logfile start
postgres_1      | 
postgres_1      | initdb: warning: enabling "trust" authentication for local connections
postgres_1      | You can change this by editing pg_hba.conf or using the option -A, or
postgres_1      | --auth-local and --auth-host, the next time you run initdb.
postgres_1      | waiting for server to start....2022-03-15 22:22:00.254 UTC [47] LOG:  starting PostgreSQL 13.3 (Debian 13.3-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
postgres_1      | 2022-03-15 22:22:00.255 UTC [47] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres_1      | 2022-03-15 22:22:00.259 UTC [48] LOG:  database system was shut down at 2022-03-15 22:22:00 UTC
postgres_1      | 2022-03-15 22:22:00.263 UTC [47] LOG:  database system is ready to accept connections
postgres_1      |  done
postgres_1      | server started
postgres_1      | CREATE DATABASE
postgres_1      | 
postgres_1      | 
postgres_1      | /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/init-user-db.sh
postgres_1      | CREATE ROLE
postgres_1      | CREATE ROLE
postgres_1      | GRANT
postgres_1      | GRANT ROLE
postgres_1      | 
postgres_1      | 2022-03-15 22:22:00.548 UTC [47] LOG:  received fast shutdown request
postgres_1      | waiting for server to shut down....2022-03-15 22:22:00.549 UTC [47] LOG:  aborting any active transactions
postgres_1      | 2022-03-15 22:22:00.550 UTC [47] LOG:  background worker "logical replication launcher" (PID 54) exited with exit code 1
postgres_1      | 2022-03-15 22:22:00.551 UTC [49] LOG:  shutting down
postgres_1      | 2022-03-15 22:22:00.564 UTC [47] LOG:  database system is shut down
postgres_1      |  done
postgres_1      | server stopped
postgres_1      | 
postgres_1      | PostgreSQL init process complete; ready for start up.
postgres_1      | 
postgres_1      | 2022-03-15 22:22:00.679 UTC [1] LOG:  starting PostgreSQL 13.3 (Debian 13.3-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
postgres_1      | 2022-03-15 22:22:00.679 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
postgres_1      | 2022-03-15 22:22:00.679 UTC [1] LOG:  listening on IPv6 address "::", port 5432
postgres_1      | 2022-03-15 22:22:00.682 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres_1      | 2022-03-15 22:22:00.686 UTC [85] LOG:  database system was shut down at 2022-03-15 22:22:00 UTC
postgres_1      | 2022-03-15 22:22:00.693 UTC [1] LOG:  database system is ready to accept connections
cht-couch2pg_1  | couchdb  is ready
cht-couch2pg_1  | check_if_postgres_is_ready with "pg_isready -q  -h postgres -U cht_couch2pg --d cht"
cht-couch2pg_1  | Postgres is ready moving on ...
cht-couch2pg_1  | Launching couch2pg
cht-couch2pg_1  | [2022-03-15T22:22:01.755Z DEBUG]:  { debug: true,
cht-couch2pg_1  |   v4Mode: false,
cht-couch2pg_1  |   couchdbUrl: '192-168-68-17.my.local-ip.co:8443/medic',
cht-couch2pg_1  |   postgresqlUrl: 'postgres:5432/cht',
cht-couch2pg_1  |   docLimit: 1000,
cht-couch2pg_1  |   changesLimit: 100,
cht-couch2pg_1  |   retryCount: 5,
cht-couch2pg_1  |   sleepMins: 60,
cht-couch2pg_1  |   couchdbUsersMetaDocLimit: 50 }
cht-couch2pg_1  | [10:22:01 PM] table couch2pg_migrations does not exist - creating it.
cht-couch2pg_1  | [10:22:01 PM] version of database is: 0
cht-couch2pg_1  | [10:22:01 PM] migrating up to 201803202020
cht-couch2pg_1  | [10:22:01 PM] running 201606091247.do.2318-standardise-schema.sql
cht-couch2pg_1  | [10:22:01 PM] running 201606091248.do.2124-support-edit-and-delete-of-documents.sql
cht-couch2pg_1  | [10:22:01 PM] running 201607132040.do.2506-unique-id-constraint.sql
cht-couch2pg_1  | [10:22:01 PM] running 201607210832.do.2523-remove-unused-index.sql
cht-couch2pg_1  | [10:22:01 PM] running 201611271809.do.2923-couch2-support.sql
cht-couch2pg_1  | [10:22:01 PM] running 201803202020.do.3423-multiple-db-support.sql
cht-couch2pg_1  | [2022-03-15T22:22:01.829Z INFO]:  Adapter is running in NORMAL mode
cht-couch2pg_1  | Package pg version 8.x.x not tested
cht-couch2pg_1  | Please raise issue to support pg > 7.x.x
cht-couch2pg_1  | Package pg version 8.x.x not tested
cht-couch2pg_1  | Please raise issue to support pg > 7.x.x
cht-couch2pg_1  | [2022-03-15T22:22:02.030Z INFO]:  Beginning couch2pg and xmlforms run at Tue Mar 15 2022 22:22:02 GMT+0000 (Coordinated Universal Time)
cht-couch2pg_1  | [2022-03-15T22:22:02.033Z DEBUG]:  Performing an import batch of up to 100 changes
cht-couch2pg_1  | [2022-03-15T22:22:02.057Z DEBUG]:  Downloading CouchDB changes feed from 0
cht-couch2pg_1  | [2022-03-15T22:22:02.204Z INFO]:  There are 67 changes to process
cht-couch2pg_1  | [2022-03-15T22:22:02.205Z DEBUG]:  There are 7 deletions and 60 new / changed documents
cht-couch2pg_1  | [2022-03-15T22:22:02.571Z DEBUG]:  Downloading CouchDB changes feed from 275-g1AAAAJjeJyd0UsKwjAQANBgBcWdCC6tXkAmSdu0K3sTzaehlKor13oTvYneRG9S8-lGKEJLYAIzzIOZqRFC0zJQaC7PF1kqkWPCtmAerk1pxJEIm6apyoAvjyYx4YRKzUVXwx9GrE0Uux9Jp1qSWPeVcivtW2nmpKzI0khCX-lgpWsrbZwkC04p7jvdaWwiupnPYHerhU5TGECQZJD28NrTagunAShICzZIe3ntbbWV01iUaELJIO3jNbe32t-SsFhmnVr1BcLxoB4
cht-couch2pg_1  | [2022-03-15T22:22:02.593Z INFO]:  There are 0 changes to process
cht-couch2pg_1  | [2022-03-15T22:22:02.594Z DEBUG]:  Import loop complete, 67 changes total
cht-couch2pg_1  | [2022-03-15T22:22:02.595Z DEBUG]:  Performing an import batch of up to 100 changes
cht-couch2pg_1  | [2022-03-15T22:22:02.598Z DEBUG]:  Downloading CouchDB changes feed from 0
cht-couch2pg_1  | [2022-03-15T22:22:02.707Z INFO]:  There are 53 changes to process
cht-couch2pg_1  | [2022-03-15T22:22:02.707Z DEBUG]:  There are 1 deletions and 52 new / changed documents
cht-couch2pg_1  | [2022-03-15T22:22:02.723Z DEBUG]:  Pulled 50 results from couchdb
cht-couch2pg_1  | [2022-03-15T22:22:02.723Z DEBUG]:  Clearing any existing documents from postgresql
cht-couch2pg_1  | [2022-03-15T22:22:02.724Z DEBUG]:  Inserting 50 results into postgresql
cht-couch2pg_1  | [2022-03-15T22:22:02.743Z DEBUG]:  Pulled 2 results from couchdb
cht-couch2pg_1  | [2022-03-15T22:22:02.744Z DEBUG]:  Clearing any existing documents from postgresql
cht-couch2pg_1  | [2022-03-15T22:22:02.744Z DEBUG]:  Inserting 2 results into postgresql
cht-couch2pg_1  | [2022-03-15T22:22:02.747Z DEBUG]:  Batch completed with 53 changes
cht-couch2pg_1  | [2022-03-15T22:22:02.747Z DEBUG]:  Performing an import batch of up to 100 changes
cht-couch2pg_1  | [2022-03-15T22:22:02.748Z DEBUG]:  Downloading CouchDB changes feed from 86-g1AAAAJjeJyd0EsKwjAQBuBgFcUH0hPoCSRJH2lX9iY6kyaUUnXlWm-iN9Gb6E1qknZZhJaBf2CG-RZTEUJmhZcTX16ussgxY1zsqClWmdUICG7qui4LD7yTGUxVrCIOsuvgD4Nbk7hvpbmTODBBuegrZVY6tNLCSaCCMErCvtLRSrdWWjpJplQDh57SeWyS3E0z2MNqvtMSyhKkdJD2bLSX1dZO01KkkKpB2rvRPlabOI1hDIHWg7Rvo7m_rZyGmMsw5l135Q8VT5-6
cht-couch2pg_1  | [2022-03-15T22:22:02.779Z INFO]:  There are 0 changes to process
cht-couch2pg_1  | [2022-03-15T22:22:02.782Z DEBUG]:  Import loop complete, 53 changes total
cht-couch2pg_1  | [2022-03-15T22:22:02.782Z DEBUG]:  Performing an import batch of up to 100 changes
cht-couch2pg_1  | [2022-03-15T22:22:02.786Z DEBUG]:  Downloading CouchDB changes feed from 0
cht-couch2pg_1  | [2022-03-15T22:22:02.823Z INFO]:  There are 16 changes to process
cht-couch2pg_1  | [2022-03-15T22:22:02.846Z DEBUG]:  Downloading CouchDB changes feed from 16-g1AAAAJbeJyd0ksKwjAQANCxFdSlJ9ATSJL-V_YmmsmHWmpdda030ZvoTfQmNf1AuyiFloEZSMhjJkwGAOvElrAVt0IkEmPKggMxQTNzZXHAXVmWaWJz-2oOVlpTKlAMPRhhcG8yHltpUUshasEYmyrFlXRqJaglETqaS1_Cpsil0pdcyTHhXAn3VrBqIXJ9omUwsZd8aTI8TDHYs5uMilCj4rO0V6O9ux_n3PE99GZpn0b79jTHc5VHZmm_Ruttg2KMkGhwG9I_-Niesg
cht-couch2pg_1  | [2022-03-15T22:22:02.869Z INFO]:  There are 0 changes to process
cht-couch2pg_1  | [2022-03-15T22:22:02.871Z DEBUG]:  Import loop complete, 16 changes total
cht-couch2pg_1  | [2022-03-15T22:22:02.871Z INFO]:  Refreshing materialised views
cht-couch2pg_1  | [2022-03-15T22:22:02.910Z DEBUG]:  { refresh_matviews: 1 }
cht-couch2pg_1  | [2022-03-15T22:22:02.910Z DEBUG]:  { debug: true,
cht-couch2pg_1  |   v4Mode: false,
cht-couch2pg_1  |   couchdbUrl: '192-168-68-17.my.local-ip.co:8443/medic',
cht-couch2pg_1  |   postgresqlUrl: 'postgres:5432/cht',
cht-couch2pg_1  |   docLimit: 50,
cht-couch2pg_1  |   changesLimit: 100,
cht-couch2pg_1  |   retryCount: 5,
cht-couch2pg_1  |   sleepMins: 60,
cht-couch2pg_1  |   couchdbUsersMetaDocLimit: 50 }
cht-couch2pg_1  | [2022-03-15T22:22:02.911Z INFO]:  Run completed. Next run at Tue Mar 15 2022 23:22:02 GMT+0000 (Coordinated Universal Time)