DEV Community

Michael
Michael

Posted on

Getting Cluster Lock and Failover Information via SQL in GBase 8a

In current builds of GBase 8a, the China-domestically developed MPP analytical database from GBASE, cluster lock and failover information is normally available only through the gcadmin command line. Because the engine supports Python UDFs, you can wrap those commands and fetch the same data with plain SQL — especially useful when shell access is inconvenient.

A Python UDF for Cluster Locks (showlock)

drop function if exists showlock;
create function showlock()
returns varchar
$$
try:
    import commands
    output = commands.getoutput("gcadmin showlock")
except:
    return None
return str(output)

$$ language plpythonu;
Enter fullscreen mode Exit fullscreen mode

Result:

gbase> select showlock();
+-------------------+
| showlock()        |
+-------------------+
|  +=================================================================+
 |                          GCLUSTER LOCK                          |
 +=================================================================+
 +-------------+----------+-------------+--------------+------+----+
 |  Lock name  |  owner   |   content   | create time  |locked|type|
 +-------------+----------+-------------+--------------+------+----+
 |gc-event-lock|10.0.2.201|global master|20250113120320| TRUE | E  |
 +-------------+----------+-------------+--------------+------+----+
 Total : 1 |
+--------------------+
1 row in set (Elapsed: 00:00:00.63)
Enter fullscreen mode Exit fullscreen mode

A Python UDF for Failover Information (showfailover)

drop function if exists showfailover;
create function showfailover()
returns varchar
$$
try:
    import commands
    output = commands.getoutput("gcadmin showfailover")
except:
    return None
return str(output)

$$ language plpythonu;
Enter fullscreen mode Exit fullscreen mode

Result:

gbase> drop function if exists showfailover;
Query OK, 0 rows affected, 1 warning (Elapsed: 00:00:00.00)

gbase> create function showfailover()
    -> returns varchar
    -> $$
    -> try:
    ->     import commands
    ->     output = commands.getoutput("gcadmin showfailover")
    -> except:
    ->     return None
    -> return str(output)
    ->
    -> $$ language plpythonu;
Query OK, 0 rows affected (Elapsed: 00:00:00.00)

gbase> select showfailover();
+--------------------------------------------------------------+
| showfailover()                                               |
+--------------------------------------------------------------+
|
gcadmin showfailover: no gcluster failover information now
 |
+--------------------------------------------------------------+
1 row in set (Elapsed: 00:00:00.63)

gbase>
Enter fullscreen mode Exit fullscreen mode

Both UDFs share the same structure: plpythonu calls the matching gcadmin subcommand through commands.getoutput, converts the output to a string, and returns None if anything raises.

Going forward, the output can also be switched to XML with the f parameter for easier programmatic parsing — see gcadmin --help for details. Bringing these operational checks into the SQL interface means you no longer need a shell account for everyone who needs them, and privilege control plus auditing stay in one place: the gbase database itself.

Top comments (0)