Upgrade error xivo-manage-db

Hi everyone,

Did someone had this problem before ? i can’t update, can’t do anything and won’t find out why…

dpkg --configure xivo-manage-db
Paramétrage de xivo-manage-db (20.01~20191218.154226.b118c55.deb10) ...
Failed to connect to postgres
Traceback (most recent call last):
  File "/usr/bin/xivo-init-db", line 4, in <module>
    main()
  File "/usr/lib/python3/dist-packages/xivo_db/bin/init_db.py", line 54, in main
    _init_db(parsed_args.db, parsed_args.owner, parsed_args.password, parsed_args.pg_db_uri)
  File "/usr/lib/python3/dist-packages/xivo_db/bin/init_db.py", line 40, in _init_db
    postgres.init_db(db_name, db_user, db_user_password, pg_db_uri)
  File "/usr/lib/python3/dist-packages/xivo_db/postgres.py", line 26, in decorator
    res = f(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/xivo_db/postgres.py", line 44, in init_db
    conn.autocommit = True
UnboundLocalError: local variable 'conn' referenced before assignment
dpkg: erreur de traitement du paquet xivo-manage-db (--configure) :
 installed xivo-manage-db package post-installation script subprocess returned error exit status 1
Des erreurs ont été rencontrées pendant l'exécution :
 xivo-manage-db

I didn’t set up a password or anything in postgres…

I do have something weird in postgres logs :


2021-07-22 20:11:55.124 CEST [32599] postgres@postgres FATAL:  authentification par mot de passe échouée pour l'utilisateur  « postgres »
2021-07-22 20:11:55.124 CEST [32599] postgres@postgres DÉTAIL:  L'utilisateur « postgres » n'a pas de mot de passe affecté.
        La connexion correspond à la ligne 10 du pg_hba.conf : « host all all all   md5  »

Hello,

This error is very strange. @fblackburn any idea?

Good morning @LaChagnasse . Do you manage to get something from postgres user, like the version of PostgreeSQL ? Try " sudo -u postgres psql --version".

Few month ago, my Wazo has been hacked and they took the control of postgres user. I was trying to connect wazo to jitsi-meet and I guess that my test configuration was not secured enough.

Hi,

yes it seems ok

could not change directory to "/root": Permission non accordée
psql (PostgreSQL) 11.5 (Debian 11.5-1+deb10u1)

running this is okay too :

sudo -u postgres psql asterisk -c 'select * from call_log order by date desc'

Using dpkg with database service is always tricky (because of debian questions)

  • rerun configuration (dpkg-reconfigure xivo-manage-db)
  • answer questions with the same default values that here
    • be careful: the admin password is empty BUT the user password is proformatique (but the prompt will be empty for both passwords by default)

Have you modified your pg_hba.conf file ?
On fresh install it should be similar to

local all postgres    peer 
local all all    peer 
host all all 127.0.0.1/32   md5 
host all all ::1/128   md5

Hi, thanks for the answer, here is the output of the command :


root@Delta01p-Wazo:~# dpkg-reconfigure xivo-manage-db
/usr/sbin/dpkg-reconfigure: xivo-manage-db est cassé ou partiellement installé

is broken or not fully installed

I don’t think i did modified pg_hba.conf , maybe i don’t remember but i don’t see a reason why…
I replaced the content of it with what you gave, still nothing

Edit: Do you have one user in your database?
SELECT count(*) FROM userfeatures

does this answer your question ?

root@Delta01p-Wazo:~# su - postgres
postgres@Delta01p-Wazo:~$ psql
psql (11.5 (Debian 11.5-1+deb10u1), serveur 11.12 (Debian 11.12-0+deb10u1))
Saisissez « help » pour l'aide.

postgres=# \c asterisk;
psql (11.5 (Debian 11.5-1+deb10u1), serveur 11.12 (Debian 11.12-0+deb10u1))
Vous êtes maintenant connecté à la base de données « asterisk » en tant qu'utilisateur « postgres ».
asterisk=#  SELECT count(*) FROM userfeatures
asterisk-#

Forgot the ; at the end
SELECT count(*) FROM userfeatures;

:grimacing:

asterisk=#  SELECT count(*) FROM userfeatures;
 count
-------
    17
(1 ligne)

And what is the output of debconf-show xivo-manage-db

root@Delta01p-Wazo:~# debconf-show xivo-manage-db
* xivo-manage-db/db-app-password: (password omitted)
* xivo-manage-db/db-admin-password: (password omitted)
* xivo-manage-db/db-admin-username: postgres
* xivo-manage-db/db-skip: false
* xivo-manage-db/db-host: localhost
* xivo-manage-db/db-app-name: asterisk
* xivo-manage-db/db-port: 5432
* xivo-manage-db/db-app-username: asterisk

Ok, everything look good

after changing your pg_hba.conf restart your postgres (systemctl restart postgresql@11-main) and retry your dpkg --configure xivo-manage-db

i restarted when you said my file wasn’t as it should, i doubled checked, restarted postgres again and still the same :

root@Delta01p-Wazo:~# cat /etc/postgresql/11/main/pg_hba.conf
#
# Ansible managed
#
# PostgreSQL Client Authentication Configuration File
# ===================================================
#
# See: https://www.postgresql.org/docs/current/static/auth-pg-hba-conf.html

local all postgres    peer
local all all    peer
host all all 127.0.0.1/32   md5
host all all ::1/128   md5
root@Delta01p-Wazo:~# service postgresql restart
root@Delta01p-Wazo:~# dpkg --configure xivo-manage-db
Paramétrage de xivo-manage-db (20.01~20191218.154226.b118c55.deb10) ...
Failed to connect to postgres
Traceback (most recent call last):
  File "/usr/bin/xivo-init-db", line 4, in <module>
    main()
  File "/usr/lib/python3/dist-packages/xivo_db/bin/init_db.py", line 54, in main
    _init_db(parsed_args.db, parsed_args.owner, parsed_args.password, parsed_args.pg_db_uri)
  File "/usr/lib/python3/dist-packages/xivo_db/bin/init_db.py", line 40, in _init_db
    postgres.init_db(db_name, db_user, db_user_password, pg_db_uri)
  File "/usr/lib/python3/dist-packages/xivo_db/postgres.py", line 26, in decorator
    res = f(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/xivo_db/postgres.py", line 44, in init_db
    conn.autocommit = True
UnboundLocalError: local variable 'conn' referenced before assignment
dpkg: erreur de traitement du paquet xivo-manage-db (--configure) :
 installed xivo-manage-db package post-installation script subprocess returned error exit status 1
Des erreurs ont été rencontrées pendant l'exécution :
 xivo-manage-db

Well that’s weird

Be sure to have backup/snapshot before the following steps

You can try apt-get install --reinstall xivo-manage-db
If it’s still not work, then you can hack the debian packaging file

  • vim /var/lib/dpkg/info/xivo-manage-db.postinst
  • comment xivo-init-db command
  • dpkg --configure xivo-manage-db
  • apt-get install --reinstall xivo-manage-db

okay, i’ll try this tonight
thanks again

Well, the fist one just output a lot of

FATAL:  authentification par mot de passe échouée pour l'utilisateur  « postgres »

and then

Failed to connect to postgres
Traceback (most recent call last):
  File "/usr/bin/xivo-init-db", line 11, in <module>
    load_entry_point('xivo-db==0.1', 'console_scripts', 'xivo-init-db')()

and the post install hack :

root@Delta01p-Wazo:~# apt-get install --reinstall xivo-manage-db
Lecture des listes de paquets... Fait
Construction de l'arbre des dépendances
Lecture des informations d'état... Fait
Les paquets suivants ont été installés automatiquement et ne sont plus nécessaires :
  apache2-data apache2-utils liblockfile1 lockfile-progs m4 nestbox-confd-client-python3 sendmail-base sendmail-cf
Veuillez utiliser « apt autoremove » pour les supprimer.
0 mis à jour, 0 nouvellement installés, 1 réinstallés, 0 à enlever et 279 non mis à jour.
3 partiellement installés ou enlevés.
Après cette opération, 0 o d'espace disque supplémentaires seront utilisés.
E: Internal Error, No file name for xivo-manage-db:amd64

now doing some research…

root@Delta01p-Wazo:~# apt-cache policy xivo-manage-db
xivo-manage-db:
  Installé : 21.09~20210625.133305.58904b1.deb10
  Candidat : 21.09~20210625.133305.58904b1.deb10
 Table de version :
 *** 21.09~20210625.133305.58904b1.deb10 500
        500 http://mirror.wazo.community/debian pelican-buster/main amd64 Packages
        100 /var/lib/dpkg/status