Pg_ctl: could not start server

Hi all,

I am new to aiida and I have installed in local directory of HPC. I installed through conda.
I am having this pg_ctl: could not start server.

I did the following:
(aiidaENV) rkarkee@ch-fe1:~> initdb -D /lustre/scratch5/$USER/aiidaDB
The files belonging to this database system will be owned by user “rkarkee”.
This user must also own the server process.

The database cluster will be initialized with locale “en_US.UTF-8”.
The default database encoding has accordingly been set to “UTF8”.
The default text search configuration will be set to “english”.

Data page checksums are disabled.

initdb: error: directory “/lustre/scratch5/rkarkee/aiidaDB” exists but is not empty
initdb: hint: If you want to create a new database system, either remove or empty the directory “/lustre/scratch5/rkarkee/aiidaDB” or run initdb with an argument other than “/lustre/scratch5/rkarkee/aiidaDB”.

Then:
(aiidaENV) rkarkee@ch-fe1:~> pg_ctl -D /lustre/scratch5/$USER/aiidaDB -l /lustre/scratch5/$USER/aiidaLOG start
waiting for server to start… stopped waiting
pg_ctl: could not start server
Examine the log output.

Then when I checked the log output, I find:
2024-02-08 12:06:41.292 MST [142870] LOG: starting PostgreSQL 15.1 on x86_64-conda-linux-gnu, compiled by x86_64-conda-linux-gnu-cc (conda-forge gcc 11.3.0-19) 11.3.0, 64-bit
2024-02-08 12:06:41.294 MST [142870] LOG: could not bind IPv4 address “127.0.0.1”: Address already in use
2024-02-08 12:06:41.294 MST [142870] HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2024-02-08 12:06:41.294 MST [142870] WARNING: could not create listen socket for “localhost”
2024-02-08 12:06:41.315 MST [142870] FATAL: could not create any TCP/IP sockets
2024-02-08 12:06:41.317 MST [142870] LOG: database system is shut down
2024-02-08 12:07:08.210 MST [154652] LOG: starting PostgreSQL 15.1 on x86_64-conda-linux-gnu, compiled by x86_64-conda-linux-gnu-cc (conda-forge gcc 11.3.0-19) 11.3.0, 64-bit
2024-02-08 12:07:08.211 MST [154652] LOG: could not bind IPv4 address “127.0.0.1”: Address already in use
2024-02-08 12:07:08.211 MST [154652] HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2024-02-08 12:07:08.211 MST [154652] WARNING: could not create listen socket for “localhost”
2024-02-08 12:07:08.211 MST [154652] FATAL: could not create any TCP/IP sockets
2024-02-08 12:07:08.212 MST [154652] LOG: database system is shut down

Please check the answer in this thread: Cannot connect to database - #4 by jgarridoa

It seems like port 5432 is already in use on your system (probably another instance of PostgreSQL is already running). Change the port when launching your server, and then make sure to update the value in your config.json. You find the configuration folder in which you find that file by running verdi profile list.

1 Like

Hi @sphuber
I followed the link as you suggested and did the following:
pg_ctl -D /lustre/scratch5/rkarkee/aiidaDB -o “-F -p 5433” -l logfile start
Server then started

I also updated the config.json
Then I did
rabbitmq-server -detached

and finally

(aiidaENV) rkarkee@ch-fe2:~> verdi daemon start 2
Critical: Could not connect to database: (psycopg2.OperationalError) connection to server at “localhost” (127.0.0.1), port 5433 failed: FATAL: role “aiida_qs_rkarkee_20554bcc4bead70a3479c4ef8d5f1f4e” does not exist

(Background on this error at: Error Messages — SQLAlchemy 2.0 Documentation)

My verdi status looks following:
(aiidaENV) rkarkee@ch-fe2:~> verdi status
:heavy_check_mark: version: AiiDA v2.5.1
:heavy_check_mark: config: /users/rkarkee/.aiida
:heavy_check_mark: profile: rkarkee
✘ 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 5433 failed: FATAL: role “aiida_qs_rkarkee_20554bcc4bead70a3479c4ef8d5f1f4e” does not exist

(Background on this error at: Error Messages — SQLAlchemy 2.0 Documentation)
:heavy_check_mark: rabbitmq: Connected to RabbitMQ v3.8.14 as amqp://guest:guest@127.0.0.1:5672?heartbeat=600
:record_button: daemon: The daemon is not running.

How can I fix this?

Thanks a lot.

Best
Rijan

As the error says, your PostgreSQL server does not have the role aiida_qs_rkarkee_20554bcc4bead70a3479c4ef8d5f1f4e which your profile defines. This may be due to you running the verdi quicksetup before with a different PSQL server up and running and now you are connecting to another one. There are two options:

  1. Run verdi quicksetup again, creating a new profile using the new PSQL server
  2. If you keep having issues with your PSQL server, why not try the recent feature of using a profile that doesn’t use PSQL. You can create such a profile as follows:
verdi profile setup core.sqlite_dos --profile new-profile --set-as-default

You can change the profile name of course. Note that this uses Sqlite instead of PSQL which is less performant. But it may be useful to just get you started for now

1 Like

Hi @sphuber
I tried creating new setup again but got the same error.
(aiidaENV) rkarkee@ch-fe2:~> pg_ctl -D /lustre/scratch5/rkarkee/aiidaDB -o “-F -p 5433” -l logfile start
waiting for server to start… done
server started
(aiidaENV) rkarkee@ch-fe2:~> verdi quicksetup
Report: enter ? for help.
Report: enter ! to ignore the default and set no value.
Profile name [quicksetup]: newproject
Email Address (for sharing data) [rkarkee@ucmerced.edu]:
First name [Rijan]: Rkarkee
Last name [Karkee]: Karkee
Institution [UC Merced]:
Unable to autodetect postgres setup.
Please provide PostgreSQL connection info:
postgres host [localhost]:
postgres port [5432]: 5433
postgres super user [postgres]:
database [template1]:
postgres password of {dsn_new[“user”]} : test
Report: initialising the profile storage.
Report: initialising empty storage schema
Report: Migrating to the head of the main branch
Success: storage initialisation completed.
Success: created new profile newproject.
(aiidaENV) rkarkee@ch-fe2:~> rabbitmq-server -detached
(aiidaENV) rkarkee@ch-fe2:~> verdi daemon start 2
Critical: Could not connect to database: (psycopg2.OperationalError) connection to server at “localhost” (127.0.0.1), port 5433 failed: FATAL: database “rkarkee_rkarkee_20554bcc4bead70a3479c4ef8d5f1f4e” does not exist

(Background on this error at: Error Messages — SQLAlchemy 2.0 Documentation)

I then tried with second option, that seemed to have worked.

(aiidaENV) rkarkee@ch-fe2:~> verdi status
:heavy_check_mark: version: AiiDA v2.5.1
:heavy_check_mark: config: /users/rkarkee/.aiida
:heavy_check_mark: profile: new-profile
:heavy_check_mark: storage: SqliteDosStorage[/users/rkarkee/.aiida/repository/sqlite_dos_1e8f6c59ad444aee8a6e5abb574e4857]: open,
:heavy_check_mark: rabbitmq: Connected to RabbitMQ v3.8.14 as amqp://guest:guest@127.0.0.1:5672?heartbeat=600
:heavy_check_mark: daemon: Daemon is running with PID 141169

I have created so many profiles.

I do not have all the permission , so I could not deleted via verdi profile delete

I saw in documentation it can be deleted manually via PostgreSQL. How can I do that?