How to check server version bt SQL?

sql

(Yonghwan SO) #1

Hi, while I write a application with cockroach, I found some differeces between versions and I want conditional statement for each versions. For this, I need version of connected server by SQL but I have no idea. How can I check version of currently connected server by SQL?


(Ron Arévalo) #2

Hi @sio4,

Just wanted to get some clarification on your question. Are you running multiple instances of CockroachDB and you want to know what version you are running by using SQL statements?

Thanks,

Ron


(Ron Arévalo) #3

Hi @sio4,

I just wanted to follow up here, What is the main issue you’re looking to solve? If you’re running multiple instances of CRDB, that isn’t something we recommend, but if you have a specific use case you’re looking to solve we may have a better way of solving your problem.

Ron


(Raphael 'kena' Poss) #4

you can run select version() in SQL to find the current version of the server.

This works in both PostgreSQL and CockroachDB. The content of the string will help you distinguish both postgres vs cockroachdb, and which version of the cockroachdb program your client is connected to.

Once you have established that the server is running CockroachDB 2.0 or later, you should also run show cluster setting version, which will reveal the “feature level” of the cockroachdb cluster.


(Yonghwan SO) #5

Thanks @ronarev and @knz!
My case is, just figure out there are some clusters with difference version without any relation. Like yours and mine. The case is, while I tried to fix an issue on an open source project, I got to know the structure of information_schema is different between versions. So I want to add conditional statement on that part of code, so it can work properly by working differently by versions.
Thanks!


(Raphael 'kena' Poss) #6

Thanks for explaining.

You have two ways.

  • either use select version() as discussed above. This is done e.g. in the SQLAlchemy adapter, see here: https://github.com/cockroachdb/cockroachdb-python/blob/master/cockroachdb/sqlalchemy/dialect.py#L74-L90

  • when the client drivers open the connection it receives a list of “postgres status parameters”. This includes various standard postgres settings like the time zone; in CockroachDB it also includes the status parameter called “crdb_version”. This will contain a version number you can use for choosing how to access information_schema.


(Yonghwan SO) #7

Oh! Nice! Thanks so much for detail information.

By the way, on my chrome on android, links and buttons are white on white. Is it my own problem? (I just tell here since you are Roacher :slight_smile:


(Raphael 'kena' Poss) #8

Yes I can see that too. Will report.