Yes, for databases that support them, and this protection is always on. PostgreSQL, MySQL and MariaDB, and Oracle run every read in a read-only transaction that ends with ROLLBACK, so the database itself refuses writes to its tables. Amazon Redshift and Google Cloud Spanner reads use read-only transactions too. Other engines differ:
- SQLite reads through a read-only file handle.
- SQL Server has no read-only transactions: GateRook applies strict
SELECTchecks and rolls back. Use aSELECT-only login for protection the server enforces. - BigQuery, Snowflake, Databricks, Trino and Athena get no read-only transaction. GateRook checks each statement, in some with the engine's own plan or dry run, and the account's permissions remain the boundary.
A read-only transaction doesn't contain every side effect of a function: advisory locks, signals to other sessions, server files and dblink connections act outside it. GateRook refuses known functions of that kind, and a read that calls a function GateRook doesn't recognize as built in waits for approval; on SQL Server it is refused. This check can't see functions called inside a view or without parentheses, so database privileges still matter: see what GateRook adds to a read-only database user.