Unable to change SQLite database to Postgres in options.ini file

Hi

Summary

I want to change the database from SQLite to Postgres and configured the options.ini file. But when I try to migrate it keeps ignoring the options.ini configurations.

Any help!

Technical details

  • Kolibri version
  • Operating system
  • Browser

Hi @mikiasephrem,

Sorry to hear you’re running into issues.

Would you please provide the following information:

  • the version of Kolibri you’re using,
  • the operating system Kolibri is installed on, and
  • the contents of the options.ini file

Regards,
Blaine

Hi @blaine,

Thanks for the response.

Kolibri version = 0.14.3
OS = Ubuntu 16.04
Contents of Options.ini

[Database]
DATABASE_ENGINE=“postgres”
DATABASE_NAME=“db_name”
DATABASE_HOST=“localhost”
DATABASE_USER=“db_user”
DATABASE_PASSWORD=“db_user_password”
DATABASE_PORT = 5432

I tried it without the double quotes too. No other values are changed other than this.

Hi @mikiasephrem,

Thank you. Luckily for my sake at least, you omitted or didn’t include sensitive information from the options.ini contents. Please make sure of that going forward.

Have you created a user and database within PostgreSQL for those parameters, for example: database name, user, and password? And you’re able to connect to the database using psql CLI? A command like this should tell you if it can connect, using the info from above (enter the password when it prompts):

$ psql --host=localhost --username=db_user --password --command="select 'Yes, connection works';" db_name

If you see Yes, connection works in the output, then the connection is working.

Please note, there is currently no automated functionality that will migrate the SQLite database contents to the PostgreSQL database. One manual option is to use a tool called pgloader.

Regards,
Blaine

Hi @blaine,

Thanks for your response. I upgraded my Kolibri to 0.14.6 and it is giving me the following error.

@mikiasephrem

Did you perhaps still have the custom database configuration in Kolibri’s options.ini file? If so, you might try removing that configuration, and restarting Kolibri.

@blaine

I did remove the configuration in Kolibri’s option.ini file and restarted Kolibri. It is the same error.

@mikiasephrem

Thanks for checking the options.ini. I attempted to reproduce your issue but I wasn’t able to. I do have two ideas for debugging:

  1. The error is coming from a pysqlite2 package, which my Kolibri doesn’t seem to need or use. I was able to install it using pip install pysqlite creating a pysqlite2 directory, and also required installing libsqlite3-dev. Do you recall having to install those manually? If so, you might try re-installing them.
  2. It’s possible there’s an issue with the database file. If it’s possible for you to send me the database file, that would be helpful in debugging your issue. Please send me a direct message if you’re willing to send it.

Regards,
Blaine

Hi @mikiasephrem,

I have some new insight for you, thanks to my co-worker Jamie who randomly ran across something that could be related to this. He found when performing a SQL dump from PostgreSQL, it quoted a column named order as seen in the image below. In combination with your screenshot of the error, which says error near "order", it seems it could be related to setting up Kolibri with PostgreSQL?

Regards,
Blaine

Hi @blaine

Thanks for following up on this and sorry for the late replay. I think you are right. Is there any documentation on setting up Kolibri with PostgreSQL? if you don’t mind me asking.

Hi @blaine,

Just want to update you on this. I have managed to configure PostgreSQL with Kolibri without any data in it but the Kolibri is not starting up. Here is the terminal screenshot and log file.

Please note that the option.ini settings are ignored.

INFO 2021-03-08 15:29:05,619 kolibri.utils.cli Going to background mode, logging to /root/.kolibri/logs/kolibri.txt
INFO 2021-03-08 15:29:05,627 kolibri.utils.server Starting Kolibri 0.14.6
INFO 2021-03-08 15:29:05,648 cherrypy.error ENGINE Listening for SIGHUP.
INFO 2021-03-08 15:29:05,649 cherrypy.error ENGINE Listening for SIGUSR1.
INFO 2021-03-08 15:29:05,649 cherrypy.error ENGINE Listening for SIGTERM.
INFO 2021-03-08 15:29:05,649 cherrypy.error ENGINE Listening for SIGINT.
INFO 2021-03-08 15:29:05,650 cherrypy.error ENGINE Bus STARTING
ERROR 2021-03-08 15:29:05,681 cherrypy.error ENGINE Error in ‘start’ listener <bound method ServicesPlugin.start of <kolibri.utils.server.ServicesPlugin object at 0x7f48db093c50>>
Traceback (most recent call last):
File “/usr/local/lib/python2.7/dist-packages/kolibri/dist/cherrypy/process/wspbus.py”, line 230, in publish
output.append(listener(*args, **kwargs))
File “/usr/local/lib/python2.7/dist-packages/kolibri/utils/server.py”, line 87, in start
scheduler.clear_scheduler()
File “/usr/local/lib/python2.7/dist-packages/kolibri/dist/django/utils/functional.py”, line 238, in inner
self._setup()
File “/usr/local/lib/python2.7/dist-packages/kolibri/dist/django/utils/functional.py”, line 386, in _setup
self._wrapped = self._setupfunc()
File “/usr/local/lib/python2.7/dist-packages/kolibri/core/tasks/main.py”, line 111, in __scheduler
return Scheduler(queue=queue, connection=connection)
File “/usr/local/lib/python2.7/dist-packages/kolibri/core/tasks/scheduler.py”, line 63, in init
self.queue = queue(connection=connection)
TypeError: ‘SimpleLazyObject’ object is not callable

INFO 2021-03-08 15:29:05,784 cherrypy.error ENGINE Serving on http://0.0.0.0:8080
ERROR 2021-03-08 15:29:05,785 cherrypy.error ENGINE Shutting down due to error in start listener:
Traceback (most recent call last):
File “/usr/local/lib/python2.7/dist-packages/kolibri/dist/cherrypy/process/wspbus.py”, line 268, in start
self.publish(‘start’)
File “/usr/local/lib/python2.7/dist-packages/kolibri/dist/cherrypy/process/wspbus.py”, line 248, in publish
raise exc
ChannelFailures: TypeError("‘SimpleLazyObject’ object is not callable",)

INFO 2021-03-08 15:29:05,785 cherrypy.error ENGINE Bus STOPPING
INFO 2021-03-08 15:29:05,797 cherrypy.error ENGINE HTTP Server cherrypy._cpwsgi_server.CPWSGIServer((‘0.0.0.0’, 8080)) shut down
ERROR 2021-03-08 15:29:05,799 cherrypy.error ENGINE Error in ‘stop’ listener <bound method ServicesPlugin.stop of <kolibri.utils.server.ServicesPlugin object at 0x7f48db093c50>>
Traceback (most recent call last):
File “/usr/local/lib/python2.7/dist-packages/kolibri/dist/cherrypy/process/wspbus.py”, line 230, in publish
output.append(listener(*args, **kwargs))
File “/usr/local/lib/python2.7/dist-packages/kolibri/utils/server.py”, line 116, in stop
scheduler.shutdown_scheduler()
File “/usr/local/lib/python2.7/dist-packages/kolibri/dist/django/utils/functional.py”, line 238, in inner
self._setup()
File “/usr/local/lib/python2.7/dist-packages/kolibri/dist/django/utils/functional.py”, line 386, in _setup
self._wrapped = self._setupfunc()
File “/usr/local/lib/python2.7/dist-packages/kolibri/core/tasks/main.py”, line 111, in __scheduler
return Scheduler(queue=queue, connection=connection)
File “/usr/local/lib/python2.7/dist-packages/kolibri/core/tasks/scheduler.py”, line 63, in init
self.queue = queue(connection=connection)
TypeError: ‘SimpleLazyObject’ object is not callable

The error would seem to indicate that you’re missing the [Database] line before listing the database specific options in the options.ini. You might also check that there’s only one line with [Database]. Could you verify that?

@blaine

Thanks, this helps.

@blaine

There seems to be a problem with logging in after frequent usage. It seems that when you click to sign in after you input the username and password, it’s not logging in and the sign-in button is disabled.

Here is the link for the XHR file

The issue appears to be that it is trying to log in without sending a password. I assume the account you are attempting to login with is an admin account, and that otherwise you have ‘no password required’ for learners set.

Can you confirm that you have this setting set? Also, have any edits been made to the frontend code that differ from Kolibri 0.14.3, as we’ve not had this issue reported previously, and it seems like it would be a common error.

Hi @richard,

Thanks for your response.

Yes, you are right, the account I am attempting to log in to is an admin account and I can confirm the settings are set to ‘no password required for learners’. As for the frontend code, I did change the default color of Kolibri nothing more.

I just want to ask one thing, is there any command available to reset the settings? Am asking this because I can’t log in as an admin and can’t even access the settings page. And I don’t know if users changed it too. If a command-line setting reset can be done that might resolve the issue.

Please let me know your thoughts.

Hi @mikiasephrem,

You can update these settings through the command line, but you would need to use the Python shell to do so.

You can access this by typing kolibri shell in the command line.

The following code entered into the shell should change this setting:

from kolibri.core.auth.models import FacilityDataset

fd = FacilityDataset.objects.all().get()
fd.learner_can_login_with_no_password = False
fd.save()

This should work, unless you have multiple facilities on the device.

If you have multiple facilities on the device, you will need to first get the specific facility you are updating this setting for:

from kolibri.core.auth.models import Facility

f = Facility.objects.get(name="facilityname")
f.dataset.learner_can_login_with_no_password = False
f.dataset.save()

Where facilityname is the name of the specific facility you are trying to update.

Kind Regards,
Richard

Hi @richard,

Thanks for the commands. But the issue is not resolved. I even tried to create an account and once fill in the information and click Finish it give me the same error as the login. I only have one facility but i tried it with both commands too.