khoj-ai / khoj

Your AI second brain. Get answers to your questions, whether they be online or in your own notes. Use online AI models (e.g gpt4) or private, local LLMs (e.g llama3). Self-host locally or use our cloud instance. Access from Obsidian, Emacs, Desktop app, Web or Whatsapp.

Home Page:https://khoj.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

can not start server

Fuckingnameless opened this issue · comments

cat pyvenv.cfg
home = /usr/bin
include-system-site-packages = false
version = 3.9.2

~/AI/khoj/env2$ khoj --anonymous-mode

Traceback (most recent call last):
File "/home/dietpi/.local/lib/python3.9/site-packages/django/db/backends/base/base.py", line 289, in ensure_connection
self.connect()
File "/home/dietpi/.local/lib/python3.9/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/dietpi/.local/lib/python3.9/site-packages/django/db/backends/base/base.py", line 270, in connect
self.connection = self.get_new_connection(conn_params)
File "/home/dietpi/.local/lib/python3.9/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/dietpi/.local/lib/python3.9/site-packages/django/db/backends/postgresql/base.py", line 275, in get_new_connection
connection = self.Database.connect(**conn_params)
File "/home/dietpi/.local/lib/python3.9/site-packages/psycopg2/init.py", line 122, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: connection to server at "localhost" (::1), port 5432 failed: Connection refused
Is the server running on that host and accepting TCP/IP connections?
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?

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/usr/local/bin/khoj", line 5, in
from khoj.main import run
File "/usr/local/lib/python3.9/dist-packages/khoj/main.py", line 42, in
call_command("migrate", "--noinput")
File "/home/dietpi/.local/lib/python3.9/site-packages/django/core/management/init.py", line 194, in call_command
return command.execute(*args, **defaults)
File "/home/dietpi/.local/lib/python3.9/site-packages/django/core/management/base.py", line 458, in execute
output = self.handle(*args, **options)
File "/home/dietpi/.local/lib/python3.9/site-packages/django/core/management/base.py", line 106, in wrapper
res = handle_func(*args, **kwargs)
File "/home/dietpi/.local/lib/python3.9/site-packages/django/core/management/commands/migrate.py", line 117, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "/home/dietpi/.local/lib/python3.9/site-packages/django/db/migrations/executor.py", line 18, in init
self.loader = MigrationLoader(self.connection)
File "/home/dietpi/.local/lib/python3.9/site-packages/django/db/migrations/loader.py", line 58, in init
self.build_graph()
File "/home/dietpi/.local/lib/python3.9/site-packages/django/db/migrations/loader.py", line 235, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "/home/dietpi/.local/lib/python3.9/site-packages/django/db/migrations/recorder.py", line 81, in applied_migrations
if self.has_table():
File "/home/dietpi/.local/lib/python3.9/site-packages/django/db/migrations/recorder.py", line 57, in has_table
with self.connection.cursor() as cursor:
File "/home/dietpi/.local/lib/python3.9/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/dietpi/.local/lib/python3.9/site-packages/django/db/backends/base/base.py", line 330, in cursor
return self._cursor()
File "/home/dietpi/.local/lib/python3.9/site-packages/django/db/backends/base/base.py", line 306, in _cursor
self.ensure_connection()
File "/home/dietpi/.local/lib/python3.9/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/dietpi/.local/lib/python3.9/site-packages/django/db/backends/base/base.py", line 289, in ensure_connection
self.connect()
File "/home/dietpi/.local/lib/python3.9/site-packages/django/db/utils.py", line 91, in exit
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/dietpi/.local/lib/python3.9/site-packages/django/db/backends/base/base.py", line 289, in ensure_connection
self.connect()
File "/home/dietpi/.local/lib/python3.9/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/dietpi/.local/lib/python3.9/site-packages/django/db/backends/base/base.py", line 270, in connect
self.connection = self.get_new_connection(conn_params)
File "/home/dietpi/.local/lib/python3.9/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/dietpi/.local/lib/python3.9/site-packages/django/db/backends/postgresql/base.py", line 275, in get_new_connection
connection = self.Database.connect(**conn_params)
File "/home/dietpi/.local/lib/python3.9/site-packages/psycopg2/init.py", line 122, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: connection to server at "localhost" (::1), port 5432 failed: Connection refused
Is the server running on that host and accepting TCP/IP connections?
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?

Hi @Fuckingnameless , it looks like you're using the python package in this issue, rather than the docker file?

Is it possible you have another postgres instance up and running? Would you be able to check and kill any active processes, as described in this post? Check via lsof -n -i:5432 | grep LISTEN.

Otherwise, can you try removing the volume and starting the container again from scratch? It's possible it was initialized previously with a different config.

  1. Run docker volume ls to get the correct volume name. It's probably something like khoj_khoj_db
  2. Run docker volume rm to delete the volume.
  3. Run docker-compose up with the same config to try and recreate the volume.

Just make sure first that you don't have the Postgres engine running on your machine.

yes, when the docker version didn't work i went to the python one

lsof -n -i:5432 | grep LISTEN.
i think i did this already but will check tomorrow

Thanks for the fast response.

Hey @Fuckingnameless , just wanted to check and see if you were able to debug any further. Let me know if you've run into any other issues.

same error on win10 like Fuckingnameless

create venv in powershell, all download and install fine without any error

your suggestion dont help me iam not that good in python ;)

.....
(.venv) PS F:\khoj> khoj
Traceback (most recent call last):
File "F:\khoj.venv\Lib\site-packages\django\db\backends\base\base.py", line 289, in ensure_connection
self.connect()
File "F:\khoj.venv\Lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "F:\khoj.venv\Lib\site-packages\django\db\backends\base\base.py", line 270, in connect
self.connection = self.get_new_connection(conn_params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\khoj.venv\Lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "F:\khoj.venv\Lib\site-packages\django\db\backends\postgresql\base.py", line 275, in get_new_connection
connection = self.Database.connect(**conn_params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\khoj.venv\Lib\site-packages\psycopg2_init_.py", line 122, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
psycopg2.OperationalError: connection to server at "localhost" (::1), port 5432 failed: Connection refused (0x0000274D/10061)
Is the server running on that host and accepting TCP/IP connections?
connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection refused (0x0000274D/10061)
Is the server running on that host and accepting TCP/IP connections?

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "", line 198, in run_module_as_main
File "", line 88, in run_code
File "F:\khoj.venv\Scripts\khoj.exe_main
.py", line 4, in
File "F:\khoj.venv\Lib\site-packages\khoj\main.py", line 42, in
call_command("migrate", "--noinput")
File "F:\khoj.venv\Lib\site-packages\django\core\management_init
.py", line 194, in call_command
return command.execute(*args, **defaults)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\khoj.venv\Lib\site-packages\django\core\management\base.py", line 458, in execute
output = self.handle(*args, **options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\khoj.venv\Lib\site-packages\django\core\management\base.py", line 106, in wrapper
res = handle_func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\khoj.venv\Lib\site-packages\django\core\management\commands\migrate.py", line 117, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\khoj.venv\Lib\site-packages\django\db\migrations\executor.py", line 18, in init
self.loader = MigrationLoader(self.connection)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\khoj.venv\Lib\site-packages\django\db\migrations\loader.py", line 58, in init
self.build_graph()
File "F:\khoj.venv\Lib\site-packages\django\db\migrations\loader.py", line 235, in build_graph
self.applied_migrations = recorder.applied_migrations()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\khoj.venv\Lib\site-packages\django\db\migrations\recorder.py", line 81, in applied_migrations
if self.has_table():
^^^^^^^^^^^^^^^^
File "F:\khoj.venv\Lib\site-packages\django\db\migrations\recorder.py", line 57, in has_table
with self.connection.cursor() as cursor:
^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\khoj.venv\Lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "F:\khoj.venv\Lib\site-packages\django\db\backends\base\base.py", line 330, in cursor
return self._cursor()
^^^^^^^^^^^^^^
File "F:\khoj.venv\Lib\site-packages\django\db\backends\base\base.py", line 306, in cursor
self.ensure_connection()
File "F:\khoj.venv\Lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "F:\khoj.venv\Lib\site-packages\django\db\backends\base\base.py", line 288, in ensure_connection
with self.wrap_database_errors:
File "F:\khoj.venv\Lib\site-packages\django\db\utils.py", line 91, in exit
raise dj_exc_value.with_traceback(traceback) from exc_value
File "F:\khoj.venv\Lib\site-packages\django\db\backends\base\base.py", line 289, in ensure_connection
self.connect()
File "F:\khoj.venv\Lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "F:\khoj.venv\Lib\site-packages\django\db\backends\base\base.py", line 270, in connect
self.connection = self.get_new_connection(conn_params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\khoj.venv\Lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "F:\khoj.venv\Lib\site-packages\django\db\backends\postgresql\base.py", line 275, in get_new_connection
connection = self.Database.connect(**conn_params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\khoj.venv\Lib\site-packages\psycopg2_init
.py", line 122, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
django.db.utils.OperationalError: connection to server at "localhost" (::1), port 5432 failed: Connection refused (0x0000274D/10061)
Is the server running on that host and accepting TCP/IP connections?
connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection refused (0x0000274D/10061)
Is the server running on that host and accepting TCP/IP connections?

(.venv) PS F:\khoj>

hey @kalle07 , if you're using the python package, you'll have to setup postgres in your backend as well. Have you gone through these setup instructions: https://docs.khoj.dev/get-started/setup#installation-option-2-local?

The resolution for the original issue with the docker setup not finding the postgres user is to delete the postgres docker volume and recreate it.
docker volume ls ; get a list of docker volumes on your machine
docker volume rm khoj_khoj_db; remove the db volume
docker-compose up; restart the container

Closing issue as I've confirmed with another use that above^ resolved the issue. If setup still has persistent problems, please open a new issue.

i see, you work with pgvector (experimentaL) or docker which need WSL2 which dont work on my machine and i dont want have it!
why other eg. gptprivate can live without that, is yours such as much better ?