作者:Digital Observer(施嘉伟)
Oracle ACE Pro: Database
PostgreSQL ACE Partner
11年数据库行业经验,现主要从事数据库服务工作
拥有Oracle OCM、DB2 10.1 Fundamentals、MySQL 8.0 OCP、WebLogic 12c OCA、KCP、PCTP、PCSD、OCI、PolarDB技术专家、达梦师资认证、数据安全咨询高级等认证
ITPUB认证专家、PolarDB开源社区技术顾问、HaloDB技术顾问、TiDB社区技术布道师、青学会MOP技术社区专家顾问、国内某高校企业实践指导教师
公众号:Digital Observer;CSDN:施嘉伟;ITPUB:sjw1933;PGFans:施嘉伟
云原生数据库 PolarDB for PostgreSQL 已于 2021 年 5 月 29 日开源。有幸拿到测试资格,接下来我们一起来感受下在云起实验室,如何快速体验 PolarDB for PostgreSQL!
PolarDB for PostgreSQL
PolarDB for PostgreSQL采用了基于Shared-Storage的存储计算分离架构。数据库由传统的Share-Nothing架构,转变成了Shared-Storage架构——由原来的N份计算+N份存储,转变成了N份计算+1份存储;而PostgreSQL使用了传统的单体数据库架构,存储和计算耦合在一起。

为保证所有计算节点能够以相同的可见性视角访问分布式块存储设备,PolarDB需要使用分布式文件系统PolarDB File System(PFS)来访问块设备;如果所有计算节点都可以本地访问同一个块存储设备,那么也可以不使用PFS,直接使用本地的单机文件系统(如 ext4)。这是与PostgreSQL的不同点之一。
实验环境已内置Docker环境以及PolarDB for PostgreSQL开源版的镜像资源,直接拉取镜像并运行,即可启动PolarDB实例。
1.执行如下命令,拉取PolarDB-PG实例镜像。
docker pull polardb/polardb_pg_local_instance2.执行如下命令,创建容器。
[root@iZuf6i67aqdz2525tkxsp4Z ~]# docker run -it --rm polardb/polardb_pg_local_instance psql
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale "C".
The default database encoding has accordingly been set to "SQL_ASCII".
The default text search configuration will be set to "english".
Data page checksums are enabled.
Data encryption is disabled.
fixing permissions on existing directory /var/polardb/primary_datadir ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default timezone ... Asia/Shanghai
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... 2024-07-25 23:16:02.713 CST [29] [29] LOG: The total log index memory table size is 402525536
2024-07-25 23:16:02.713 CST [29] [29] LOG: The total log index memory table size is 133987136
2024-07-25 23:16:02.716 CST [29] [29] LOG: server cannot reuse buffer pool due to polar_shmem_reused is false, start to reset buffer pool
......2024-07-25 23:16:04.920 CST [31] [31] LOG: attempting to remove WAL segments older than log file 000000000000000000000000
2024-07-25 23:16:04.920 CST [31] [31] STATEMENT: CREATE DATABASE polardb_admin;
2024-07-25 23:16:04.921 CST [31] [31] LOG: Truncate relation size cache from 107CF18
2024-07-25 23:16:04.921 CST [31] [31] LOG: Truncate logindex pg_logindex from lsn=107CF18
2024-07-25 23:16:04.921 CST [31] [31] LOG: Truncate logindex polar_fullpage from lsn=107CF18
2024-07-25 23:16:04.921 CST [31] [31] LOG: attempting to remove WAL segments older than log file 000000000000000000000000
ok
syncing data to disk ... ok
WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
pg_ctl -D /var/polardb/primary_datadir -l logfile start
use localfs mode
list base dir file 1
13163
13164
13165
delete /var/polardb/primary_datadir/base/1/112
delete /var/polardb/primary_datadir/base/13163/112
delete /var/polardb/primary_datadir/base/13164/112
delete /var/polardb/primary_datadir/base/13165/112
delete /var/polardb/primary_datadir/global/1136
delete /var/polardb/primary_datadir/pg_wal
delete /var/polardb/primary_datadir/pg_logindex
delete /var/polardb/primary_datadir/pg_twophase
delete /var/polardb/primary_datadir/pg_xact
delete /var/polardb/primary_datadir/pg_commit_ts
delete /var/polardb/primary_datadir/pg_multixact
delete /var/polardb/primary_datadir/pg_csnlog
delete /var/polardb/primary_datadir/polar_dma
init polarDB data dir success
waiting for server to start....2024-07-25 23:16:05.645 CST [81] [81] LOG: /var/polardb/primary_datadir/polar_node_static.conf does not exist, we create it, This is best done on the first boot and not on restart
2024-07-25 23:16:05.652 CST [81] [81] WARNING: polardb skip readControlfile
2024-07-25 23:16:05.652 CST [81] [81] LOG: recovery.conf not exist, polardb in readwrite mode
......2024-07-25 23:16:06.095 CST [81] [81] LOG: pss shmem share memory total size is 1048576
2024-07-25 23:16:06.095 CST [81] [81] LOG: pss global share memory total size is 1736
2024-07-25 23:16:06.095 CST [81] [81] LOG: pss dispatcher share memory total size is 131568
2024-07-25 23:16:06.095 CST [81] [81] LOG: pss session_contexts share memory total size is 8000
2024-07-25 23:16:06.099 CST [81] [81] LOG: forked new process, pid is 82, true pid is 2370
2024-07-25 23:16:06.099 CST [81] [81] LOG: redirecting log output to logging collector process
2024-07-25 23:16:06.099 CST [81] [81] HINT: Future log output will appear in directory "pg_log".
. done
server started
slot_name | lsn
-----------+-----
replica1 |
(1 row)
slot_name | lsn
-----------+-----
replica2 |
(1 row)
waiting for server to shut down.... done
server stopped
waiting for server to start....2024-07-25 23:16:08.075 CST [116] [116] WARNING: polardb skip readControlfile
2024-07-25 23:16:08.075 CST [116] [116] LOG: recovery.conf not exist, polardb in readwrite mode
2024-07-25 23:16:08.078 CST [116] [116] LOG: polar_vfs loaded in postmaster 116
......2024-07-25 23:16:08.492 CST [116] [116] LOG: pss shmem share memory total size is 1048576
2024-07-25 23:16:08.492 CST [116] [116] LOG: pss global share memory total size is 1736
2024-07-25 23:16:08.492 CST [116] [116] LOG: pss dispatcher share memory total size is 131568
2024-07-25 23:16:08.492 CST [116] [116] LOG: pss session_contexts share memory total size is 8000
2024-07-25 23:16:08.496 CST [116] [116] LOG: forked new process, pid is 117, true pid is 2405
2024-07-25 23:16:08.496 CST [116] [116] LOG: redirecting log output to logging collector process
2024-07-25 23:16:08.496 CST [116] [116] HINT: Future log output will appear in directory "pg_log".
. done
server started
waiting for server to start....2024-07-25 23:16:10.094 CST [147] [147] LOG: /var/polardb/replica_datadir1/polar_node_static.conf does not exist, we create it, This is best done on the first boot and not on restart
2024-07-25 23:16:10.096 CST [147] [147] WARNING: polardb skip readControlfile
2024-07-25 23:16:10.096 CST [147] [147] LOG: polar_replica = 'on'
2024-07-25 23:16:10.096 CST [147] [147] LOG: read polar_replica = on, polardb in replica mode, use ro mode mount pfs
2024-07-25 23:16:10.098 CST [147] [147] LOG: polar_vfs loaded in postmaster 147
2024-07-25 23:16:10.099 CST [147] [147] WARNING: could not access file "polar_resource_group": No such file or directory
......2024-07-25 23:16:10.527 CST [147] [147] LOG: forked new process, pid is 148, true pid is 2436
2024-07-25 23:16:10.527 CST [147] [147] LOG: redirecting log output to logging collector process
2024-07-25 23:16:10.527 CST [147] [147] HINT: Future log output will appear in directory "pg_log".
. done
server started
waiting for server to start....2024-07-25 23:16:11.213 CST [163] [163] LOG: /var/polardb/replica_datadir2/polar_node_static.conf does not exist, we create it, This is best done on the first boot and not on restart
2024-07-25 23:16:11.215 CST [163] [163] WARNING: polardb skip readControlfile
2024-07-25 23:16:11.215 CST [163] [163] LOG: polar_replica = 'on'
2024-07-25 23:16:11.215 CST [163] [163] LOG: read polar_replica = on, polardb in replica mode, use ro mode mount pfs
2024-07-25 23:16:11.217 CST [163] [163] LOG: polar_vfs loaded in postmaster 163
2024-07-25 23:16:11.218 CST [163] [163] WARNING: could not access file "polar_resource_group": No such file or directory
......
2024-07-25 23:16:11.601 CST [163] [163] LOG: rename polar_fullpage to local cache trash polar_cache_trash/polar_fullpage_0001, errno=39
2024-07-25 23:16:11.630 CST [163] [163] LOG: The total log index memory table size is 66993872
2024-07-25 23:16:11.643 CST [163] [163] LOG: vfs open dir pg_notify, num open dir 1
2024-07-25 23:16:11.643 CST [163] [163] LOG: removing file "pg_notify/0000"
2024-07-25 23:16:11.643 CST [163] [163] LOG: vfs_unlink pg_notify/0000
2024-07-25 23:16:11.647 CST [163] [163] LOG: forked new process, pid is 164, true pid is 2452
2024-07-25 23:16:11.647 CST [163] [163] LOG: redirecting log output to logging collector process
2024-07-25 23:16:11.647 CST [163] [163] HINT: Future log output will appear in directory "pg_log".
. done
server started
psql (11.9)
Type "help" for help.
3.尝试创建一个数据库:
postgres-# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
---------------+----------+-----------+---------+-------+-----------------------
polardb_admin | postgres | SQL_ASCII | C | C | =T/postgres +
| | | | | postgres=CTc/postgres
postgres | postgres | SQL_ASCII | C | C |
template0 | postgres | SQL_ASCII | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | SQL_ASCII | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
(4 rows)
postgres=# create database test;
CREATE DATABASE
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
---------------+----------+-----------+---------+-------+-----------------------
polardb_admin | postgres | SQL_ASCII | C | C | =T/postgres +
| | | | | postgres=CTc/postgres
postgres | postgres | SQL_ASCII | C | C |
template0 | postgres | SQL_ASCII | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | SQL_ASCII | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
test | postgres | SQL_ASCII | C | C |
(5 rows)
postgres=# PolarDB for PostgreSQL 开源数据库对研发人员非常友好,使用简单,大大降低了运维成本,同时具备云原生架构和高性能的优点。对于学习 PostgreSQL 的开发者来说,这是一个绝佳的实践和提升机会。

往期推荐:

在看点这里

点击"阅读原文"
原文作者:Digital Observer;如有侵权,请联系管理员删除。