Cannot connect to database

Hi everyone

I have been using Aiida in two different workstations available in my research group. To install Aiida in those workstations, I simply followed the steps in Installation into Conda environment — AiiDA 2.5.1.post0 documentation with no problem.

Now I have a new workstation in which I have to install Aiida again, but this time, I am having an issue. When I write verdi status, I get:

:heavy_check_mark: version: AiiDA v2.5.0
:heavy_check_mark: config: /home/ICN2/jgarridoa/.aiida
:heavy_check_mark: profile: jgarridoa
✘ storage: Unable to connect to profile’s storage.
Error: UnreachableStorage: Could not connect to database: (psycopg2.OperationalError) connection to server at “localhost” (127.0.0.1), port 5432 failed: Connection refused
Is the server running on that host and accepting TCP/IP connections?

(Background on this error at: Error Messages — SQLAlchemy 2.0 Documentation)
✘ rabbitmq: Unable to connect to rabbitmq with URL: amqp://guest:guest@127.0.0.1:5672?heartbeat=600
Error: ConnectionError: [Errno 111] Connect call failed (‘127.0.0.1’, 5672)
✘ daemon: The daemon could not be reached, seemingly because of a stale PID file. Either stop or start the daemon to remove it and restore the daemon to a functional state.

Any idea of what might be causing this error?

In case it helps , I am using Ubuntu 22.04.3 LTS. The previous workstations I used have Ubuntu 22.04.2 LTS.

Thanks in advance

Jaime

Hi Jaime,

I haven’t used conda/mamba much myself, but if I understand correctly the services (postgresql/rabbitMQ) need to be started again every time the environment is activated.

Can you try to restart the services after starting the environment using the “Restart the services” instructions at the end of the page you linked above?

Thanks @mbercx, I forget to tell you that I had a zoom chat with @jgarridoa. The problem he encountered was the postgreSQL can not be start because the port 5432 is used.
He is running AiiDA in a multi-user cluster with having his own folder (@jgarridoa correct me if I am wrong).
In the end the problem is solved by starting PostgreSQL with specifying the other port number. The command to run is:

pg_ctl -D mylocal_db -o "-F -p 15443" -l logfile start   # 15433 is the port number, change to what ever you need.

We can try to improve the documentation with some of these information, it now simply point to the postgresql official documentation.

For the rabbitmq, @mbercx is right, start the service with rabbitmq-server -detached solve the problem.

1 Like

Yes, it is exactly that. I am using a multi-user workstation with my own folder. The rest was exactly as you say

Thanks a lot!

1 Like

Hi again.

I kept working and I had the following problem: I had already designed a workchain and I wast trying to submit it. I was trying it via a jupyter notebook in Visual Studio Code. The problem I had was that despite having added the folder with the workchains I used to the python path, I kept getting the error that modules could not be loaded. I obtained the same error after trying adding the folder to the python path temporarily using sys. …

After checking several things, I did not arrive to any conclusion. but I thought that something might be off with my miniconda environment and how it was interacting with the pythonpath.

In the end, I decided to delete all my miniconda environmentes and then, install aiida again.

The problem I am facing now during the installation is with rabbitmq. After following the steps that worked the last time (including changing the port number), I get a different error:

✘ rabbitmq: Unable to connect to rabbitmq with URL: amqp://guest:guest@127.0.0.1:5672?heartbeat=600
Error: ConnectionResetError: [Errno 104] Connection reset by peer

Any idea about how to solve this problem? I would also like to know what might be causing it. After having so many weird difficulties with not only aiida but also with the things I said about the python path, I am starting to think that IT department did something weird when setting up my workstation. I have worked with aiida in two other workstations and I never had the issues I am having with this one.

Thanks a lot in advance

Jaime

Hi,

I have a similar issue on connecting the database after restarting my workstation:
:check_mark: version: AiiDA v2.6.3
:check_mark: config: /home/biliu/.aiida
:check_mark: profile: biliu
✘ storage: Unable to connect to profile’s storage.
Error: UnreachableStorage: Could not connect to database: (psycopg2.OperationalError) connection to server at “localhost” (127.0.0.1), port 5432 failed: Connection refused
Is the server running on that host and accepting TCP/IP connections?

(Background on this error at: Error Messages — SQLAlchemy 2.0 Documentation)
✘ broker: Unable to connect to broker: RabbitMQ @ amqp://guest:guest@127.0.0.1:5672?heartbeat=600
Error: ConnectionError: [Errno 111] Connect call failed (‘127.0.0.1’, 5672)

And I tried the command suggested here
‘’’
pg_ctlcluster 14 main start – -o “-F -p 5433”
‘’’
but it didn’t work and gives the following issue:
Notice: extra pg_ctl/postgres options given, bypassing systemctl for start operation
Error: Could not open logfile /var/log/postgresql/postgresql-14-main.log
Error: /usr/lib/postgresql/14/bin/pg_ctl /usr/lib/postgresql/14/bin/pg_ctl start -D /var/lib/postgresql/14/main -l /var/log/postgresql/postgresql-14-main.log -o -F -p 5433 -s -o -c config_file=“/etc/postgresql/14/main/postgresql.conf” exited with status 1:

Here are more info regarding this issue:
systemctl status ‘postgresql*’
× postgresql@12-main.service - PostgreSQL Cluster 12-main
Loaded: loaded (/lib/systemd/system/postgresql@.service; enabled-runtime; vendor preset: enabled)
Active: failed (Result: protocol) since Tue 2025-06-17 11:21:06 CEST; 1h 5min ago
Process: 708468 ExecStart=/usr/bin/pg_ctlcluster --skip-systemctl-redirect 12-main start (code=exited, status=1/FAILURE)
CPU: 72ms

● postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
Active: active (exited) since Tue 2025-06-17 11:21:06 CEST; 1h 5min ago
Process: 708474 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Process: 751087 ExecReload=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 708474 (code=exited, status=0/SUCCESS)
CPU: 2ms

× postgresql@14-main.service - PostgreSQL Cluster 14-main
Loaded: loaded (/lib/systemd/system/postgresql@.service; enabled-runtime; vendor preset: enabled)
Active: failed (Result: protocol) since Tue 2025-06-17 11:21:06 CEST; 1h 5min ago
Process: 708469 ExecStart=/usr/bin/pg_ctlcluster --skip-systemctl-redirect 14-main start (code=exited, status=1/FAILURE)
CPU: 61ms

Any idea/suggestions on this?

Many thanks,
Binbin

From the last part, it looks like you have 3 different Postgres versions on your computer. The one that succeeds is the second one, while the first one and the third one (v14-main) don’t (maybe because by default they are all trying to connect to the same port 5432?). Maybe you installed (or the system self-upgraded)? Do you know in which version of Postgres you have the data in? if it’s the second one, you don’t need to start by hand. If it’s in v14, you are indeed trying to start it, but 1. you are trying to start on a different port 5433, which is in principle correct, but AiiDA (see earlier in verdi status) is trying to connect to port 5432, so even if you manage to start it, it wouldn’t really help. 2. The main error is “Could not open logfile /var/log/postgresql/postgresql-14-main.log”, so probably this is owned by root or the postgres user, and you have no permissions to write on it as a regular user. The first think you can do is to check with ports are open, to understand if there is one of those services listening on port 5432.

(Apologies, I was connected with the wrong account - the previous message was from me)

Hello,

For rabbitmq, it is probable you have the same problem regarding ports - also rabbimq uses ports, the 5672 specifically (you can also see it from the address 127.0.0.1:5672).

In conda/mamba environment, you should be able to change the port as follows:

echo "NODE_PORT=5673" >> $CONDA_PREFIX/etc/rabbitmq/rabbitmq-env.conf

5673 is an example, but rather safe. This procedure also requires to change the aiida config (usually ~/.aiida/config.json) RabbitMQ port to the same configured previously. In this case, you should change it to 5673.

Importantly, aslo change the consumer timeout if you have recent versions of rabbitmq, by doing:

echo "consumer_timeout = 360000000000" >> $CONDA_PREFIX/etc/rabbitmq/rabbitmq.conf

If you don’t have rabbitmq in a conda/mamba environment, you can still identify the path to the filenames and change accordingly.

Hope it helps

Thanks a lot Giovanni! It is indeed a port issue due to the permission of the /var/log/postgresql/ folder not given to postgresql. And same issue for the RabbitMQ. Thank you Lorenzo as well!