PostgreSQL码农集散地

PolarDB 100 问 | PolarDB 不支持表空间?

#PolarDB 100问

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


PolarDB 100 问 | PolarDB创建表空间正常, 但使用报错, 如何解决?

PolarDB创建表空间正常, 但是使用时报错, 如何解决?

复现方法

使用这个项目构建镜像并创建容器:

  • https://github.com/ApsaraDB/polardb-pg-docker-images/
  • 使用方法详见:《如何构建PolarDB Docker镜像 OR 本地编译PolarDB?》

在共享数据目录中创建表空间目录

cd /var/polardb/shared_datadir  
mkdir abc  

创建表空间正常

psql -c "create tablespace tbs location '/var/polardb/shared_datadir/abc';"

使用该表空间建表时报错

postgres=# \set VERBOSITY verbose  
postgres=# create table t (id int) tablespace tbs;  
ERROR:  58P01: could not create directory "file-dio:///var/polardb/shared_datadir/pg_tblspc/24578/PG_15_202209061/5": No such file or directory  
LOCATION:  TablespaceCreateDbspace, tablespace.c:164  

解决思路

搜索到一个跟file-dio相关的配置, 但是对解决表空间报错貌似没有帮助:

postgres=# \x  
Expanded display is on.  
postgres=# select * from pg_settings where setting ~ 'file-dio';  
-[ RECORD 1 ]---+----------------------------------------------------  
name            | polar_datadir  
setting         | file-dio:///var/polardb/shared_datadir  
unit            |  
category        | PolarDB Storage  
short_desc      | Sets the server's data directory in shared storage.  
extra_desc      |  
context         | postmaster  
vartype         | string  
source          | configuration file  
min_val         |  
max_val         |  
enumvals        |  
boot_val        |  
reset_val       | file-dio:///var/polardb/shared_datadir  
sourcefile      | /var/polardb/primary_datadir/postgresql.conf  
sourceline      | 838  
pending_restart | f  

每个database在表空间中都有一个相应的目录, 这个路径中的24578/PG_15_202209061/5对应的是pg_tablespace.oid/PG_majver_catalognumber/current_database_oid, 可以通过以下方式获取:

postgres=# select oid from pg_tablespace where spcname ='tbs';  
 oid    
-------  
24578  
(1 row)  

postgres=# select version();  
                                version                                    
--------------------------------------------------------------------------  
PostgreSQL 15.10 (PolarDB 15.10.2.0 build 35199b32) on aarch64-linux-gnu  
(1 row)  

postgres=# select * from pg_control_system();  
-[ RECORD 1 ]------------+-----------------------  
pg_control_version       | 1300  
catalog_version_no       | 202209061  
system_identifier        | 7444841746190987311  
pg_control_last_modified | 2024-12-06 09:47:15+08  

postgres=# select oid from pg_database where datname =current_database();  
-[ RECORD 1 ]  
oid | 5  

已有表空间中倒是自动创建了PG_majver_catalognumber目录

ll -R /var/polardb/shared_datadir/abc/  
/var/polardb/shared_datadir/abc/:  
total 0  
drwx------  3 postgres postgres  96 Dec  6 09:46 ./  
drwxr-xr-x 14 postgres postgres 448 Dec  6 09:45 ../  
drwx------  2 postgres postgres  64 Dec  6 09:46 PG_15_202209061/  

/var/polardb/shared_datadir/abc/PG_15_202209061:  
total 0  
drwx------ 2 postgres postgres 64 Dec  6 09:46 ./  
drwx------ 3 postgres postgres 96 Dec  6 09:46 ../  

按常规PG的方式, 表空间目录要软链到$PGDATA/pg_tblspc下, 尝试如下:

ln -s /var/polardb/shared_datadir/abc /var/polardb/shared_datadir/pg_tblspc/24578  

现在在tbs里建表就可以了, (current_database.oid目录自动被创建了, 不需要人为创建)

postgres=# create table t (id int) tablespace tbs;   
CREATE TABLE  
postgres=# \db  
                  List of tablespaces  
   Name    |  Owner   |            Location              
------------+----------+---------------------------------  
pg_default | postgres |  
pg_global  | postgres |  
tbs        | postgres | /var/polardb/shared_datadir/abc  
(3 rows)  

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

在其他数据库中也可以使用该表空间创建表

postgres=# create database db1;  
CREATE DATABASE  
postgres=# \c db1  
You are now connected to database "db1" as user "postgres".  
db1=# create table t (id int) tablespace tbs;  
CREATE TABLE  

接下来的问题是, 如果采用了polardb pfs的话? 应该如何操作? 更多可参考pfs使用帮助以及PolarDB源代码.

postgres=# select * from pg_settings where name ~ 'disk';  
-[ RECORD 1 ]---+---------------------------------------------  
name            | polar_disk_name  
setting         | home  
unit            |  
category        | PolarDB Storage  
short_desc      | The disk name provided for polarFS.  
extra_desc      |  
context         | postmaster  
vartype         | string  
source          | configuration file  
min_val         |  
max_val         |  
enumvals        |  
boot_val        |  
reset_val       | home  
sourcefile      | /var/polardb/primary_datadir/postgresql.conf  
sourceline      | 830  
pending_restart | f  

为什么要问PFS如何解决新增表空间问题? 因为马上我有另一个问题: 如何给一个PolarDB实例挂载多个共享盘? 因为一块盘的容量、IOPS、吞吐指标都有上限, 希望通过多块盘来突破上限.

  • 《PolarDB 100 问 | 如何给一个PolarDB实例挂载多个共享盘?》

期待更多解答.

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

当然一款数据库要流行起来, 除了自己要强大, 还离不开生态. 用好周边生态工具, 管理水平战胜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