On this page
Connections, Database Groups and Environments
BroadSQL organizes the databases you work with around three ideas. A Connection is one physical database you can open. A Database Group gathers the Connections of one application or system. An Environment says which deployment stage a Connection belongs to: DEV, QA, PROD and so on. Together they let you think "the WORLD application, in QA" instead of remembering a list of unrelated connection names.
| Concept | Answers | Example |
|---|---|---|
| Connection | Which physical database do I open? | WORLD-QA, WORLD, WORKCOPY |
| Database Group | Which application or system is it part of? | WORLDAPP |
| Environment | Which deployment stage is it? | QA, PROD |
The examples of this page use the WORLD sample and a practice set that does not exist by default: the Database Group WORLDAPP, with WORLD-IN and WORLD-QA, two copies of the sample, and WORLD itself playing the production database. Set up QA and production copies of WORLD creates it.
Connection
A Connection is one database endpoint and the way to reach it: a JDBC URL, a database type (which gives the JDBC driver), a user name and a password, plus a short ID that you type to open it. Connections are stored, with their credentials encrypted, in the Connections Definition File (CDF). You create them with CONFIG on Windows or ADD CONNECTION on any platform (see Getting started).
CONNECT <id> opens a Connection:
BroadSQL> CONNECT WORLD-QA;
- The new Connection is opened first. If that fails, the error is reported and the current Connection stays open, so a typo never leaves you without a session.
- On success, the previous Connection is closed: BroadSQL has one open database Connection at a time.
- A Connection whose URL opens BroadSQL's own configuration database (the CDF) is refused: see The configuration database (CDF).
- The prompt changes to the Connection ID, the Connection's login script runs, and a short summary of the database (driver, product and version, autocommit) is printed.
DISCONNECT (or BYE, CLOSE, three names for one command) closes the current Connection. You then land at the BroadSQL> prompt, with no Connection, or, with the setting RememberLastConnection=TRUE, back on the Connection you were on before; BroadSQL never returns to the CDF by itself. ENV switches count as Connection changes for that history. See Starting, connecting and logging out. DISCONNECT API is a different command: it clears only the API context. PING <id> (or CHECK <id>) tests a Connection without opening it.
Database Group
A Database Group is the application or system a Connection belongs to: WORLDAPP in these examples, or the name of one of your applications. One application usually has several physical databases, one per deployment stage, and the Database Group is what ties them together. A Connection without a Database Group is standalone; the local H2 databases created by DUMP ... AS H2 are standalone, for example.
A Database Group differs from a Connection in that you never open it: it is a label shared by several Connections. Its value is in the rule it carries: a Database Group holds at most one Connection per Environment. That rule is what makes "the QA database of WORLDAPP" a precise answer, and what ENV and / <environment> rely on.
WORLD-QA> SHOW GROUP;
List of environments for Database Group 'WORLDAPP':
|------------|---------------|--------------------|---------------------------------------------|---------------|
|ENVIRONMENT |ID |USER |NAME |TYPE |
|------------|---------------|--------------------|---------------------------------------------|---------------|
|IN |WORLD-IN | |Sample World Database, integration |H2 |
|PROD |WORLD | |Sample World Database |H2 |
|QA |WORLD-QA | |Sample World Database, QA |H2 |
|------------|---------------|--------------------|---------------------------------------------|---------------|
3 database connections foundDatabase Groups are managed in the "Database Groups" tab of CONFIG, or with ADD GROUP, EDIT GROUP and DEL GROUP. SHOW ALL GROUPS lists them all.
Environment
An Environment is a deployment stage: DEV, INT, QA, PROD, or whatever names your organization uses. Environments form one list shared by every Database Group, each with a description, a comment and a Production flag. LOCAL is built in.
WORLD-QA> SHOW ALL ENVIRONMENTS;
|---------------|---------------------------------------------|----------|
|ID |DESCRIPTION |PRODUCTION|
|---------------|---------------------------------------------|----------|
|IN |Integration |false |
|LOCAL |Local |false |
|PROD |Production |true |
|QA |Quality assurance |false |
|---------------|---------------------------------------------|----------|
4 environment(s) foundEach Connection of a Database Group is assigned one Environment, so a Database Group and an Environment together designate exactly one Connection: WORLDAPP in QA is WORLD-QA. Environments are managed in the "Environments" tab of CONFIG, or with ADD ENVIRONMENT, EDIT ENVIRONMENT and DEL ENVIRONMENT.
CONNECT versus ENV
The two commands both open a Connection, but you name a different thing:
CONNECT <id>opens a physical Connection by its ID. It works for any Connection, in any Database Group or none.ENV <environment>switches to the Connection of that Environment in the Database Group of the current Connection. It opens it exactly asCONNECTwould: same test, same login script, same prompt.
WORLD-QA> ENV PROD;
Disconnected from 'Sample World Database, QA'
Connected to 'WORLD' using JDBC driver 'H2 JDBC Driver, 2.3.232 (2024-08-11)'
Database: H2 version 2.3.232 (2024-08-11)
WORLD>ENV PROD worked because WORLD-QA is in the WORLDAPP Database Group, which has a Connection for PROD. The name after CONNECT is always a Connection and the name after ENV is always an Environment, so a Connection and an Environment with the same name never conflict. ENVT and CONNECT ENVIRONMENT are aliases of ENV.
ENV never searches other Database Groups. It fails, and leaves the current Connection open, when the current Connection is standalone, when the Environment does not exist, when the Database Group has no Connection for it, when that Connection is inactive, or when it cannot be opened:
WORLD> ENV NOPE;
ERROR: Cannot switch to Environment 'NOPE': Environment 'NOPE' does not exist.Why the model exists
- The same application in several stages. Most databases you manage exist in DEV, QA and PROD. With a Database Group you move between them by stage (
ENV QA,ENV PROD) instead of rememberingWRLD_Q2_NEWandWORLD_PRD_01. - Comparing stages. A query you just ran in QA can be run once against PROD with
/ PROD, without leaving QA;COMPARE TABLE STRUCTUREcompares a table with the same table in another Connection. - Knowing where you are.
SHOW CONNECTIONstates the Database Group and Environment of the open Connection, and a Production Environment changes the color of the prompt. - Context for Scripts. A Script can be tagged with the Database Groups and Environments it is meant for (
-- @instance:,-- @environment:); BroadSQL warns when it runs elsewhere, andLIB LISTshows the Scripts that match the current Connection (see Scripts Library).
Knowing where you are
The prompt shows the ID of the open Connection, followed by the API session when there is one:
WORLD-QA>
WORLD-QA [API CRM:TEST]>
The Database Group and the Environment are not part of the prompt. SHOW CONNECTION shows them, with the rest of the Connection's definition:
WORLD-QA> SHOW CONNECTION;
CONNECTION: WORLD-QA
NAME : Sample World Database, QA
TYPE : H2
URL : jdbc:h2:./samples/WorldDB_QA
USER : sa
DATABASE GROUP : WORLDAPP
ENVIRONMENT : QASHOW CONNECTION <id> shows another Connection without opening it, and SHOW DBINFOS shows the driver and database version of the open one.
Production Environments
When colors are on (the color and theme settings, see Interactive console), the prompt of a Connection whose Environment is flagged Production is shown in a distinct style, so you notice before you type. With colors off, the prompt looks the same in every Environment. On such a Connection, BroadSQL asks for a confirmation before a statement that can modify the database: see Production confirmation. The flag plays no part in the Script tag warnings.
Production confirmation
When the open Connection belongs to an Environment flagged Production, BroadSQL asks before it runs a statement that can modify the database. Nothing is sent to the database before you answer.
WORLD> UPDATE COUNTRY SET POPULATION = 59225800 WHERE CODE = 'FRA';
WARNING: This operation can modify a Production database.
Connection: WORLD (Environment PROD, Production)
Statement: UPDATE COUNTRY SET POPULATION = 59225800 WHERE CODE = 'FRA'
Why: it is an UPDATE
Execute? [yes/no]: yes
1 row(s) updated.On the practice set, answering yes changes WORLD; answer no to see the question without changing anything.
Only yes or y (any case) runs the statement. no, an empty answer, any other answer, end of input or CTRL+C refuse it:
Execute? [yes/no]: no
Not executed.
SQL ERROR
------------------------------------------------------------
Connection : WORLD
SQLState : BSQPR
Error code : 0
Production change refused on connection 'WORLD': the change was not confirmed. Nothing was executed.
Query:
1 | UPDATE COUNTRY SET POPULATION = 59225800 WHERE CODE = 'FRA'
------------------------------------------------------------Your answer is recorded in the activity log ("Production confirmation for WORLD: approved" or "refused"), not in the command history.
What asks and what does not
| Never asks | Always asks |
|---|---|
SELECT, WITH queries, SHOW, DESCRIBE, EXPLAIN, VALUES | INSERT, UPDATE, DELETE, MERGE and every DDL (CREATE, ALTER, DROP, TRUNCATE...) |
Session statements: ALTER SESSION, SET SCHEMA, SET search_path, SET ROLE, USE | GRANT, REVOKE, other SET statements |
COMMIT, ROLLBACK, SAVEPOINT | CALL, EXEC, BEGIN and other blocks: BroadSQL cannot tell what they change |
| BroadSQL commands that only read | SELECT ... INTO, SELECT ... FOR UPDATE, a sequence's next value, a WITH holding a data change, EXPLAIN ANALYZE |
A statement BroadSQL cannot read (an unterminated quote, an unknown form) asks too. The rule applies wherever the statement comes from: typed, in a Script, in the Editor, in a login script, in a BroadSQL command that writes (LOAD, LINK TABLE), in JavaScript, or in a / <environment> rerun that reaches a Production Connection. A Connection of any other Environment never asks.
Every change, or once per session
The setting ProductionConfirmEveryChange chooses how often BroadSQL asks (see Settings):
TRUE(the default): before every statement that can modify the database. A Script of ten such statements asks ten times. A BroadSQL command is one statement:LOADasks once for all its rows. In JavaScript, eachexecuteorexecuteUpdatecall asks.FALSE: before the first such statement of each connected session. It asks again after any new connection:CONNECT,ENV, a switch to another Connection,DISCONNECTthenCONNECT, an automatic reconnection after a lost connection, andLOGOUT. A/ <environment>rerun and a JavaScriptconnect()open their own connection, so they ask each time.
A refusal never counts as an approval. A change of this setting in CONFIG (Application Settings tab) applies at once.
Scripts, typed lines and the Editor
- A Script (
@file,LIB RUN): a refusal stops the whole run, nested Scripts included, with "Run stopped: a Production change was refused at statement 3 of Script <name> (line 7)." Statements already executed stay executed. - A typed line with several statements: the refused statement and the statements after it are not run.
- The BroadSQL Editor: the question is a dialog with Yes and No. No is the default button; Escape and closing the dialog also refuse. A refusal stops the run, as for a Script.
Without a terminal
When BroadSQL cannot ask (its input is redirected from a file, or no interactive terminal is attached), every statement that can modify a Production database is refused:
Production change refused on connection 'WORLD': confirmation is required and no interactive confirmation is
available. Nothing was executed.
No setting turns this off.
Transactions
The confirmation never commits or rolls back anything. With Autocommit=false, the changes you confirmed stay pending until COMMIT or ROLLBACK, as on any other Connection. On a database whose DDL statements commit the open transaction (Oracle, MySQL, H2 and others), the question of a DDL statement adds: "On this database, this statement also commits your pending changes."
SET PASSWORD on a Production Connection asks one question only, worded for Production: it is the confirmation.
Limits
- BroadSQL recognizes statement forms, not what the database does: a function with side effects called from a
SELECT, a trigger, a database link or the logic of a stored procedure cannot be seen. - The confirmation protects against mistakes. It is not access control: the rights of the database account remain the security boundary.
Everyday commands
| You want to | Command |
|---|---|
| Open a Connection | CONNECT <id> (aliases OPEN, CON, CONN) |
| Move to another Environment of the same application | ENV <environment> |
Close the Connection (back to BroadSQL>, or to the previous Connection) | DISCONNECT (aliases BYE, CLOSE) |
| Test a Connection without opening it | PING <id> (alias CHECK) |
| See the open Connection's definition, Database Group and Environment | SHOW CONNECTION |
| See another Connection's definition | SHOW CONNECTION <id> |
| See the database product and driver | SHOW DBINFOS |
| List every Connection, or those of one database type | SHOW ALL CONNECTIONS [type] |
| List the inactive Connections | SHOW INACTIVE CONNECTIONS |
| List the Connections of the current Database Group, by Environment | SHOW GROUP |
| List all Database Groups, or all Environments | SHOW ALL GROUPS, SHOW ALL ENVIRONMENTS |
| Run the last query again, here | / |
| Run the last query once on another Environment, staying here | / <environment> |
| Show the last query without running it | // or SHOW QUERY |
/ and / <environment> are typed on a line by themselves. / <environment> resolves the Environment in the current Database Group, as ENV does, but only for that one run: the open Connection does not change.
Examples
Check a figure in QA, then in production
A test city was added to the QA copy only (see Check a figure in QA, then in production), so the two runs differ:
WORLD-QA> SELECT COUNT(*) AS CITIES FROM CITY WHERE COUNTRYCODE = 'FRA';
|--------------------|
|CITIES |
|--------------------|
|41 |
|--------------------|
1 rows fetched in 5 ms.
WORLD-QA> / PROD
Running last query on WORLD [PROD]...
|--------------------|
|CITIES |
|--------------------|
|40 |
|--------------------|
1 rows fetched in 0 ms.
WORLD-QA>The prompt still shows WORLD-QA: only that one run went to WORLD.
Work in production for a while, then come back
WORLD-QA> ENV PROD;
WORLD> SHOW CONNECTION;
WORLD> SELECT CODE, NAME, POPULATION FROM COUNTRY WHERE CONTINENT = 'Oceania' ORDER BY POPULATION DESC;
WORLD> DUMP / TO oceania_prod AS XLSX;
WORLD> ENV QA;
WORLD-QA>
DUMP / exports the result you just looked at (see Exporting data).
Find the Connections of an application
WORLD-QA> SHOW GROUP;
WORLD-QA> SHOW GROUP WORLD-QA PROD;
The second form keeps only the PROD row. SHOW ALL CONNECTIONS H2; lists every H2 Connection, whatever its Database Group.
What stays the same when you switch
- Script variables belong to the BroadSQL session: they survive
CONNECT,ENVandDISCONNECT. - An API session opened with
CONNECT APIis independent of the database Connection: switching one never closes the other (see Running API requests). - Pending changes are not carried over: opening another Connection closes the previous one, which rolls back its uncommitted work when autocommit is off.
Related pages
- User guide: the everyday steps this page belongs to.
- Getting started: creating Connections, Database Groups and Environments, and editing the CDF.
- Exploring a database: what to do once you are connected.
- Interactive console: the prompt, colors,
/and other shortcuts. - Application settings:
color,themeand the other settings. - Command reference:
CONNECT,ENV,DISCONNECT,PING,SHOW CONNECTION,SHOW GROUP,SHOW ALL CONNECTIONS,SHOW ALL GROUPS,SHOW ALL ENVIRONMENTS,SHOW QUERY.
Found something wrong or unclear on this page? Tell us, with the page address.