matomomomemo

PostgreSQLサーバーのバージョン確認方法

SQLクライアント経由での取得

文字列で取得①

ref: https://www.postgresql.jp/document/16/html/functions-info.html#FUNCTIONS-INFO-SESSION

クエリ

SELECT * FROM version();

出力

PostgreSQL 14.13 (Ubuntu 14.13-0ubuntu0.22.04.1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0, 64-bit

文字列で取得②

ref: https://www.postgresql.jp/document/16/html/runtime-config-preset.html#GUC-SERVER-VERSION

クエリ

SHOW server_version;

出力

14.13 (Ubuntu 14.13-0ubuntu0.22.04.1)

数値で取得

ref: https://www.postgresql.jp/document/16/html/runtime-config-preset.html#GUC-SERVER-VERSION-NUM

クエリ

SHOW server_version_num;

出力

140013

libpq経由での取得

ref: https://www.postgresql.jp/document/16/html/libpq-status.html#LIBPQ-PQSERVERVERSION

  • libpqが提供する関数経由でも取得できるよう
  • ruby-pgのようなPostgreSQLクライアントのラッパーを実装する際に利用するという理解をしている
  • ruby-pgの場合は このあたりがそうだろうか
static VALUE
pgconn_server_version(VALUE self)
{
	return INT2NUM(PQserverVersion(pg_get_pgconn(self)));
}

リファレンスにも記載があった