Error, will retry in 2s: pq: password authentication failed for user “loraserver”"

Hello,

I’m having an issue with the following Error when setting up, following the ‘Quick-Install’ guide.
Here: https://docs.loraserver.io/install/quick-install/

Error received is:
Oct 21 09:11:37 loraserver loraserver[16224]: time=“2017-10-21T09:11:37Z” level=error msg="ping database error, will retry in 2s: pq: password authentication failed for user “loraserver”"

…what is confusing:

Loraserver says:
…level=error msg="ping database error, will retry in 2s: pq: passsword authentication failed for user “loraserver”"

If you check the steps in the quick-install page, we do not set password anywhere for user “loraserver” except mosquitto.

here: sudo mosquitto_passwd /etc/mosquitto/pwd loraserver

I have tried using the mosquitto_passwd and still get the error.

the passwords we set as directed in the guide are here:
create role loraserver_as with login password ‘dbpassword’;
create role loraserver_ns with login password ‘dbpassword’;

…So my question is, what file/field/user is loraserver referring too please?

where can I find password parameter for user “loraserver”" so I can set it?

Just to note that i’m installing this on cloud not local machine.

Many thanks in advance for your replies,
Leon

What’s failing is postgres’ authentication, not mosquitto’s. You need to provide a valid POSTGRES_DSN var in /etc/default/loraserver in order to properly connect to postgres DB. Replace the defaults values with your real credentials in:
postgres://user:password@hostname/db_name?sslmode=disable

Hey iegomez,

Thanks for you reply!

Here is what I set (exactly the same as the setup procedure)

create role loraserver_as with login password ‘dbpassword’;
create role loraserver_ns with login password ‘dbpassword’;

create database loraserver_as with owner loraserver_as;
create database loraserver_ns with owner loraserver_ns;

– exit psql
\q

Here is what I set for postgresql dsn /etc/default/loraserver.

#postgresql dsn (e.g.: postgres://user:password@hostname/database?sslmode=disable)**
postgres://loraserver_ns:dbpassword@localhost/loraserver?sslmode=disable

root@lora-server:~# journalctl -u loraserver -f
– Logs begin at Sat 2017-10-21 09:31:17 UTC. –
Oct 21 13:14:48 lora-server systemd[1]: loraserver.service: Ignoring invalid environment assignment ‘postgres://loraserver_ns:dbpassword@localhost/loraserver?sslmode=disable’: /etc/default/loraserver
Oct 21 13:14:48 lora-server systemd[1]: Started LoRa Server.
Oct 21 13:14:48 lora-server loraserver[14560]: time=“2017-10-21T13:14:48Z” level=info msg=“starting LoRa Server” band=“EU_863_870” docs=“https://docs.loraserver.io/” net_id=010203 version=0.21.0
Oct 21 13:14:48 lora-server loraserver[14560]: time=“2017-10-21T13:14:48Z” level=info msg=“setup redis connection pool” url=“redis://localhost:6379”
Oct 21 13:14:48 lora-server loraserver[14560]: time=“2017-10-21T13:14:48Z” level=info msg=“connecting to postgresql”
Oct 21 13:14:48 lora-server loraserver[14560]: time=“2017-10-21T13:14:48Z” level=error msg=“ping database error, will retry in 2s: pq: password authentication failed for user “loraserver””

I’m starting to think I need to replace localhost for cloud server IP?

Many thanks in advance for you reply iegomez!
Leon

“…I’m starting to think I need to replace localhost for cloud server IP?”

I have just tried that …and still don’t work

Leon, you are right, if your Loraserver and Postgres instances are in different machines, you need to change localhost for the Postgre’s host name or ip. After that, you need to configure Postgres so that it can be remotely accessed (by default it only allows local access). You can achieve this by changing postgresql.conf (its location depends on the installation, but most common ones are /etc/postgressql//main/ and /var/lib/pgsql//data/). You need to modify this line:

listen_addresses = ‘localhost’

Change it to this:

listen_addresses = ‘*’

Also, pg_hba.conf (most likely at the same location as postgresql.conf) needs to be modified to allow user’s remote access (again, by default it only allows local access). Add these lines to the end of the file:

host all all 0.0.0.0/0 md5
host all all ::/0 md5

Now just restart the postgresql service and you should be able to connect to your DB remotely.

EDIT:
Also check the error you got:

Are you sure that you assigned it to POSTGRES_DSN var? I.e., it should be like this:

POSTGRES_DSN=postgres://loraserver_ns:dbpassword@localhost/loraserver?sslmode=disable

Hey iegomez,

you are correct I did not set the variable! // my mistake

:slight_smile: BUT…

Now I have:
POSTGRES_DSN=postgres://loraserver_ns:dbpassword@localhost/loraserver?sslmode=disable

root@lora-server:~# journalctl -u loraserver -f
– Logs begin at Sat 2017-10-21 09:31:17 UTC. –
Oct 21 13:51:48 lora-server loraserver[14984]: time=“2017-10-21T13:51:48Z” level=error msg=“ping database error, will retry in 2s: pq: password authentication failed for user “loraserver””
Oct 21 13:51:50 lora-server loraserver[14984]: time=“2017-10-21T13:51:50Z” level=error msg=“ping database error, will retry in 2s: pq: password authentication failed for user “loraserver””
Oct 21 13:51:50 lora-server systemd[1]: Stopping LoRa Server…
Oct 21 13:51:50 lora-server systemd[1]: Stopped LoRa Server.
Oct 21 13:51:55 lora-server systemd[1]: Started LoRa Server.
Oct 21 13:51:55 lora-server loraserver[15787]: time=“2017-10-21T13:51:55Z” level=info msg=“starting LoRa Server” band=“EU_863_870” docs=“blah” net_id=010203 version=0.21.0
Oct 21 13:51:55 lora-server loraserver[15787]: time=“2017-10-21T13:51:55Z” level=info msg=“setup redis connection pool” url=“redis://localhost:6379”
Oct 21 13:51:55 lora-server loraserver[15787]: time=“2017-10-21T13:51:55Z” level=info msg=“connecting to postgresql”
Oct 21 13:51:55 lora-server loraserver[15787]: time=“2017-10-21T13:51:55Z” level=error msg=“ping database error, will retry in 2s: pq: database “loraserver” does not exist”

loraserver says: database “loraserver” does not exist" ??

Many thanks again for your reply iegomez!
Leon

I have moved from:

Error, will retry in 2s: pq: password authentication failed for user “loraserver””

to

level=error msg=“ping database error, will retry in 2s: pq: database “loraserver” does not exist”

by fixing the correct POSTGRES_DSN=

Any ideas Mr.

Cheers in advance,
Leon

Solved with the following steps:

vi /etc/default/loraserver
POSTGRES_DSN=postgres://loraserver_ns:dbpassword@localhost/loraserver?sslmode=disable

vi /etc/postgresql/9.5/main/postgresql.conf
listen_addresses = ‘localhost’

Change it to this:

listen_addresses = ‘*’

vi /etc/postgresql/9.5/main/pg_hba.conf . // add at bottom
host all all 0.0.0.0/0 md5
host all all ::/0 md5

…then restart postgresql.

For Cloud server install especially on DigitalOcean server, I recommend to read.

Thank you iegomez for your help throughout …appreciated!
Leon

2 things:

First, from your comments the db name is loraserver_ns, not loraserver, so check that is right.

Second, check that auth method is md5 and not peer in pg_hba.conf. You can check it is right by trying to connect to the DB:

psql -U username -d dbname (you’ll be prompted for the password after)

If you can log to psql, then it’s correctly set.

As I mentioned, you have your postgres auth set as peer, you need to change it to md5. You can change it at pg_hba.conf, then restart postgres.

Hi, I have a similar problem.

I try to install loraserver on a single server with ubuntu headless 16.04

I followed the instructions from https://docs.loraserver.io/install/quick-install/ but after finishing Installing LoRa Server I cannot start loraserver. I get:

Oct 23 19:05:03 shuttle-server loraserver[17457]: time=“2017-10-23T19:05:03+02:00” level=error msg=“ping database error, will retry in 2s: pq: password authentication failed for user “loraserver””

When I login on postgres I have no problem

remko@shuttle-server:~$ psql -h localhost -d loraserver_ns -U loraserver_ns
Password for user loraserver_ns:
psql (9.5.9)
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
Type “help” for help.

loraserver=>

no idea what goes wrong

The error says:

“ping database error, will retry in 2s: pq: password authentication failed for user “loraserver””

You example connection shows a different user (loraserver_ns != loraserver):

remko@shuttle-server:~$ psql -h localhost -d loraserver_ns -U loraserver_ns

So probably your POSTGRES_DSN for loraserver hast the wrong user set.

Hi,

I have seen that too but in the config file this is added:

POSTGRESS_DSN=postgres://loraserver_ns:password@localhost/loraserver?sslmode=disable

How is it possible that loraserver is using a different username?

There’s a typo in the env var: it says POSTGRESS_DSN, and it should say POSTGRES_DSN (just one S before the underscore).

Thanks! that did the trick. always fine to have people that see things you overlook yourself.
Now up to new problems to be solved:

Oct 23 19:42:04 shuttle-server loraserver[25543]: time="2017-10-23T19:42:04+02:00" level=fatal msg="--gw-server-jwt-secret must be set"
Oct 23 19:42:04 shuttle-server systemd[1]: loraserver.service: Main process exited, code=exited, status=1/FAILURE
Oct 23 19:42:04 shuttle-server systemd[1]: loraserver.service: Unit entered failed state.
Oct 23 19:42:04 shuttle-server systemd[1]: loraserver.service: Failed with result 'exit-code'.
Oct 23 19:42:04 shuttle-server systemd[1]: loraserver.service: Service hold-off time over, scheduling restart.
Oct 23 19:42:04 shuttle-server systemd[1]: Stopped LoRa Server.
Oct 23 19:42:04 shuttle-server systemd[1]: loraserver.service: Start request repeated too quickly.
Oct 23 19:42:04 shuttle-server systemd[1]: Failed to start LoRa Server.

Cu, Remko

As the error states, you are not setting the --gw-server-jwt-secret flag (or GW_SERVER_JWT_SECRET env), which must be set.

Right, I corrected this in bot server and app-server.
No mention of it in https://docs.loraserver.io/install/quick-install/
Now both servers are running.

Now when access in the app-gateway I get this:

afbeelding
I had to move the port as it is occupied already.

When i use https I get a real website :slight_smile:

Thanks for thinking along with me.

1 Like

I seem to be having the same issue (or one resembling it). Just spun up a new instance using the quick-install method, as I wanted to test whether or not we’re getting a response on OTAA requests back to the gateways. Right now we’re not on the first install. In any case, I’ve checked /etc/default/loraserver and it says this:

POSTGRES_DSN=postgres://loraserver_ns:dbpassword@localhost/loraserver_ns?sslmode=disable

That seems to match reality. I used psql and the users and roles seem fine. the error changes like one would expect if I change the DSN string for Postgres in the loraserver config, so I’m a tad baffled.

Actual Error message:

Dec 07 16:21:26 mint-1802 loraserver[1299]: time=“2017-12-07T16:21:26-06:00” level=error msg=“ping database error, will retry in 2s: pq: password authentication failed for user “loraserver_ns””

Ancillary info:

Brand new apt-get install on all the software
Postgres 9.5.10

Thanks!

tl;dr Never Mind

OK, I discovered that I had to make modifications to the way that Postgres deals with logins. This may not be the REAL AND PROPER way to do it, but I know little of Postgres (MySql, Mongo, and MSsql mostly), and have to get this up and running. In any case, I googled and found this. Eventually I ended up with my /etc/postgresql/9.5/main/pg_hba.conf looking like this:

# "local" is for Unix domain socket connections only
local   all             all                                     trust

Since this is just to ensure that things work, I can figure out how to clean up my actual install, when I get to that point.

I intent to create a new post, which will also mention this problem.

After many efforts and with support of @brocaar and other users i have this-last-problem.

I have the same problem with loraserver, despite i tried whatever your suggested solutions in postgresql.conf file i still have the same authentication problem, while i debug loraserver from /etc:

.

Executing service command seems everything ok:

.

As a result,while pkt fwd and lora-gateway-bridge seem to communicate each other

, i can’t see this gateway (activity) in loraserver client

It has really to do with authentication problem finally?

Thanks in advance,
Nikos.

PS:i can also share my loraserver.toml configuration file.