Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Querying System Catalogs

Updated on 2024-05-07 GMT+08:00

In addition to the created tables, a database contains many system catalogs. These system catalogs contain database installation information and information about various queries and processes in GaussDB. You can obtain information about the database by querying system catalogs.

In System Catalogs and System Views, the description about each table specifies whether the table is visible to all users or only the initial user. To query tables that are visible only to the initial user, log in as the initial user.

GaussDB provides the following types of system catalogs and views:

  • PostgreSQL-compatible system catalogs and views

    These system catalogs and views have the prefix PG.

  • New system catalogs and system views of GaussDB

    These system catalogs and views have the prefix GS.

Querying Database Tables

Create tables in the public schema.
gaussdb=#  CREATE TABLE public.search_table_t1(a int);
CREATE TABLE
gaussdb=#  CREATE TABLE public.search_table_t2(b int);
CREATE TABLE
gaussdb=#  CREATE TABLE public.search_table_t3(c int);
CREATE TABLE
gaussdb=#  CREATE TABLE public.search_table_t4(d int);
CREATE TABLE
gaussdb=#  CREATE TABLE public.search_table_t5(e int);
CREATE TABLE
In the PG_TABLES system catalog, view the tables prefixed with search_table in the public schema.
1
gaussdb=#  SELECT distinct(tablename) FROM pg_tables WHERE SCHEMANAME = 'public' AND TABLENAME LIKE 'search_table%';
The result is as follows:
1
2
3
4
5
6
7
8
    tablename
-----------------
 search_table_t1
 search_table_t2
 search_table_t3
 search_table_t4
 search_table_t5
(5 rows)

Viewing Database Users

You can use PG_USER to view the list of all users in the database, and view the user ID (USESYSID) and permissions.

1
SELECT * FROM pg_user; 
 usename | usesysid | usecreatedb | usesuper | usecatupd | userepl |  passwd  | valbegin | valuntil |   respool    | parent | spacelimit | useconfig | no
degroup | tempspacelimit | spillspacelimit | usemonitoradmin | useoperatoradmin | usepolicyadmin
---------+----------+-------------+----------+-----------+---------+----------+----------+----------+--------------+--------+------------+-----------+---
--------+----------------+-----------------+-----------------+------------------+----------------
 omm     |       10 | t           | t        | t         | t       | ******** |          |          | default_pool |      0 |            |           |
        |                |                 | t               | t                | t

Viewing and Stopping the Running Query Statements

You can view the running query statements in the PG_STAT_ACTIVITY view. You can use the following methods:

  1. Set the parameter track_activities to on.

    1
    SET track_activities = on;
    

    The database obtains the running information about active queries only if the parameter is set to on.

  2. View the running query statements. View the database names, users performing queries, query status, and the corresponding PID which are connected to the running query statements.

    1
    SELECT datname, usename, state,pid FROM pg_stat_activity;
    
    1
    2
    3
    4
    5
    6
    7
    8
     datname  | usename | state  |       pid
    ----------+---------+--------+-----------------
     testdb | Ruby    | active | 140298793514752
     testdb | Ruby    | active | 140298718004992
     testdb | Ruby    | idle   | 140298650908416
     testdb | Ruby    | idle   | 140298625742592
     testdb | omm | active | 140298575406848
    (5 rows)
    

    If the state column is idle, the connection is idle and requires a user to enter a command.

    Identify only active query statements.

    1
    SELECT datname, usename, state, pid FROM pg_stat_activity WHERE state != 'idle';
    

  3. To cancel queries that have been running for a long time, use the PG_TERMINATE_BACKEND function to end sessions based on the thread ID.

    1
    SELECT PG_TERMINATE_BACKEND(140298793514752);
    

    If the following information is displayed, the session is successfully terminated:

    1
    2
    3
    4
    PG_TERMINATE_BACKEND
    ----------------------
     t
    (1 row)
    
    If the following information is displayed, a user has terminated the current session:
    1
    2
    FATAL:  terminating connection due to administrator command
    FATAL:  terminating connection due to administrator command
    
    NOTE:
    1. When an initial user uses the PG_TERMINATE_BACKEND function to terminate the backend threads of active sessions, the gsql client is reconnected automatically rather than be logged out. The message "The connection to the server was lost. Attempting reset: Succeeded." is returned. If non-initial users do this operation, the message "The connection to the server was lost. Attempting reset: Failed." is returned. This is because only initial users can log in to the system in password-free mode.
    2. If the PG_TERMINATE_BACKEND function is used to end inactive backend threads, and the thread pool is enabled, idle sessions do not have thread IDs and cannot be terminated. In non-thread pool mode, terminated sessions are not automatically reconnected.
    1
    2
    3
    FATAL:  terminating connection due to administrator command
    FATAL:  terminating connection due to administrator command
    The connection to the server was lost. Attempting reset: Succeeded.
    

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback