Chirpstack Docker image - can't connect to postgres

Hi All,

I’m not familiar with docker beyond the intro tutorial. The ChirpStack docker file doesn’t seem to setup the database correctly. I looked through the forum and didn’t find an answer. It looks like the correct commands are in the shell files 001-init-chirpstack_ns.sh etc.

Actions I made to resolve the issue:

pulled latest docker file
removed old containers and volumes

Error messages:
postgresql_1 | FATAL: password authentication failed for user “chirpstack_as”
postgresql_1 | DETAIL: Role “chirpstack_as” does not exist.
postgresql_1 | Connection matched pg_hba.conf line 95: “host all all all md5”
postgresql_1 | FATAL: password authentication failed for user “chirpstack_ns”
postgresql_1 | DETAIL: Role “chirpstack_ns” does not exist.
postgresql_1 | Connection matched pg_hba.conf line 95: “host all all all md5”
chirpstack-network-server_1 | time=“2021-01-18T14:17:52Z” level=warning msg=“storage: ping PostgreSQL database error, will retry in 2s” error=“pq: password authentication failed for user “chirpstack_ns””
postgresql_1 | FATAL: password authentication failed for user “chirpstack_as”
postgresql_1 | DETAIL: Role “chirpstack_as” does not exist.
postgresql_1 | Connection matched pg_hba.conf line 95: “host all all all md5”
chirpstack-application-server_1 | time=“2021-01-18T14:17:53Z” level=warning msg=“storage: ping PostgreSQL database error, will retry in 2s” error=“pq: password authentication failed for user “chirpstack_as””
chirpstack-network-server_1 | time=“2021-01-18T14:17:54Z” level=warning msg=“storage: ping PostgreSQL database error, will retry in 2s” error=“pq: password authentication failed for user “chirpstack_ns””

I’m running MacOS 10.14 and Docker Engine 20.10.2, Compose 1.27.4

Looks like a password issue to me. Can you eyeball where “chirpstack_as” came from?

The username and password set in: /etc/chirpstack-network-server/chirpstack-network-server.toml must match where it was set in the postgresl SQL setup here:

– create the chirpstack_ns user with password ‘dbpassword’
create role chirpstack_ns with login password ‘dbpassword’;

– create the chirpstack_ns database
create database chirpstack_ns with owner chirpstack_ns;

– exit the prompt
\q

2 Likes

I am also getting this problem on macOS - could it be a problem with running this docker-compose on macOS? it seems to me that we might not be running the code in the configuration/postgresql/initdb directory, although that might be a red herring

Hi all, just to confirm - I tried using docker-compose up with exactly the same setup on a Linux VM - it didn’t complain at all so I do think this is Mac-specific - I’m going to continue development on the VM - it would be good to know if this can be fixed by changing the Chirpstack repo or if this an issue with docker-compose that can’t be fixed.

For Mac users current solution is the following.

  1. Change two docker-compose-env.yml and docker-compose.yml files. POSTGRES_PASSWORD=postgres. Otherwise connecting under root password prevented by Postgres
  2. Run docker compose-up
  3. Enter to Postgres docker container
  4. Run psql -U postgres
  5. Create manually roles and tables

-- set up the users and the passwords
-- (note that it is important to use single quotes and a semicolon at the end!)
create role chirpstack_as with login password 'dbpassword';
create role chirpstack_ns with login password 'dbpassword';

-- create the database for the servers
create database chirpstack_as with owner chirpstack_as;
create database chirpstack_ns with owner chirpstack_ns;

-- change to the ChirpStack Application Server database
\c chirpstack_as

-- enable the pq_trgm and hstore extensions
-- (this is needed to facilitate the search feature)
create extension pg_trgm;
-- (this is needed to store additional k/v meta-data)
create extension hstore;

-- exit psql
\q

`

Ran into similar problem with the unmodified docker-compose on Mac with chirpstack_as and chirpstack_ns password authenticattion not matching the users. Fix was going into the .toml files for the application server and network and setting the password to ‘dbpassword’

Ex: dsn=“postgres://chirpstack_ns:chirpstack_ns@postgresql/chirpstack_ns?sslmode=disable”
to dsn=“postgres://chirpstack_ns:dbpassword@postgresql/chirpstack_ns?sslmode=disable”