Hello juju switching to postgresql database example failure

Hello,

new to juju, I tried the ‘Getting started with Juju’ tutorial, but something went wrong at the end :slight_smile:

the juju relate postgresql:db hello-juju command fails with this message : hook failed: "db-relation-changed"

Can someone help ? I don’t know what to do to fix it.

I also see the same error. There seems to be a bug in the hello-juju charm, which I’ve filed as https://github.com/juju/hello-juju-charm/issues/1.

I saw this by running juju debug-log, in case you’re interested.

Hopefully someone will be able to take a look at this soon and get it fixed up.

Thank you. I saw the same log, but was wondering if the problem could be on the other side of the relation, as unit-postgresql showed errors too :

unit-postgresql-1: 01:04:09 ERROR unit.postgresql/1.juju-log Unable to find implementation for relation: provides of block-storage
unit-postgresql-1: 01:04:09 ERROR unit.postgresql/1.juju-log Unable to find implementation for relation: provides of local-monitors
unit-postgresql-1: 01:04:09 ERROR unit.postgresql/1.juju-log Unable to find implementation for relation: provides of pgreplication
unit-postgresql-1: 01:04:09 ERROR unit.postgresql/1.juju-log Unable to find implementation for relation: peers of pgpeer

Hello again,

I don’t understand, is it so difficult to fix the first example one will see when trying to understand juju and the juju relations ?

Thanks for the report. This has been fixed. I’ll get it published to the store presently.

After re-deploying

I get the same error : ‘hook failed: “db-relation-changed”’

and the logs are very similar

unit-hello-juju-5: 11:52:22 WARNING unit.hello-juju/5.db-relation-changed TypeError: expected bytes, str found
unit-hello-juju-5: 11:52:22 ERROR unit.hello-juju/5.juju-log db:19: Hook error:
self._action(*args)
File “/var/lib/juju/agents/unit-hello-juju-5/charm/reactive/hello_juju.py”, line 103, in create_and_configure_database
create_database_tables()
File “/var/lib/juju/agents/unit-hello-juju-5/charm/reactive/hello_juju.py”, line 66, in create_database_tables
check_call(str(‘sudo -u www-data /srv/hello-juju/venv/bin/python3 /srv/hello-juju/current/init.py’).split())
File “/usr/lib/python3.6/subprocess.py”, line 311, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command ‘[‘sudo’, ‘-u’, ‘www-data’, ‘/srv/hello-juju/venv/bin/python3’, ‘/srv/hello-juju/current/init.py’]’ returned non-zero exit status 1.
unit-hello-juju-5: 11:52:22 WARNING unit.hello-juju/5.db-relation-changed Traceback (most recent call last):
unit-hello-juju-5: 11:52:22 WARNING unit.hello-juju/5.db-relation-changed File “/var/lib/juju/agents/unit-hello-juju-5/charm/hooks/db-relation-changed”, line 22, in
unit-hello-juju-5: 11:52:22 WARNING unit.hello-juju/5.db-relation-changed main()
unit-hello-juju-5: 11:52:22 WARNING unit.hello-juju/5.db-relation-changed File “/var/lib/juju/agents/unit-hello-juju-5/.venv/lib/python3.6/site-packages/charms/reactive/init.py”, line 74, in main
unit-hello-juju-5: 11:52:22 WARNING unit.hello-juju/5.db-relation-changed bus.dispatch(restricted=restricted_mode)
unit-hello-juju-5: 11:52:22 WARNING unit.hello-juju/5.db-relation-changed File “/var/lib/juju/agents/unit-hello-juju-5/.venv/lib/python3.6/site-packages/charms/reactive/bus.py”, line 390, in dispatch
unit-hello-juju-5: 11:52:22 WARNING unit.hello-juju/5.db-relation-changed _invoke(other_handlers)
unit-hello-juju-5: 11:52:22 WARNING unit.hello-juju/5.db-relation-changed File “/var/lib/juju/agents/unit-hello-juju-5/.venv/lib/python3.6/site-packages/charms/reactive/bus.py”, line 359, in _invoke
unit-hello-juju-5: 11:52:22 WARNING unit.hello-juju/5.db-relation-changed handler.invoke()
unit-hello-juju-5: 11:52:22 WARNING unit.hello-juju/5.db-relation-changed File “/var/lib/juju/agents/unit-hello-juju-5/.venv/lib/python3.6/site-packages/charms/reactive/bus.py”, line 181, in invoke
unit-hello-juju-5: 11:52:22 WARNING unit.hello-juju/5.db-relation-changed self._action(*args)
unit-hello-juju-5: 11:52:22 WARNING unit.hello-juju/5.db-relation-changed File “/var/lib/juju/agents/unit-hello-juju-5/charm/reactive/hello_juju.py”, line 103, in create_and_configure_database
unit-hello-juju-5: 11:52:22 WARNING unit.hello-juju/5.db-relation-changed create_database_tables()
unit-hello-juju-5: 11:52:22 WARNING unit.hello-juju/5.db-relation-changed File “/var/lib/juju/agents/unit-hello-juju-5/charm/reactive/hello_juju.py”, line 66, in create_database_tables
unit-hello-juju-5: 11:52:22 WARNING unit.hello-juju/5.db-relation-changed check_call(str(‘sudo -u www-data /srv/hello-juju/venv/bin/python3 /srv/hello-juju/current/init.py’).split())
unit-hello-juju-5: 11:52:22 WARNING unit.hello-juju/5.db-relation-changed File “/usr/lib/python3.6/subprocess.py”, line 311, in check_call
unit-hello-juju-5: 11:52:22 WARNING unit.hello-juju/5.db-relation-changed raise CalledProcessError(retcode, cmd)
unit-hello-juju-5: 11:52:22 WARNING unit.hello-juju/5.db-relation-changed subprocess.CalledProcessError: Command ‘[‘sudo’, ‘-u’, ‘www-data’, ‘/srv/hello-juju/venv/bin/python3’, ‘/srv/hello-juju/current/init.py’]’ returned non-zero exit status 1.
unit-hello-juju-5: 11:52:22 ERROR juju.worker.uniter.operation hook “db-relation-changed” (via explicit, bespoke hook script) failed: exit status 1
unit-hello-juju-5: 11:52:22 INFO juju.worker.uniter awaiting error resolution for “relation-changed” hook
unit-hello-juju-5: 11:52:32 INFO juju.worker.uniter awaiting error resolution for “relation-changed” hook
unit-hello-juju-5: 11:52:33 INFO unit.hello-juju/5.juju-log db:19: Reactive main running for hook db-relation-changed
unit-hello-juju-5: 11:52:33 INFO unit.hello-juju/5.juju-log db:19: Invoking reactive handler: reactive/hello_juju.py:45:configure_gunicorn
unit-hello-juju-5: 11:52:34 INFO unit.hello-juju/5.juju-log db:19: Invoking reactive handler: reactive/hello_juju.py:86:pending
unit-hello-juju-5: 11:52:34 INFO unit.hello-juju/5.juju-log db:19: Invoking reactive handler: hooks/relations/pgsql/requires.py:388:_joined:db
unit-hello-juju-5: 11:52:34 INFO unit.hello-juju/5.juju-log db:19: Invoking reactive handler: hooks/relations/pgsql/requires.py:404:_changed:db
unit-hello-juju-5: 11:52:34 INFO unit.hello-juju/5.juju-log db:19: Invoking reactive handler: reactive/hello_juju.py:91:create_and_configure_database

It should work now.
Fixed by https://github.com/juju/hello-juju/pull/1

It worked indeed. Thanks.

I’ve juju deployed postgresql in one model, hello-juju in another, the relevant offer and relate commands done. It shows up okay in the juju status --relations output. Visiting the hello-juju IP:80 displays a page okay and tcpdump shows port 5432 traffic between the two LXD hosts. But the page loads ONLY the 1st time. Subsequent loads return 500 Internal Server Error.

root@proud-egret:/srv/app# tail access.log

10.0.0.144 - - [05/May/2022:09:50:59 +0000] "GET / HTTP/1.1" 200 9766 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36"
10.0.0.144 - - [05/May/2022:09:50:59 +0000] "GET /favicon.ico HTTP/1.1" 404 232 "http://172.16.0.33/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36"
10.0.0.144 - - [05/May/2022:09:52:09 +0000] "GET / HTTP/1.1" 500 290 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36"

In /srv/app/error.log:

[2022-05-05 09:52:09,263] ERROR in app: Exception on / [GET]
Traceback (most recent call last):
  File "/srv/app/venv/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1770, in _execute_context
    self.dialect.do_execute(
  File "/srv/app/venv/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 717, in do_execute
    cursor.execute(statement, parameters)
  File "/srv/app/venv/lib/python3.8/site-packages/pg8000/core.py", line 341, in execute
    self._c.execute_unnamed(
  File "/srv/app/venv/lib/python3.8/site-packages/pg8000/core.py", line 1214, in execute_unnamed
    self.handle_messages(cursor)
  File "/srv/app/venv/lib/python3.8/site-packages/pg8000/core.py", line 1381, in handle_messages
    raise self.error
pg8000.exceptions.ProgrammingError: {'S': 'ERROR', 'V': 'ERROR', 'C': '42501', 'M': 'permission denied for table greeting', 'F': 'aclchk.c', 'L': '3490', 'R': 'aclcheck_error'}

Any ideas, why Postgresql would give a “permission denied for table greeting” please? Juju is supposed to be dealing with the configurations, what might have failed?

1 Like