Session information functions

更新时间:
复制 MD 格式

Hologres is compatible with PostgreSQL and supports standard PostgreSQL syntax for session information functions. The functions listed here are a subset of the PostgreSQL system information functions.

Supported functions

FunctionSyntaxReturn typeDescription
CURRENT_CATALOGCURRENT_CATALOGnameReturns the name of the current catalog.
CURRENT_DATABASECURRENT_DATABASE()nameReturns the name of the current database.
CURRENT_QUERYCURRENT_QUERY()textReturns the query statement being executed.
CURRENT_ROLECURRENT_ROLEnameReturns the account ID used for database operations.
CURRENT_SCHEMACURRENT_SCHEMA[()]nameReturns the name of the current schema. Parentheses are optional.
CURRENT_SCHEMASCURRENT_SCHEMAS(boolean)name[]Returns an array of schema names in the current search path.
CURRENT_USERCURRENT_USERnameReturns the ID of the current account.
INET_CLIENT_ADDRINET_CLIENT_ADDR()inetReturns the IP address of the current client connection.
INET_CLIENT_PORTINET_CLIENT_PORT()integerReturns the port of the current client connection.
INET_SERVER_ADDRINET_SERVER_ADDR()inetReturns the IP address of the current server.
INET_SERVER_PORTINET_SERVER_PORT()integerReturns the port of the current server.
PG_BACKEND_PIDPG_BACKEND_PID()integerReturns the process ID (PID) of the server process for the current session.
PG_BLOCKING_PIDSPG_BLOCKING_PIDS(integer)integer[]Returns the PIDs of processes blocking the specified backend process from acquiring a lock.
SESSION_USERSESSION_USERnameReturns the account ID of the user for the current session.
USERUSERnameReturns the account ID of the current logon user.
VERSIONVERSION()textReturns the PostgreSQL version string.

CURRENT_CATALOG

Returns the name of the current catalog.

Syntax

CURRENT_CATALOG

Return type: name

Example

SELECT CURRENT_CATALOG;

Result:

 current_catalog
-----------------
 hologrestest

CURRENT_DATABASE

Returns the name of the current database.

Syntax

CURRENT_DATABASE()

Return type: name

Example

SELECT CURRENT_DATABASE();

Result:

 current_database
------------------
 hologrestest

CURRENT_QUERY

Returns the query statement being executed.

Syntax

CURRENT_QUERY()

Return type: text

Example

SELECT CURRENT_QUERY();

Result:

      current_query
-------------------------
 SELECT CURRENT_QUERY();

CURRENT_ROLE

Returns the account ID used for database operations.

Syntax

CURRENT_ROLE

Return type: name

Example

SELECT CURRENT_ROLE;

Result:

   current_role
------------------
 139699392458****

CURRENT_SCHEMA

Returns the name of the current schema. The parentheses are optional.

Syntax

CURRENT_SCHEMA[()]

Return type: name

Example

SELECT CURRENT_SCHEMA();

Result:

 current_schema
----------------
 public

CURRENT_SCHEMAS

Returns an array of schema names visible in the current search path.

Syntax

CURRENT_SCHEMAS(boolean)

Parameters

ParameterTypeDescription
booleanbooleanWhen TRUE, implicit schemas such as pg_catalog are included. When FALSE, they are excluded.

Return type: name[]

Examples

Include implicit schemas:

SELECT CURRENT_SCHEMAS(TRUE);

Result:

   current_schemas
---------------------
 {pg_catalog,public}

Exclude implicit schemas:

SELECT CURRENT_SCHEMAS(FALSE);

Result:

   current_schemas
---------------------
 {public}

CURRENT_USER

Returns the ID of the current account.

Syntax

CURRENT_USER

Return type: name

Example

SELECT CURRENT_USER;

Result:

   current_user
------------------
 139699392458****

INET_CLIENT_ADDR

Returns the IP address of the current client connection.

Syntax

INET_CLIENT_ADDR()

Return type: inet

Example

SELECT INET_CLIENT_ADDR();

Result:

 inet_client_addr
------------------
 124.8*.1**.1**

INET_CLIENT_PORT

Returns the port of the current client connection.

Syntax

INET_CLIENT_PORT()

Return type: integer

Example

SELECT INET_CLIENT_PORT();

Result:

 inet_client_port
------------------
             5823

INET_SERVER_ADDR

Returns the IP address of the current server.

Syntax

INET_SERVER_ADDR()

Return type: inet

Example

SELECT INET_SERVER_ADDR();

Result:

  inet_server_addr
------------------
  10.**.4*.4*

INET_SERVER_PORT

Returns the port of the current server.

Syntax

INET_SERVER_PORT()

Return type: integer

Example

SELECT INET_SERVER_PORT();

Result:

  inet_server_port
------------------
            42581

PG_BACKEND_PID

Returns the process ID (PID) of the server process attached to the current session.

Syntax

PG_BACKEND_PID()

Return type: integer

Example

SELECT PG_BACKEND_PID();

Result:

 pg_backend_pid
----------------
       53674002

PG_BLOCKING_PIDS

Returns an array of backend process IDs that are blocking the specified backend process from acquiring a lock. Returns an empty array ({}) if no blocking processes exist.

Syntax

PG_BLOCKING_PIDS(integer)

Parameters

ParameterTypeDescription
integerintegerThe backend process ID to check for blockers. Use PG_BACKEND_PID() to get the current session's PID.

Return type: integer[]

Example

SELECT PG_BLOCKING_PIDS(1);

Result:

 pg_blocking_pids
------------------
 {}

SESSION_USER

Returns the account ID of the user for the current session.

Syntax

SESSION_USER

Return type: name

Example

SELECT SESSION_USER;

Result:

   session_user
------------------
 139699392458****

USER

Returns the account ID of the current logon user.

Syntax

USER

Return type: name

Example

SELECT USER;

Result:

       user
------------------
 139699392458****

VERSION

Returns the PostgreSQL version string, including build details.

Syntax

VERSION()

Return type: text

Example

SELECT VERSION();

Result:

                                                                                               version
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 PostgreSQL 11.3 (Release-build@6feee25dff7 on release-3.0.x) on x86_64-linux, compiled by clang version 13.0.1 (Alibaba 13.0.1-2.fix20240305102602.alios7 193811f571966bccce929b0f457df345c4fca5ed)