在只读模式下,PostgreSQL不允许如下SQL:
When a transaction is read-only, the following SQL commands are disallowed: INSERT,UPDATE, DELETE, and COPY FROM if the table they would write to is not a temporary table; allCREATE, ALTER, and DROP commands; COMMENT, GRANT, REVOKE, TRUNCATE; and EXPLAIN ANALYZE and EXECUTE if the command they would execute is among those listed. This is a high-level notion of read-only that does not prevent all writes to disk.
mydb=# begin;
BEGIN
mydb=# set transaction read only;
SET
--插入数据失败
mydb=# insert into t values(generate_series(1,10000),'rudy');
ERROR: cannot execute INSERT in a read-only transaction