database “template0“ is not currently accepting connections

港控/mmm° 2022-12-05 04:57 293阅读 0赞

template0 数据库默认是不允许登录的,做 vacuumdb 减少 age 时报错。

  1. postgres=# select datfrozenxid,datname,age(datfrozenxid),txid_current() from pg_database;
  2. datfrozenxid | datname | age | txid_current
  3. --------------+--------------------+--------+--------------
  4. 289572 | postgres | 22 | 289594
  5. 289572 | peiybdb | 22 | 289594
  6. 289571 | template1 | 23 | 289594
  7. 561 | template0 | 289033 | 289594
  8. 289574 | pgbenchdb | 20 | 289594
  9. 289570 | yewudb | 24 | 289594
  10. 289593 | pgbench_plprofiler | 1 | 289594
  11. (7 rows)
  12. $ /usr/pgsql-11/bin/vacuumdb --freeze template0
  13. vacuumdb: could not connect to database template0: FATAL: database "template0" is not currently accepting connections

需要 superuser 执行下更新命令。

  1. postgres=# update pg_database set datallowconn = TRUE where datname = 'template0';
  2. $ /usr/pgsql-11/bin/vacuumdb --freeze template0
  3. vacuumdb: vacuuming database "template0"
  4. postgres=# select datfrozenxid,datname,age(datfrozenxid),txid_current() from pg_database;
  5. datfrozenxid | datname | age | txid_current
  6. --------------+--------------------+-----+--------------
  7. 289572 | postgres | 24 | 289596
  8. 289572 | peiybdb | 24 | 289596
  9. 289571 | template1 | 25 | 289596
  10. 289574 | pgbenchdb | 22 | 289596
  11. 289570 | yewudb | 26 | 289596
  12. 289593 | pgbench_plprofiler | 3 | 289596
  13. 289596 | template0 | 0 | 289596
  14. (7 rows)

使用 superuser 还原一下。

  1. postgres=# update pg_database set datallowconn = FALSE where datname = 'template0';

发表评论

表情:
评论列表 (有 0 条评论,293人围观)

还没有评论,来说两句吧...

相关阅读