Skip to content

sys.database

A system view that returns information about the databases in the system.

Column NameData TypeDescription
database_idbigintThe unique ID for the database.
nametextName of the database. (Note that the yellowbrick database row contains information about some internal tables.)
owner_idbigintUnique ID of the user who owns the database. Join to sys.user to get the name of the user.
encodingtextDatabase encoding; either LATIN9 or UTF8.
collationtextDatabase collation type; currently always C.
is_readonlybooleanWhether the database is in READONLY mode. See HOT_STANDBY and READONLY Modes.
readonly_reasontextWhy the database is in READONLY mode. The database may have been set to READONLY explicitly by a database administrator. The system may put a database in this mode if the connection between the primary and secondary appliances is lost (for example, because of a network failure), or if the target database for replication is not in HOT_STANDBY mode.
is_hot_standbybooleanWhether the database is in HOT_STANDBY mode. See HOT_STANDBY and READONLY Modes.
access_privilegestextUser access privileges defined for the database, using the following format:
role=privileges/dbowner


The abbreviations are explained under Definition of Access Privileges. Alternatively, you can use the HAS_DATABASE_PRIVILEGE function to get information about access privileges.
table_countbigintNumber of user tables and temporary tables in the database.
rows_columnstorebigintTotal number of rows in the column store for this database (backend storage).
rows_rowstorebigintTotal number of rows in the row store for this database (rows not yet flushed).
compressed_bytesbigintTotal number of compressed bytes in the database. See also sys.table_storage
uncompressed_bytesbigintTotal number of uncompressed bytes in the database. See also sys.table_storage

Examples

Return information for a database named newpremdb:

premdb=# select * from sys.database where name = 'newpremdb';
-[ RECORD 1 ]------+---------
database_id        | 16395
name               | newpremdb
owner_id           | 10
encoding           | LATIN9
collation          | C
is_readonly        | f
readonly_reason    | [NULL]
is_hot_standby     | f
access_privileges  | [NULL]
table_count        | 5
rows_columnstore   | 2203486
rows_rowstore      | 8681
compressed_bytes   | 69206016
uncompressed_bytes | 91051612

Return information about any readonly databases:

premdb=# select database_id, name, is_readonly, readonly_reason, rows_columnstore from sys.database where is_readonly='t';
 database_id |  name  | is_readonly |                                     readonly_reason                                        | rows_columnstore 
-------------+--------+-------------+--------------------------------------------------------------------------------------------+------------------
      31384 | repldb | t           | Replication topology validation failure. Target database premdb_yb95 is not in HOT_STANDBY |      25944130936
(1 row)

Return access privileges for the premdb database:

yellowbrick=# select name, access_privileges from sys.database where name='premdb';
  name  |    access_privileges     
--------+--------------------------
 premdb | =Tc/ybrick1             +
       | ybrick1=CTcpqQuO/ybrick1+
       | bobr=CTcpqQuO/ybrick1   +
       | bar=uO/ybrick1          +
       | yb007=C/ybrick1         +
       | yb008=q/ybrick1
(1 row)

In this example, ybrick1 is the database owner. The users and roles with privileges on this database are bobr, bar, yb007, and yb008.

Definition of Access Privileges

The following abbreviations are used in the access_privileges column:

AbbreviationAccess PrivilegeRelevant Object Types
a (append)INSERTTables, views,
r (read)SELECTTables, views, sequences,
w (write)UPDATETables, views, sequences,
dDELETETables
DTRUNCATETables
xREFERENCESTables (create a foreign-key constraint), views
XEXECUTEStored procedures
UUSAGESchemas, sequences
CCREATESchemas; databases; roles on system
TCREATE TEMPORARYDatabases
cCONNECTDatabases
eENCRYPTKeys
EDECRYPTKeys
hHMACKeys (privilege to run the HMAC_KS function with a key as input to the function)
bCREATE DATABASESystem
pEXPLAIN QUERYDatabases
qVIEW QUERY TEXTDatabases
QTRACE QUERYDatabases
AALTER ANY ROLESystem
BDROP ANY ROLESystem
uBACKUPDatabases
ORESTORE, RESTORE ANY DATABASERESTORE on databases, RESTORE ANY DATABASE on system

Parent topic:System Views