debugsqlMinor
PostgreSQL - Cannot UPDATE pg_database
Viewed 0 times
postgresqlcannotupdatepg_database
Problem
I am not able to UPDATE table pg_database with user postgres. As you can see below, i am able to run the SQL query, however nothing changes.
postgres=# select datname, datdba, datistemplate, datallowconn from pg_database;
datname | datdba | datistemplate | datallowconn
----------------+--------+---------------+--------------
postgres | 10 | f | t
template1 | 10 | t | t
template0 | 10 | t | f
my_template_1 | 10 | f | t
(4 rows)
postgres=# UPDATE pg_database set datistemplate=true, datallowconn=false where datname='my_template_1' ;
UPDATE 1
postgres=# select datname, datdba, datistemplate, datallowconn from pg_database;
datname | datdba | datistemplate | datallowconn
----------------+--------+---------------+--------------
postgres | 10 | f | t
template1 | 10 | t | t
template0 | 10 | t | f
my_template_1 | 10 | f | t
(4 rows)
postgres=#Solution
You can't update
Use
pg_database to change a database (you shouldn't be updating system tables at all, although you can do it for some of them). Use
ALTER DATABASE instead:alter database my_template_1
with is_template true
allow_connections false;Code Snippets
alter database my_template_1
with is_template true
allow_connections false;Context
StackExchange Database Administrators Q#202685, answer score: 6
Revisions (0)
No revisions yet.