Search code examples
pythonpostgresqlflask-sqlalchemycitus

Using CitusDB with SQL-alchemy


I am using caravel with CitusDB and I am running into problems connecting to the database node. To be frank, I have no clue what to do.

I followed the official installation instructions to install and run.

I can log into the running master using the psql script in /opt/citusdb/4.0/bin but I can't connect to it from the application. Flask-SQLAlchemy supports the postgresql dialect and driver and the server running seems to be on the 5432 port. I am trying it with psycopg2.

I have turned off the postgresql service because that was interfering with the master node start-up.

This is the error:

2016-04-28 10:10:53,487:ERROR:flask_appbuilder.security.sqla.manager:DB Creation and initialization failed: (psycopg2.OperationalError) could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

Solution

  • Thanks to @Ahmet Eren Başak I was able to look at problem from a new angle.

    The key to this problem was the pid file of the running server. psycopg2 and postgresql in general refer to the /var/run/postgresql/ directory to see if the server is running. CitusDB apparently does not have permission to edit/create files in this directory. Hence, the pid file is created in /tmp/.

    The solution was to link this file to /var/run/postgresql/ and that solved it

    ln -s /tmp/.s.PGSQL.5432 /var/run/postgresql/.s.PGSQL.5432