Issue after using pgcryptofield

Hi,

I am facing issue while using the django-pgcrypto-fields. Model has charsymmetricfield and emailsymmetricfield.

After using this 2 field in models. Django admin page is super slow uts taking around 1 min to load single page?

Also added pgcrypto extension in postgres sql for above 2 encrypted model column.

As far as i debug abdy my finding are below

  1. no time increase in sql query before and after adding pgcrypto.

  2. when i stated server in debug mode then there is time gap between the when i hit the page load button and the log display at server side… And this time gap is huge around 40 sec.

To add Pgcrypto in system i follow below steps

  1. added pgcrypto in INSTALLED_APP in base settings.
  2. added django-pgcrypto-fields plug in.
  3. replace model char fields to charpgpsymmetric fields.
  4. copy data in encrypted format in encrypted fields.

Any input will be very helpful, as system is very slow.

Is it every page showing this effect, or only those pages using those fields? (Or can you identify any models whose pages are not affected?)

Only those model which are using encrypted field. If i change encrypted field to model char field then django admin work perfectly.

Pages which have foreign key relationship with encrypted field model also impacted

Is this happening only on the “list” pages or does it happen on an “edit” page?

Also, what happens if you exclude those fields from the admin?

Its only list page, when i opened edit page and back to list again its taking time.

Excluding encrypted field also not helping, it is stilll slow.

Created one end point and try to hit from Postman again the list page is slow

Since this is a third-party package, have you checked with them? (Perhaps checked their github issues?) That would be the first place to look.

If I had to try and track this down, I’d be running a number of tests from the Django shell with different queries on different fields / combinations of fields to try and identify where the time is being consumed.

This would include combinations of queries with applying filters to restrict the number of rows being returned and using “only” with specifying only non-encrypted fields to change the select statement being issued.

Superficially, the symptoms you’re describing are being caused by Django / PostgreSQL having to decrypt a large amount of data for those pages - but that’s just conjecture based on that information.

I might also try running some of those same queries directly on the database engine to determine whether the issue is happening within Django or PostgreSQL.

Thanks for you input,

Its sql query which generated by django ORM, which in short taking time, we used new -relic to analyse flow and found sql query itself taking around 54 sec