How to run PostgreSQL 11 in Linux on ARM

我们选择的系统是一个运行在AArch64芯片架构上的CentOS 7.5。

[root@ecs-arm-0005 ~]# uname -a
Linux ecs-arm-0005 4.14.0-49.el7a.aarch64 #1 SMP Tue Apr 10 17:22:26 UTC 2018 aarch64 aarch64 aarch64 GNU/Linux

[root@ecs-arm-0005 ~]# cat /etc/centos-release
CentOS Linux release 7.5.1804 (AltArch)

这台服务器拥有8颗ARMv8(Huawei Kunpeng 916 2.4GHz)的芯片,和29GB的内存,并不是很大的机器。

[root@ecs-arm-0005 ~]# cat /proc/cpuinfo | grep processor|wc -l
8

[root@ecs-arm-0005 ~]# cat /proc/meminfo | grep MemTotal
MemTotal:       29756224 kB

这台服务器有两块磁盘,一块是系统盘vda,一块是超高IO的数据盘vdb。vdb还没有创建文件系统,自然也没有挂载点。

[root@ecs-arm-0005 ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
vdb    253:16   0  100G  0 disk
vda    253:0    0   40G  0 disk
├─vda2 253:2    0 39.8G  0 part /
└─vda1 253:1    0  244M  0 part /boot/efi

将vdb格式化为ext4格式的文件系统,挂载到/data目录中。作为后续Pg数据库的数据文件存储位置。

[root@ecs-arm-0005 ~]# mkfs -t ext4 /dev/vdb
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
6553600 inodes, 26214400 blocks
1310720 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2174746624
800 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
    4096000, 7962624, 11239424, 20480000, 23887872

Allocating group tables: done
Writing inode tables: done

[root@ecs-arm-0005 ~]# mkdir /data
[root@ecs-arm-0005 ~]# mount /dev/vdb /data
[root@ecs-arm-0005 ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs         15G     0   15G   0% /dev
tmpfs            15G     0   15G   0% /dev/shm
tmpfs            15G   22M   15G   1% /run
tmpfs            15G     0   15G   0% /sys/fs/cgroup
/dev/vda2        40G  1.6G   36G   5% /
/dev/vda1       244M  8.6M  236M   4% /boot/efi
tmpfs           2.9G     0  2.9G   0% /run/user/0
/dev/vdb         99G   61M   94G   1% /data

如果要保证在操作系统重新启动的时候,vdb还会自动挂载到/data目录下,还需要修改/etc/fstab文件,此处不赘述。

因为Pg for ARM的版本并没有发布实现编译好的二进制安装包(实际上也有,但是是比较古老的9.2版本),因此首先我们下载PostgreSQL数据库最新版本11.3的源码。通过编译源码手动安装。

如果在下述过程中发现报错:configure: error: no acceptable C compiler found in $PATH,则表示没有安装gcc编译器,需要通过yum install gcc gcc-c++命令来事先安装。
如果在下述过程中发现报错:configure: error: readline library not found,则表示没有安装readline-devel包,需要通过yum install readline-devel命令来事先安装。
如果在下述过程中发现报错:configure: error: zlib library not found,则表示没有安装zlib-devel包,需要通过yum install zlib-devel命令来事先安装。

总结一下就是需要事先安装以下依赖包。

yum install gcc gcc-c++ readline-devel zlib-devel

从configure到make install都是标准的Linux下编译源码安装的步骤。如果一切正常,在第一步时不会显示任何error,在第二步最后会显示:All of PostgreSQL successfully made. Ready to install.字样。

$ ./configure
$ make
$ su
# make install

成功安装完毕以后,因为我们使用的是默认配置,因此PostgreSQL软件被安装到/usr/local/pgsql目录中。

[root@ecs-arm-0005 postgresql-11.3]# ls -l /usr/local/pgsql
total 16
drwxr-xr-x 2 root root 4096 Jun  4 16:01 bin
drwxr-xr-x 6 root root 4096 Jun  4 16:01 include
drwxr-xr-x 4 root root 4096 Jun  4 16:01 lib
drwxr-xr-x 6 root root 4096 Jun  4 16:01 share

接下来创建postgres用户,而不要使用root用户管理数据库。

# adduser postgres
# passwd postgres

之前我们在/data目录下挂载了100GB的高速IO数据盘,所以下面我们将PostgreSQL数据库的数据文件存储位置指定到/data目录下,并初始化数据库。

# mkdir /data/pgsql/data
# chown postgres /data/pgsql/data
# su - postgres
$ /usr/local/pgsql/bin/initdb -D /data/pgsql/data

初始化数据库的正常显示如下。

[postgres@ecs-arm-0005 ~]$ /usr/local/pgsql/bin/initdb -D /data/pgsql/data
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 "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /data/pgsql/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... 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:

    /usr/local/pgsql/bin/pg_ctl -D /data/pgsql/data -l logfile start

数据库初始化结束以后显示的最后一条命令,告知了如果要启动数据库应该使用的命令。

[postgres@ecs-arm-0005 ~]$ /usr/local/pgsql/bin/pg_ctl -D /data/pgsql/data -l logfile start
waiting for server to start.... done
server started

至此,PostgreSQL 11.3在CentOS 7.5 on ARM上的安装和运行宣告完成。

[postgres@ecs-arm-0005 ~]$ psql
psql (11.3)
Type "help" for help.

postgres=# \db
       List of tablespaces
    Name    |  Owner   | Location
------------+----------+----------
 pg_default | postgres |
 pg_global  | postgres |
(2 rows)

How to modify timezone settings in Docker Container

我们之前从Oracle官方docker仓库中生成的Oracle 19.3镜像,默认的时区并非是中国时区,这会让在查看alertlog等日志文件时比较困惑。

那么如何修改容器中的时区呢?

确认容器中已经包含了tzdata包

$ docker exec -it oracle19c_new rpm -qa|grep tz
tzdata-2019a-1.el7.noarch

通过-e参数设置容器运行的时区参数

$ docker run --name oracle19c_new \
-p 11521:1521 -p 15500:5500 \
-v /Users/Kamus/oracle/oradata/oracle19c:/opt/oracle/oradata \
-e TZ=Asia/Chongqing \
-e ORACLE_SID=ORCLNEW \
oracle/database:19.3.0-ee

检查新生成的容器的时区

$ docker exec -it oracle19c_new date +"%Z %z"
CST +0800

CST+0800表示东8时区,正是设置的中国时区。

如何在MarsEdit中使用Markdown编写文章

一直在寻找一个适合编写完毕以后直接发布到Wordpress中,同时又能完美支持Markdown语法的工具,尝试过Ulysess还有Typora,Ulysess本身对于Markdown的支持很奇怪,当粘贴的代码中有一些Markdown语法的关键字时,会出现很难编辑的情况;而Typora本身确实是很好的Markdown编辑器,但是无法直接将本地编写的文章一键发布到Wordpress中是致命弱点。

Setapp中近期引入了MarsEdit,这是一个较为著名的Blog编写工具,一键发布到Wordpress中是这类工具的标准功能,而稍作配置之后,又可以完美支持Markdown语法。

设置MarsEdit

首先需要设置MarsEdit
NewImage

NewImage

设置Wordpress

还需要设置Wordpress。在Wordpress中首先先安装Jetpack插件,实际上Jetpack已经基本上变为Wordpress的标准插件了。
在Jetpack插件的设置界面,将“使用Markdown语法编写纯文本文章”的选项勾上。
NewImage

用MarsEdit编写文章的优点

在MarsEdit中可以混用HTML和Markdown标志来编写文章,因此一些容易记忆的Markdown语法,比如标题,这是我最常用的Markdown语法,没有之一。比如代码块,对于写技术文章的人来说,代码块是非常方便的。

Markdown示例

以下是代码块的例子。

package main

import (
    "fmt"
    "database/sql"
    _ "gopkg.in/goracle.v2"