How to make a postgres database readonly - DBACLASS DBACLASS
default_transaction_read_only controls whether the database is in read only or not . Use the steps mentioned in the article to
postgresql configurationintermediate
by PostgreSQL
14 views
default_transaction_read_only controls whether the database is in read only or not . Use the steps mentioned in the article to
12345678910111213141516171819202122232425262728
[enterprisedb@localhost ~]$ psql -d postgres
psql (12.4.5)
Type "help" for help.
postgres=# \conninfo
You are connected to database "postgres" as user "enterprisedb" via socket in "/tmp" at port "5444".
postgres=# alter database edbstore set <span style="color: #ff0000;"><strong>default_transaction_read_only=on</strong></span>;
ALTER DATABASE
[root@localhost ~]# systemctl stop edb-as-12
[root@localhost ~]# systemctl start edb-as-12
edbstore=# \conninfo
You are connected to database "edbstore" as user "enterprisedb" via socket in "/tmp" at port "5444".
edbstore=# create table test as select * from pg_settings;
ERROR: cannot execute CREATE TABLE AS in a read-only transaction
postgres=# \conninfo
You are connected to database "postgres" as user "enterprisedb" via socket in "/tmp" at port "5444".
postgres=# alter database edbstore set <strong><span style="color: #ff0000;">default_transaction_read_only=off</span></strong>;
ALTER DATABASE
[root@localhost ~]# systemctl stop edb-as-12
[root@localhost ~]# systemctl start edb-as-12123456789101112
postgres=# show <span style="color: #ff0000;"><strong>default_transaction_read_only</strong></span>;
default_transaction_read_only
-------------------------------
off
(1 row)
postgres=# alter system set <span style="color: #ff0000;"><strong>default_transaction_read_only=on</strong></span>;
ALTER SYSTEM
-- Restart the pg cluster:
[root@localhost ~]# systemctl stop edb-as-12
[root@localhost ~]# systemctl start edb-as-12Please to add comments
No comments yet. Be the first to comment!