Typically, the most likely causes of this kind of error are:
An attempt to create statements in a read-only replica (the entire instance is read-only).
<username> has default_transaction_read_only set to ON
database default_transaction_read_only set to ON
The specified script has in its first lines:
CREATE DATABASE exercises; \c exercises CREATE SCHEMA cd;
, and you report that the error occurs with CREATE SCHEMA on line 6, and not earlier.
This means that CREATE DATABASE works when <username> is executed. And this will not work if any of the above reasons were directly applicable.
One possibility that would technically explain this would be that default_transaction_read_only would be ON in the postgresql.conf file and set to OFF for the postgres database, the one that calls psql, through the ALTER DATABASE statement, which replaces the configuration file .
This is why CREATE DATABASE works, but then as soon as it connects to another database with \c , the session default_transaction_read_only parameter will turn to ON .
But, of course, it would be a rather strange and unusual configuration.
Daniel VΓ©ritΓ©
source share