I want to know version of the default Postgres database. How to find it using Django?
Get a database connection:
from django.db import connection
And access the inner psycopg2 connection object:
print(connection.cursor().connection.server_version)
One-liner:
$ python3 manage.py shell -c "from django.db import connection; print(connection.cursor().connection.server_version)"
90504
The number is formed by converting the major, minor, and revision numbers into two-decimal-digit numbers and appending them together. For example, version 8.1.5 will be returned as 80105.
Docs: http://initd.org/psycopg/docs/connection.html#connection.server_version
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With