Manuel Anglada Tort
Manuel Anglada Tort

Reputation: 96

Cannot debug a PsyNet experiment because a failure to connect to Postgres

I cannot debug a PsyNet experiment locally because I see the following error in the terminal (I'm using PsyNet v5.0.2 with Dallinger 7.7):

Exception: Failed to connect to Postgres at postgresql://dallinger:dallinger@localhost/dallinger. Is Postgres running on port 5432?

I tried restarging postgres but did not fix it.

Unfortunately I am unable to share the full experiment code here due to privacy constraints, but I'm hoping someone has familiarity with the error message nonetheless.

Upvotes: 2

Views: 23

Answers (1)

Manuel Anglada Tort
Manuel Anglada Tort

Reputation: 96

I found a solution to the problem above. Sometimes, PostgresSQL crashes and you may get an error like the one above or also like this:

❯❯ There was a problem connecting to the Postgres database!

This problem can be due to several reasons but I found the following procedure to fix this issue robustly:

You can check if PostgreSQL is running normally with postgres -D /usr/local/var/postgres; if the above didn't work, this will return an error.

If there is an error, your db has been corrupted due to the crash. Try the following:

rm /usr/local/var/postgres/postmaster.pid

If this does not work or you cannot find the file (postmaster.pid). Then try the following steps in the same order:

  1. Stop postgress services: brew services stop postgresql
  2. Uninstall postgress in your computer completely: and delete all postgress databases and postgress folders in your computer:
brew uninstall postgresql
rm -rf /usr/local/var/postgres
rm -rf .psql_history .psqlrc .psql.local .pgpass .psqlrc.local
  1. Install postgress again: brew install postgresql
  2. Start postgress: brew services start postgresql
  3. Install db as indicated in the dallinger documentation for creating a new user database (as your computer crashing can cause it to be deleted):
createuser -P dallinger --createdb
(Password: dallinger)
createdb -O dallinger dallinger
createdb -O dallinger dallinger-import

This should solve the problem.

Upvotes: 1

Related Questions