Search code examples
surrealdb

Command for seeing list of all existing namespaces and databases


I have recently come across SurrealDB, and installed it.

After adding to path, I started the server using surreal start.


 .d8888b.                                             888 8888888b.  888888b. 
d88P  Y88b                                            888 888  'Y88b 888  '88b
Y88b.                                                 888 888    888 888  .88P
 'Y888b.   888  888 888d888 888d888  .d88b.   8888b.  888 888    888 8888888K.
    'Y88b. 888  888 888P'   888P'   d8P  Y8b     '88b 888 888    888 888  'Y88b
      '888 888  888 888     888     88888888 .d888888 888 888    888 888    888
Y88b  d88P Y88b 888 888     888     Y8b.     888  888 888 888  .d88P 888   d88P
 'Y8888P'   'Y88888 888     888      'Y8888  'Y888888 888 8888888P'  8888888P'


[2022-09-27 14:14:30] INFO  surrealdb::iam Root authentication is disabled
[2022-09-27 14:14:30] INFO  surrealdb::dbs Database strict mode is disabled
[2022-09-27 14:14:30] INFO  surrealdb::kvs Starting kvs store in memory
[2022-09-27 14:14:30] INFO  surrealdb::kvs Started kvs store in memory
[2022-09-27 14:14:30] INFO  surrealdb::net Starting web server on 0.0.0.0:8000
[2022-09-27 14:14:30] INFO  surrealdb::net Started web server on 0.0.0.0:8000

Then I entered the database in another terminal using surreal sql --conn http://0.0.0.0:8000.

How do I list all namespaces and databases?

Also, when I use a command like SELECT * FROM buybig, I get:

> SELECT * FROM buybig;
There was an error with the remote request: error sending request for url (http://0.0.0.0:8000/sql): error trying to connect: tcp connect error: The requested address is not valid in its context. (os error 10049)   
>

Solution

  • Namespaces can be listed with the INFO query.

    INFO FOR KV;
    

    which returns

    [
        {
            "time": "19.6µs",
            "status": "OK",
            "result": {
                "ns": {
                    "namespace1": "DEFINE NAMESPACE namespace1",
                    "namespace2": "DEFINE NAMESPACE namespace2"
                }
            }
        }
    ]
    

    You can retrieve the databases inside a namespace by selecting the namespace with USE NS and running INFO FOR NS.

    USE NS namespace1;
    INFO FOR NS;
    

    This will return

    [
        {
            "time": "21.9µs",
            "status": "OK",
            "result": {
                "db": {
                    "database1": "DEFINE DATABASE database1",
                    "database2": "DEFINE DATABASE database2"
                },
                "nl": {},
                "nt": {}
            }
        }
    ]