Image source: https://docs.datadoghq.com/integrations/postgres/

If you are actively using Rails for developing your projects, then it’s likely that in at least one of your projects you are using PostgreSQL as the database technology. You have already added the pg in your Gemfile and have already started to use it. Then your client asks you about the version of PostgreSQL that you are using, and you may be confused for a bit about it, as you aren’t sure.

You are relying on the great abstractions that Rails do so that you do not waste time on boilerplate and repetitive tasks, but start developing the project.

If you are still reading, then here is what you came here for.

Go to the project directory with the terminal and enter into the Rails console. Once you are there, execute the following:

ActiveRecord::Base.connection.select_value('SELECT version()')

As you can see, you are simply executing an SQL query and executing it through the ActiveRecord module. This means that you can find its version by running SELECT version() inside a PostgreSQL client as well and get the answer.

That’s it for this quick trick. I hope it helps you give the answer to your client.