HomeMogDBMogDB StackUqbar
v3.1

Documentation:v3.1

Supported Versions:

Other Versions:

Session Information Functions

  • current_catalog

    Description: Name of the current database (called "catalog" in the SQL standard)

    Return type: name

    Example:

    MogDB=# SELECT current_catalog;
     current_database
    ------------------
     mogdb
    (1 row)
  • current_database()

    Description: Name of the current database

    Return type: name

    Example:

    MogDB=# SELECT current_database();
     current_database
    ------------------
     mogdb
    (1 row)
  • current_query()

    Description: Text of the currently executing query, as submitted by the client (might contain more than one statement)

    Return type: text

    Example:

    MogDB=# SELECT current_query();
          current_query
    -------------------------
     SELECT current_query();
    (1 row)
  • current_schema[()]

    Description: Name of current schema

    Return type: name

    Example:

    MogDB=# SELECT current_schema();
     current_schema
    ----------------
     public
    (1 row)

    Remarks: current_schema returns the first valid schema name in the search path. (If the search path is empty or contains no valid schema name, NULL is returned.) This is the schema that will be used for any tables or other named objects that are created without specifying a target schema.

  • current_schemas(Boolean)

    Description: Names of schemas in search path

    Return type: name[]

    Example:

    MogDB=# SELECT current_schemas(true);
       current_schemas
    ---------------------
     {pg_catalog,public}
    (1 row)

    Note:

    current_schemas(Boolean) returns an array of the names of all schemas presently in the search path. The Boolean option determines whether implicitly included system schemas such as pg_catalog are included in the returned search path.

    img NOTE: The search path can be altered at run time by running the following command:

    SET search_path TO schema [, schema, ...]
  • current_user

    Description: User name of current execution context

    Return type: name

    Example:

    MogDB=# SELECT current_user;
     current_user
    --------------
     omm
    (1 row)

    Note: current_user is the user identifier that is applicable for permission checking. Normally it is equal to the session user, but it can be changed with SET ROLE. It also changes during the execution of functions with the attribute SECURITY DEFINER.

  • definer_current_user

    Description: User name of current execution context

    Return type: name

    Example:

    MogDB=# SELECT definer_current_user();
     definer_current_user
    ----------------------
     omm
    (1 row)
  • pg_current_sessionid()

    Description: Session ID of the current execution context

    Return type: text

    Example:

    MogDB=# SELECT pg_current_sessionid();
        pg_current_sessionid
    ----------------------------
     1579228402.140190434944768
    (1 row)

    Note: pg_current_sessionid() is used to obtain the session ID in the current execution context. The structure of the value is Timestamp. Session ID. When enable_thread_pool is set to off, the actual session ID is the thread ID.

  • pg_current_sessid

    Description: Session ID of the current execution context

    Return type: text

    Example:

    MogDB=# select pg_current_sessid();
    pg_current_sessid
    -------------------
    140308875015936
    (1 row)

    Note: In thread pool mode, the session ID of the current session is obtained. In non-thread pool mode, the background thread ID of the current session is obtained.

  • pg_current_userid

    Description: Current user ID.

    Return type: text

    MogDB=# SELECT pg_current_userid();
    pg_current_userid
    -------------------
    10
    (1 row)
  • working_version_num()

    Description: Returns a version number regarding system compatibility.

    Return type: int

    Example:

    MogDB=# SELECT working_version_num();
     working_version_num
    ---------------------
                   92231
    (1 row)
    
  • tablespace_oid_name()

    Description: Queries the tablespace name based on the tablespace OID.

    Return type: text

    Example:

    MogDB=# select tablespace_oid_name(1663);
     tablespace_oid_name
    ---------------------
     pg_default
    (1 row)
  • inet_client_addr()

    Description: Remote connection address. inet_client_addr returns the IP address of the current client.

    img NOTE: It is available only in remote connection mode.

    Return type: inet

    Example:

    MogDB=# SELECT inet_client_addr();
     inet_client_addr
    ------------------
     10.10.0.50
    (1 row)
  • inet_client_port()

    Description: Remote connection port. And inet_client_port returns the port number of the current client.

    img NOTE: It is available only in remote connection mode.

    Return type: int

    Example:

    MogDB=# SELECT inet_client_port();
     inet_client_port
    ------------------
                33143
    (1 row)
  • inet_server_addr()

    Description: Local connection address. inet_server_addr returns the IP address on which the server accepted the current connection.

    img NOTE: It is available only in remote connection mode.

    Return type: inet

    Example:

    MogDB=# SELECT inet_server_addr();
     inet_server_addr
    ------------------
     10.10.0.13
    (1 row)
  • inet_server_port()

    Description: Local connection port. inet_server_port returns the port number. All these functions return NULL if the current connection is via a Unix-domain socket.

    img NOTE: It is available only in remote connection mode.

    Return type: int

    Example:

    MogDB=# SELECT inet_server_port();
     inet_server_port
    ------------------
                 8000
    (1 row)
  • pg_conf_load_time()

    Description: Configures load time. pg_conf_load_time returns the timestamp with time zone when the server configuration files were last loaded.

    Return type: timestamp with time zone

    Example:

    MogDB=# SELECT pg_conf_load_time();
          pg_conf_load_time
    ------------------------------
     2017-09-01 16:05:23.89868+08
    (1 row)
  • pg_my_temp_schema()

    Description: OID of the temporary schema of a session. The value is 0 if the OID does not exist.

    Return type: oid

    Example:

    MogDB=# SELECT pg_my_temp_schema();
     pg_my_temp_schema
    -------------------
                     0
    (1 row)

    Note: pg_my_temp_schema returns the OID of the current session's temporary schema, or zero if it has none (because it has not created any temporary tables). pg_is_other_temp_schema returns true if the given OID is the OID of another session's temporary schema.

  • pg_is_other_temp_schema(oid)

    Description: Specifies whether the schema is the temporary schema of another session.

    Return type: Boolean

    Example:

    MogDB=# SELECT pg_is_other_temp_schema(25356);
     pg_is_other_temp_schema
    -------------------------
     f
    (1 row)
  • pg_listening_channels()

    Description: Channel names that the session is currently listening on

    Return type: SETOF text

    Example:

    MogDB=# SELECT pg_listening_channels();
     pg_listening_channels
    -----------------------
    (0 rows)

    Note: pg_listening_channels returns a set of names of channels that the current session is listening to.

  • pg_postmaster_start_time()

    Description: Server start time pg_postmaster_start_time returns the timestamp with time zone when the server started.

    Return type: timestamp with time zone

    Example:

    MogDB=# SELECT pg_postmaster_start_time();
       pg_postmaster_start_time
    ------------------------------
     2017-08-30 16:02:54.99854+08
    (1 row)
  • pg_get_ruledef(rule_oid)

    Description: Obtains the CREATE RULE command for a rule.

    Return type: text

    Example:

    MogDB=# select * from pg_get_ruledef(24828);
                                    pg_get_ruledef
    -------------------------------------------------------------------
     CREATE RULE t1_ins AS ON INSERT TO t1 DO INSTEAD INSERT INTO t2 (id) VALUES (new.id);
    (1 row)
  • sessionid2pid()

    Description: Obtains PID information from a session ID (for example, the sessid column in gs_session_stat).

    Return type: int8

    Example:

    MogDB=# select sessionid2pid(sessid::cstring) from gs_session_stat limit 2;
      sessionid2pid
    -----------------
     139973107902208
     139973107902208
    (2 rows)
  • pg_trigger_depth()

    Description: Current nesting level of triggers

    Return type: int

    Example:

    MogDB=# SELECT pg_trigger_depth();
     pg_trigger_depth
    ------------------
                    0
    (1 row)
  • session_user

    Description: Session user name

    Return type: name

    Example:

    MogDB=# SELECT session_user;
     session_user
    --------------
     omm
    (1 row)

    Note: session_user is usually the user who initiated the current database connection, but administrators can change this setting with SET SESSION AUTHORIZATION.

  • user

    Description: Equivalent to current_user.

    Return type: name

    Example:

    MogDB=# SELECT user;
     current_user
    --------------
     omm
    (1 row)
  • getpgusername()

    Description: Obtains the database username.

    Return type: name

    Example:

    MogDB=# select getpgusername();
     getpgusername
    ---------------
     GaussDB_userna
    (1 row)
  • getdatabaseencoding()

    Description: Obtains the database encoding mode.

    Return type: name

    Example:

    MogDB=# select getdatabaseencoding();
     getdatabaseencoding
    ---------------------
     SQL_ASCII
    (1 row)
  • version()

    Description: Version information. version returns a string describing a server's version.

    Return type: text

    Example:

    MogDB=# select version();
    version
    -------------------------------------------------------------------------------------------------------------------------------------------------------------
    (MogDB 3.0.1 build 62408a0f) compiled at 2022-06-30 15:06:56 commit 0 last mr   on aarch64-unkno
    wn-linux-gnu, compiled by g++ (GCC) 7.3.0, 64-bit
    (1 row)
  • opengauss_version()

    Description: MogDB version information

    Return type: text

    Example:

    MogDB=# select opengauss_version();
     opengauss_version
    -------------------
     3.0.1
    (1 row)
  • gs_deployment()

    Description: Information about the deployment mode of the current system

    Return type: text

    Example:

    MogDB=# select gs_deployment();
        gs_deployment
    -----------------------
    OpenSourceCentralized
    (1 row)
  • get_hostname()

    Description: Returns the host name of the current node.

    Return type: text

    Example:

    MogDB=# SELECT get_hostname();
     get_hostname
    --------------
     linux-user
    (1 row)
  • get_nodename()

    Description: Returns the name of the current node.

    Return type: text

    Example:

    MogDB=# SELECT get_nodename();
     get_nodename
    --------------
     datanode1
    (1 row)
  • get_schema_oid(cstring)

    Description: Returns the OID of the queried schema.

    Return type: oid

    Example:

    MogDB=# SELECT get_schema_oid('public');
     get_schema_oid
    ----------------
               2200
    (1 row)
  • get_client_info()

    Description: Returns client information.

    Return type: record

Copyright © 2011-2024 www.enmotech.com All rights reserved.