PostgreSQL码农集散地

国产啊!真锻炼代码能力和忍耐极限。把文档写明白点不行吗?

参考文档点击文末阅读原文打开; 推荐《最好的PostgreSQL学习镜像》;


搞什么? 到底让不让创建无日志表? 

我想在polardb里面创建unlogged table, 但是创建出来的表还是日志表, 这是怎么回事?

复现方法

开启一个PolarDB for PostgreSQL 11实例, 然后创建unlogged table.

postgres=# create unlogged table tbl1 (id int);  
WARNING:  change unlogged table to logged table, because unlogged table does not support primary-replica mode  
CREATE TABLE  

有一条告警印入眼帘, 他他他替我做了个决定,强制把tbl1强制转换为logged table了, 查看这个表的元数据得知:

postgres=# \d+ tbl1  
                                          Table "public.tbl1"
 Column |  Type   | Collation | Nullable | Default | Storage | Compression | Stats target | Description   
--------+---------+-----------+----------+---------+---------+-------------+--------------+-------------  
 id     | integer |           |          |         | plain   |             |              |   
Access method: heap

postgres=# select relpersistence from pg_class where relname='tbl1';
 relpersistence 
----------------
 p  -- unlogged table这里应该是u
(1 row)

请问如何解决?

解决办法,幸亏有点三脚猫的功夫

1、查看报错的代码

postgres=# \set VERBOSITY verbose  

postgres=# create unlogged table tbl1 (id int);  
WARNING:  01000: change unlogged table to logged table, because unlogged table does not support primary-replica mode  
LOCATION:  DefineRelation, tablecmds.c:719  
CREATE TABLE  

报错代码如下:

src/backend/commands/tablecmds.c

/* ----------------------------------------------------------------  
 *              DefineRelation  
 *                              Creates a new relation.  
 *  
 * stmt carries parsetree information from an ordinary CREATE TABLE statement.  
 * The other arguments are used to extend the behavior for other cases:  
 * relkind: relkind to assign to the new relation  
 * ownerId: if not InvalidOid, use this as the new relation's owner.  
 * typaddress: if not null, it'
s set to the pg_type entry's address.  
 * queryString: for error reporting  
 *  
 * Note that permissions checks are done against current user regardless of  
 * ownerId.  A nonzero ownerId is used when someone is creating a relation  
 * "on behalf of" someone else, so we still want to see that the current user  
 * has permissions to do it.  
 *  
 * If successful, returns the address of the new relation.  
 * ----------------------------------------------------------------  
 */  
ObjectAddress  
DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,  
                           ObjectAddress *typaddress, const char *queryString)  
{  

...  

        /*  
         * POLAR: change unlogged table to logged table, because unlogged table not support  
         * Master-Slave mode, it does not write xlog, we must do it before create table.  
         * we do it in DefineRelation() because not only create unlogged table but also  
         * select into XXX unlogged table, but they all call DefineRelation() function.  
         */  
        if (polar_force_unlogged_to_logged_table &&  
                        stmt->relation->relpersistence == RELPERSISTENCE_UNLOGGED)  
        {  
                stmt->relation->relpersistence = RELPERSISTENCE_PERMANENT;  
                elog(NOTICE, "change unlogged table to logged table,"  
                                "because unlogged table not supports Master-Slave mode");  
        }  
        /* POLAR end */  

当polar_force_unlogged_to_logged_table参数设置为on时, 会自动把unlogged table转换为logged table.

解决办法也很简单, 设置一下polar_force_unlogged_to_logged_table=off, 然后再创建unlogged table即可

postgres=# set polar_force_unlogged_to_logged_table=off;  
SET  
postgres=# drop table tbl1;  
DROP TABLE  
postgres=# create unlogged table tbl1 (id int);  
CREATE TABLE  
postgres=# \d tbl1  
           Unlogged table "public.tbl1"
 Column |  Type   | Collation | Nullable | Default   
--------+---------+-----------+----------+---------  
 id     | integer |           |          |

postgres=# select relpersistence from pg_class where relname='tbl1';
 relpersistence 
----------------
 u
(1 row)

怪不得老唐每次都要逼逼一下:“我就不明白了,文档不能好好写吗?几百个新增参数啥意思都找不到说明,还真以为用户都是内核专家啊!”

文末彩蛋:国产数据库周边生态

当然一款数据库要流行起来, 除了自己要强大, 还离不开生态. 用好周边生态工具, 管理水平战胜90%老司机!!! 下面简单介绍一下国产数据库周边生态.

1、管控软件

鸣嵩(前阿里云数据库总经理 / 研究员)等大佬们创业创办的云猿生, 核心产品是KubeBlocks. 他们的理念是让管理数据库和搭积木一样简单, 如果你要管理很多套并且种类(OLTP\OLAP\NoSQL\KV\TS\MQ等)很多的数据库产品, 推荐首选.

  • https://github.com/apecloud/kubeblocks

PG中文社区核心委员唐成老师的公司乘数开源的Clup, 专用管理PostgreSQL和PolarDB的集群管理软件, 如果你要管理很多套数据库, 推荐选择. 并且Clup还提供了企业版、自研的连接池、分布式存储、一体机、备份平台等, 是企业用户推荐之选.

  • https://www.csudata.com/

若航老司机开源的pigsty, 集成了300多个PG插件的PG集群和PolarDB集群管理软件, 如果你要管理很多套PG或PolarDB数据库, 且对插件有特别多的需求, 推荐选择.

  • https://pigsty.cc/zh/

2、审计监控诊断优化

翟总(曾经是我背后的男人)到海信聚好看后研发的 DBdoctor, 采用ebpf技术, 在对数据库几乎没有影响的情况下实时监控数据库和服务器的各项指标, 发现和诊断问题根因非常方便.

  • https://www.dbdoctor.cn/

天舟老哥的核心产品Bytebase 是位于您和数据库之间的中间件。它是数据库 DevOps 的 GitLab/GitHub,专为开发人员、DBA 和平台工程师打造。

  • https://bytebase.cc/docs/introduction/what-is-bytebase/

PawSQL, SQL优化和诊断产品.  

D-Smart, Oracle老前辈白老大出品, 专注企业级市场, 将业界顶级DBA经验的产品化作品, 产品功能包括数据库监控、诊断、优化等.

  • https://www.modb.pro/db/567140

3、国产数据库IDE

IDE是开发者的必备工具,例如社区有pgAdmin, 国产IDE则可以看看老程序猿达刚老师的DeskUI:

  • https://www.deskui.com

4、数据同步&迁移&备份恢复

NineData, 老领导出去创业做的产品, 产品涵盖了数据同步、迁移、备份、比对、devops、chatDBA等.

  • https://www.ninedata.cloud/home

DSG, 非常老牌的数据库同步迁移企业级产品, 支持各种数据库的异构和同构迁移, 用他们的话说, 没有dsg搞不定的迁移, 比goldengate还牛.

  • https://www.dsgdata.com/

公开课

如果你对PolarDB学习感兴趣可以阅读这个公开课系列:

除了PolarDB还非常值得关注的几款PG栈国产数据库:

  • HaloDB(基于PG兼容PostgreSQL、Oracle、MySQL. http://www.halodbtech.com/ )、
  • IvorySQL(基于开源PG兼容PG、Oracle. https://www.ivorysql.org/zh-cn/ )、
  • ProtonBase(云原生分布式数仓. https://protonbase.com/ )、
  • 成都文武数据库(https://ww-it.cn)

参考文档点击阅读原文获得


感谢关注我的github (https://github.com/digoal/blog) 及视频号:

Image