{"id":8985,"date":"2016-09-28T14:43:47","date_gmt":"2016-09-28T12:43:47","guid":{"rendered":"https:\/\/www.dbi-services.com\/blog\/running-postgresql-on-zfs-on-linux\/"},"modified":"2016-09-28T14:43:47","modified_gmt":"2016-09-28T12:43:47","slug":"running-postgresql-on-zfs-on-linux","status":"publish","type":"post","link":"https:\/\/www.dbi-services.com\/blog\/running-postgresql-on-zfs-on-linux\/","title":{"rendered":"Running PostgreSQL on ZFS on Linux"},"content":{"rendered":"<p><a href=\"https:\/\/en.wikipedia.org\/wiki\/ZFS\" target=\"_blank\" rel=\"noopener\">ZFS<\/a> for <a href=\"https:\/\/en.wikipedia.org\/wiki\/Solaris_(operating_system)\" target=\"_blank\" rel=\"noopener\">Solaris<\/a> is around for several years now (since 2015). But there is also a project called <a href=\"https:\/\/en.wikipedia.org\/wiki\/OpenZFS\" target=\"_blank\" rel=\"noopener\">OpenZFS<\/a> which makes ZFS available on other operating systems. For Linux the announcement for ZFS being production ready was back in <a href=\"https:\/\/lwn.net\/Articles\/545163\/\" target=\"_blank\" rel=\"noopener\">2013<\/a>. So why not run PostgreSQL on it? ZFS provides many cool <a href=\"http:\/\/open-zfs.org\/wiki\/Features\" target=\"_blank\" rel=\"noopener\">features<\/a> including compression, snapshots and build in volume management. Lets give it a try and do an initial setup. More details will follow in separate posts.<\/p>\n<p><!--more--><\/p>\n<p>As usual I am running a CentOS 7 VM for my tests:<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">\n[root@centos7 ~] lsb_release -a\nLSB Version:\t:core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch\nDistributor ID:\tCentOS\nDescription:\tCentOS Linux release 7.2.1511 (Core) \nRelease:\t7.2.1511\nCodename:\tCore\n<\/pre>\n<p>There is a dedicated website for <a href=\"http:\/\/zfsonlinux.org\/\" target=\"_blank\" rel=\"noopener\">ZFS on Linux<\/a> where you can find the instructions on how to install it for various distributions. The instruction for CentOS\/RHEL are quite easy. Download the repo files:<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">\n[root@centos7 ~] yum install http:\/\/download.zfsonlinux.org\/epel\/zfs-release$(rpm -E %dist).noarch.rpm\nLoaded plugins: fastestmirror\nzfs-release.el7.centos.noarch.rpm                                                                    | 5.0 kB  00:00:00     \nExamining \/var\/tmp\/yum-root-Uv79vc\/zfs-release.el7.centos.noarch.rpm: zfs-release-1-3.el7.centos.noarch\nMarking \/var\/tmp\/yum-root-Uv79vc\/zfs-release.el7.centos.noarch.rpm to be installed\nResolving Dependencies\n--&gt; Running transaction check\n---&gt; Package zfs-release.noarch 0:1-3.el7.centos will be installed\n--&gt; Finished Dependency Resolution\n\nDependencies Resolved\n\n============================================================================================================================\n Package                  Arch                Version                     Repository                                   Size\n============================================================================================================================\nInstalling:\n zfs-release              noarch              1-3.el7.centos              \/zfs-release.el7.centos.noarch              2.9 k\n\nTransaction Summary\n============================================================================================================================\nInstall  1 Package\n\nTotal size: 2.9 k\nInstalled size: 2.9 k\nIs this ok [y\/d\/N]: y\nDownloading packages:\nRunning transaction check\nRunning transaction test\nTransaction test succeeded\nRunning transaction\n  Installing : zfs-release-1-3.el7.centos.noarch                                                                        1\/1 \n  Verifying  : zfs-release-1-3.el7.centos.noarch                                                                        1\/1 \n\nInstalled:\n  zfs-release.noarch 0:1-3.el7.centos                                                                                       \n\nComplete!\n\n[root@centos7 ~] gpg --quiet --with-fingerprint \/etc\/pki\/rpm-gpg\/RPM-GPG-KEY-zfsonlinux\ngpg: new configuration file `\/root\/.gnupg\/gpg.conf' created\ngpg: WARNING: options in `\/root\/.gnupg\/gpg.conf' are not yet active during this run\npub  2048R\/F14AB620 2013-03-21 ZFS on Linux \n      Key fingerprint = C93A FFFD 9F3F 7B03 C310  CEB6 A9D5 A1C0 F14A B620\nsub  2048R\/99685629 2013-03-21\n<\/pre>\n<p>For the next step it depends if you want to go with <a href=\"https:\/\/en.wikipedia.org\/wiki\/Dynamic_Kernel_Module_Support\" target=\"_blank\" rel=\"noopener\">DKMS<\/a> or <a href=\"https:\/\/elrepo.org\/tiki\/FAQ\" target=\"_blank\" rel=\"noopener\">kABI-tracking kmod<\/a>. I&#8217;ll go with kABI-tracking kmod and therefore will disable the DKMS repository and enable the kmod repository:<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">\n[root@centos7 ~] cat \/etc\/yum.repos.d\/zfs.repo \n[zfs]\nname=ZFS on Linux for EL7 - dkms\nbaseurl=http:\/\/download.zfsonlinux.org\/epel\/7\/$basearch\/\nenabled=0\nmetadata_expire=7d\ngpgcheck=1\ngpgkey=file:\/\/\/etc\/pki\/rpm-gpg\/RPM-GPG-KEY-zfsonlinux\n\n[zfs-kmod]\nname=ZFS on Linux for EL7 - kmod\nbaseurl=http:\/\/download.zfsonlinux.org\/epel\/7\/kmod\/$basearch\/\nenabled=1\nmetadata_expire=7d\ngpgcheck=1\ngpgkey=file:\/\/\/etc\/pki\/rpm-gpg\/RPM-GPG-KEY-zfsonlinux\n\n[zfs-source]\nname=ZFS on Linux for EL7 - Source\nbaseurl=http:\/\/download.zfsonlinux.org\/epel\/7\/SRPMS\/\nenabled=0\ngpgcheck=1\ngpgkey=file:\/\/\/etc\/pki\/rpm-gpg\/RPM-GPG-KEY-zfsonlinux\n\n[zfs-testing]\nname=ZFS on Linux for EL7 - dkms - Testing\nbaseurl=http:\/\/download.zfsonlinux.org\/epel-testing\/7\/$basearch\/\nenabled=0\nmetadata_expire=7d\ngpgcheck=1\ngpgkey=file:\/\/\/etc\/pki\/rpm-gpg\/RPM-GPG-KEY-zfsonlinux\n\n[zfs-testing-kmod]\nname=ZFS on Linux for EL7 - kmod - Testing\nbaseurl=http:\/\/download.zfsonlinux.org\/epel-testing\/7\/kmod\/$basearch\/\nenabled=0\nmetadata_expire=7d\ngpgcheck=1\ngpgkey=file:\/\/\/etc\/pki\/rpm-gpg\/RPM-GPG-KEY-zfsonlinux\n\n[zfs-testing-source]\nname=ZFS on Linux for EL7 - Testing Source\nbaseurl=http:\/\/download.zfsonlinux.org\/epel-testing\/7\/SRPMS\/\nenabled=0\ngpgcheck=1\ngpgkey=file:\/\/\/etc\/pki\/rpm-gpg\/RPM-GPG-KEY-zfsonlinux\n[root@centos7 ~] \n<\/pre>\n<p>Installing ZFS from here on is just a matter of using yum:<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">\n[root@centos7 ~] yum install zfs\nLoaded plugins: fastestmirror\nLoading mirror speeds from cached hostfile\n * base: mirror.spreitzer.ch\n * extras: mirror.spreitzer.ch\n * updates: mirror.de.leaseweb.net\nzfs-kmod\/x86_64\/primary_db                                                                           | 231 kB  00:00:01     \nResolving Dependencies\n--&gt; Running transaction check\n---&gt; Package zfs.x86_64 0:0.6.5.8-1.el7.centos will be installed\n--&gt; Processing Dependency: zfs-kmod = 0.6.5.8 for package: zfs-0.6.5.8-1.el7.centos.x86_64\n--&gt; Processing Dependency: spl = 0.6.5.8 for package: zfs-0.6.5.8-1.el7.centos.x86_64\n--&gt; Processing Dependency: libzpool2 = 0.6.5.8 for package: zfs-0.6.5.8-1.el7.centos.x86_64\n--&gt; Processing Dependency: libzfs2 = 0.6.5.8 for package: zfs-0.6.5.8-1.el7.centos.x86_64\n--&gt; Processing Dependency: libuutil1 = 0.6.5.8 for package: zfs-0.6.5.8-1.el7.centos.x86_64\n--&gt; Processing Dependency: libnvpair1 = 0.6.5.8 for package: zfs-0.6.5.8-1.el7.centos.x86_64\n--&gt; Processing Dependency: libzpool.so.2()(64bit) for package: zfs-0.6.5.8-1.el7.centos.x86_64\n--&gt; Processing Dependency: libzfs_core.so.1()(64bit) for package: zfs-0.6.5.8-1.el7.centos.x86_64\n--&gt; Processing Dependency: libzfs.so.2()(64bit) for package: zfs-0.6.5.8-1.el7.centos.x86_64\n--&gt; Processing Dependency: libuutil.so.1()(64bit) for package: zfs-0.6.5.8-1.el7.centos.x86_64\n--&gt; Processing Dependency: libnvpair.so.1()(64bit) for package: zfs-0.6.5.8-1.el7.centos.x86_64\n--&gt; Running transaction check\n---&gt; Package kmod-zfs.x86_64 0:0.6.5.8-1.el7.centos will be installed\n--&gt; Processing Dependency: spl-kmod for package: kmod-zfs-0.6.5.8-1.el7.centos.x86_64\n---&gt; Package libnvpair1.x86_64 0:0.6.5.8-1.el7.centos will be installed\n---&gt; Package libuutil1.x86_64 0:0.6.5.8-1.el7.centos will be installed\n---&gt; Package libzfs2.x86_64 0:0.6.5.8-1.el7.centos will be installed\n---&gt; Package libzpool2.x86_64 0:0.6.5.8-1.el7.centos will be installed\n---&gt; Package spl.x86_64 0:0.6.5.8-1.el7.centos will be installed\n--&gt; Running transaction check\n---&gt; Package kmod-spl.x86_64 0:0.6.5.8-1.el7.centos will be installed\n--&gt; Finished Dependency Resolution\n\nDependencies Resolved\n\n============================================================================================================================\n Package                     Arch                    Version                                Repository                 Size\n============================================================================================================================\nInstalling:\n zfs                         x86_64                  0.6.5.8-1.el7.centos                   zfs-kmod                  334 k\nInstalling for dependencies:\n kmod-spl                    x86_64                  0.6.5.8-1.el7.centos                   zfs-kmod                  110 k\n kmod-zfs                    x86_64                  0.6.5.8-1.el7.centos                   zfs-kmod                  665 k\n libnvpair1                  x86_64                  0.6.5.8-1.el7.centos                   zfs-kmod                   35 k\n libuutil1                   x86_64                  0.6.5.8-1.el7.centos                   zfs-kmod                   41 k\n libzfs2                     x86_64                  0.6.5.8-1.el7.centos                   zfs-kmod                  123 k\n libzpool2                   x86_64                  0.6.5.8-1.el7.centos                   zfs-kmod                  423 k\n spl                         x86_64                  0.6.5.8-1.el7.centos                   zfs-kmod                   29 k\n\nTransaction Summary\n============================================================================================================================\nInstall  1 Package (+7 Dependent packages)\n\nTotal download size: 1.7 M\nInstalled size: 5.7 M\nIs this ok [y\/d\/N]: y\nDownloading packages:\n(1\/8): kmod-spl-0.6.5.8-1.el7.centos.x86_64.rpm                                                      | 110 kB  00:00:01     \n(2\/8): libnvpair1-0.6.5.8-1.el7.centos.x86_64.rpm                                                    |  35 kB  00:00:00     \n(3\/8): libuutil1-0.6.5.8-1.el7.centos.x86_64.rpm                                                     |  41 kB  00:00:00     \n(4\/8): kmod-zfs-0.6.5.8-1.el7.centos.x86_64.rpm                                                      | 665 kB  00:00:02     \n(5\/8): libzfs2-0.6.5.8-1.el7.centos.x86_64.rpm                                                       | 123 kB  00:00:00     \n(6\/8): libzpool2-0.6.5.8-1.el7.centos.x86_64.rpm                                                     | 423 kB  00:00:00     \n(7\/8): spl-0.6.5.8-1.el7.centos.x86_64.rpm                                                           |  29 kB  00:00:00     \n(8\/8): zfs-0.6.5.8-1.el7.centos.x86_64.rpm                                                           | 334 kB  00:00:00     \n----------------------------------------------------------------------------------------------------------------------------\nTotal                                                                                       513 kB\/s | 1.7 MB  00:00:03     \nRunning transaction check\nRunning transaction test\nTransaction test succeeded\nRunning transaction\n  Installing : libuutil1-0.6.5.8-1.el7.centos.x86_64                                                                    1\/8 \n  Installing : libnvpair1-0.6.5.8-1.el7.centos.x86_64                                                                   2\/8 \n  Installing : libzpool2-0.6.5.8-1.el7.centos.x86_64                                                                    3\/8 \n  Installing : kmod-spl-0.6.5.8-1.el7.centos.x86_64                                                                     4\/8 \n  Installing : spl-0.6.5.8-1.el7.centos.x86_64                                                                          5\/8 \n  Installing : libzfs2-0.6.5.8-1.el7.centos.x86_64                                                                      6\/8 \n  Installing : kmod-zfs-0.6.5.8-1.el7.centos.x86_64                                                                     7\/8 \n  Installing : zfs-0.6.5.8-1.el7.centos.x86_64                                                                          8\/8 \n  Verifying  : libnvpair1-0.6.5.8-1.el7.centos.x86_64                                                                   1\/8 \n  Verifying  : libzfs2-0.6.5.8-1.el7.centos.x86_64                                                                      2\/8 \n  Verifying  : zfs-0.6.5.8-1.el7.centos.x86_64                                                                          3\/8 \n  Verifying  : spl-0.6.5.8-1.el7.centos.x86_64                                                                          4\/8 \n  Verifying  : kmod-zfs-0.6.5.8-1.el7.centos.x86_64                                                                     5\/8 \n  Verifying  : libzpool2-0.6.5.8-1.el7.centos.x86_64                                                                    6\/8 \n  Verifying  : libuutil1-0.6.5.8-1.el7.centos.x86_64                                                                    7\/8 \n  Verifying  : kmod-spl-0.6.5.8-1.el7.centos.x86_64                                                                     8\/8 \n\nInstalled:\n  zfs.x86_64 0:0.6.5.8-1.el7.centos                                                                                         \n\nDependency Installed:\n  kmod-spl.x86_64 0:0.6.5.8-1.el7.centos   kmod-zfs.x86_64 0:0.6.5.8-1.el7.centos  libnvpair1.x86_64 0:0.6.5.8-1.el7.centos \n  libuutil1.x86_64 0:0.6.5.8-1.el7.centos  libzfs2.x86_64 0:0.6.5.8-1.el7.centos   libzpool2.x86_64 0:0.6.5.8-1.el7.centos  \n  spl.x86_64 0:0.6.5.8-1.el7.centos       \n\nComplete!\n[root@centos7 ~]\n<\/pre>\n<p>Be aware that the kernel modules are not loaded by default, so you have to do this on your own:<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">\n[root@centos7 ~] \/sbin\/modprobe zfs\nLast login: Wed Sep 28 11:04:21 2016 from 192.168.22.1\n[postgres@centos7 ~]$ lsmod | grep zfs\nzfs                  2713912  0 \nzunicode              331170  1 zfs\nzavl                   15236  1 zfs\nzcommon                55411  1 zfs\nznvpair                93227  2 zfs,zcommon\nspl                    92223  3 zfs,zcommon,znvpair\n[root@centos7 ~] zfs list\nno datasets available\n<\/pre>\n<p>For loading the modules automatically create a file under \/etc\/modules-load.d:<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">\n[root@centos7 ~] echo \"zfs\" &gt; \/etc\/modules-load.d\/zfs.conf\n[root@centos7 ~] cat \/etc\/modules-load.d\/zfs.conf\nzfs\n<\/pre>\n<p>So far so good. Lets create a ZFS file system. I have two disks available for playing with ZFS (sdb and sdc):<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">\n[root@centos7 ~] ls -la \/dev\/sd*\nbrw-rw----. 1 root disk 8,  0 Sep 28 11:14 \/dev\/sda\nbrw-rw----. 1 root disk 8,  1 Sep 28 11:14 \/dev\/sda1\nbrw-rw----. 1 root disk 8,  2 Sep 28 11:14 \/dev\/sda2\nbrw-rw----. 1 root disk 8, 16 Sep 28 11:14 \/dev\/sdb\nbrw-rw----. 1 root disk 8, 32 Sep 28 11:14 \/dev\/sdc\n<\/pre>\n<p>The first thing you have to do is to create a new <a href=\"https:\/\/en.wikipedia.org\/wiki\/ZFS#Storage_pools\" target=\"_blank\" rel=\"noopener\">zfs pool<\/a> (I don&#8217;t care about the warnings, that is why I use the &#8220;-f&#8221; option below):<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">\n[root@centos7 ~] zpool create pgpool mirror \/dev\/sdb \/dev\/sdc\ninvalid vdev specification\nuse '-f' to override the following errors:\n\/dev\/sdb does not contain an EFI label but it may contain partition information in the MBR.\n\/dev\/sdc does not contain an EFI label but it may contain partition information in the MBR.\n[root@centos7 ~] zpool create pgpool mirror \/dev\/sdb \/dev\/sdc -f\n[root@centos7 ~] zpool list\nNAME     SIZE  ALLOC   FREE  EXPANDSZ   FRAG    CAP  DEDUP  HEALTH  ALTROOT\npgpool  9.94G    65K  9.94G         -     0%     0%  1.00x  ONLINE  -\n[root@centos7 ~] zpool status pgpool\n  pool: pgpool\n state: ONLINE\n  scan: none requested\nconfig:\n\n\tNAME        STATE     READ WRITE CKSUM\n\tpgpool      ONLINE       0     0     0\n\t  mirror-0  ONLINE       0     0     0\n\t    sdb     ONLINE       0     0     0\n\t    sdc     ONLINE       0     0     0\n\nerrors: No known data errors\n\n[root@centos7 ~] df -h\nFilesystem               Size  Used Avail Use% Mounted on\n\/dev\/mapper\/centos-root   49G  1.7G   47G   4% \/\ndevtmpfs                 235M     0  235M   0% \/dev\ntmpfs                    245M     0  245M   0% \/dev\/shm\ntmpfs                    245M  4.3M  241M   2% \/run\ntmpfs                    245M     0  245M   0% \/sys\/fs\/cgroup\n\/dev\/sda1                497M  291M  206M  59% \/boot\ntmpfs                     49M     0   49M   0% \/run\/user\/1000\npgpool                   9.7G     0  9.7G   0% \/pgpool\n<\/pre>\n<p>What I did here is to create a mirrored pool over my two disks. The <a href=\"http:\/\/open-zfs.org\/wiki\/Performance_tuning#PostgreSQL\" target=\"_blank\" rel=\"noopener\">open zfs wiki<\/a> has some performance tips for running PostgreSQL on ZFS as well as for other topics. Lets go with the recommendations:<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">\n[root@centos7 ~] zfs create pgpool\/pgdata -o recordsize=8192\n[root@centos7 ~] zfs set logbias=throughput pgpool\/pgdata\n[root@centos7 ~] zfs set primarycache=all pgpool\/pgdata\n[root@centos7 ~] zfs list\nNAME            USED  AVAIL  REFER  MOUNTPOINT\npgpool           82K  9.63G  19.5K  \/pgpool\npgpool\/pgdata    19K  9.63G    19K  \/pgpool\/pgdata\n<\/pre>\n<p>My new ZFS file system is ready and already mounted, cool. Lets change the permissions and list all the properties:<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">\n[root@centos7 ~] chown postgres:postgres \/pgpool\/pgdata\n[root@centos7 ~] zfs get all \/pgpool\/pgdata\nNAME           PROPERTY              VALUE                  SOURCE\npgpool\/pgdata  type                  filesystem             -\npgpool\/pgdata  creation              Wed Sep 28 11:31 2016  -\npgpool\/pgdata  used                  19K                    -\npgpool\/pgdata  available             9.63G                  -\npgpool\/pgdata  referenced            19K                    -\npgpool\/pgdata  compressratio         1.00x                  -\npgpool\/pgdata  mounted               yes                    -\npgpool\/pgdata  quota                 none                   default\npgpool\/pgdata  reservation           none                   default\npgpool\/pgdata  recordsize            8K                     local\npgpool\/pgdata  mountpoint            \/pgpool\/pgdata         default\npgpool\/pgdata  sharenfs              off                    default\npgpool\/pgdata  checksum              on                     default\npgpool\/pgdata  compression           off                    default\npgpool\/pgdata  atime                 on                     default\npgpool\/pgdata  devices               on                     default\npgpool\/pgdata  exec                  on                     default\npgpool\/pgdata  setuid                on                     default\npgpool\/pgdata  readonly              off                    default\npgpool\/pgdata  zoned                 off                    default\npgpool\/pgdata  snapdir               hidden                 default\npgpool\/pgdata  aclinherit            restricted             default\npgpool\/pgdata  canmount              on                     default\npgpool\/pgdata  xattr                 on                     default\npgpool\/pgdata  copies                1                      default\npgpool\/pgdata  version               5                      -\npgpool\/pgdata  utf8only              off                    -\npgpool\/pgdata  normalization         none                   -\npgpool\/pgdata  casesensitivity       sensitive              -\npgpool\/pgdata  vscan                 off                    default\npgpool\/pgdata  nbmand                off                    default\npgpool\/pgdata  sharesmb              off                    default\npgpool\/pgdata  refquota              none                   default\npgpool\/pgdata  refreservation        none                   default\npgpool\/pgdata  primarycache          all                    default\npgpool\/pgdata  secondarycache        all                    default\npgpool\/pgdata  usedbysnapshots       0                      -\npgpool\/pgdata  usedbydataset         19K                    -\npgpool\/pgdata  usedbychildren        0                      -\npgpool\/pgdata  usedbyrefreservation  0                      -\npgpool\/pgdata  logbias               throughput             local\npgpool\/pgdata  dedup                 off                    default\npgpool\/pgdata  mlslabel              none                   default\npgpool\/pgdata  sync                  standard               default\npgpool\/pgdata  refcompressratio      1.00x                  -\npgpool\/pgdata  written               19K                    -\npgpool\/pgdata  logicalused           9.50K                  -\npgpool\/pgdata  logicalreferenced     9.50K                  -\npgpool\/pgdata  filesystem_limit      none                   default\npgpool\/pgdata  snapshot_limit        none                   default\npgpool\/pgdata  filesystem_count      none                   default\npgpool\/pgdata  snapshot_count        none                   default\npgpool\/pgdata  snapdev               hidden                 default\npgpool\/pgdata  acltype               off                    default\npgpool\/pgdata  context               none                   default\npgpool\/pgdata  fscontext             none                   default\npgpool\/pgdata  defcontext            none                   default\npgpool\/pgdata  rootcontext           none                   default\npgpool\/pgdata  relatime              on                     temporary\npgpool\/pgdata  redundant_metadata    all                    default\npgpool\/pgdata  overlay               off                    default\n<\/pre>\n<p>Ready to deploy a PostgreSQL instance on it:<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">\npostgres@centos7:\/home\/postgres\/ [pg954] initdb -D \/pgpool\/pgdata\/\nThe files belonging to this database system will be owned by user \"postgres\".\nThis user must also own the server process.\n\nThe database cluster will be initialized with locales\n  COLLATE:  en_US.UTF-8\n  CTYPE:    en_US.UTF-8\n  MESSAGES: en_US.UTF-8\n  MONETARY: de_CH.UTF-8\n  NUMERIC:  de_CH.UTF-8\n  TIME:     en_US.UTF-8\nThe default database encoding has accordingly been set to \"UTF8\".\nThe default text search configuration will be set to \"english\".\n\nData page checksums are disabled.\n\nfixing permissions on existing directory \/pgpool\/pgdata ... ok\ncreating subdirectories ... ok\nselecting default max_connections ... 100\nselecting default shared_buffers ... 128MB\nselecting dynamic shared memory implementation ... posix\ncreating configuration files ... ok\ncreating template1 database in \/pgpool\/pgdata\/base\/1 ... ok\ninitializing pg_authid ... ok\ninitializing dependencies ... ok\ncreating system views ... ok\nloading system objects' descriptions ... ok\ncreating collations ... ok\ncreating conversions ... ok\ncreating dictionaries ... ok\nsetting privileges on built-in objects ... ok\ncreating information schema ... ok\nloading PL\/pgSQL server-side language ... ok\nvacuuming database template1 ... ok\ncopying template1 to template0 ... ok\ncopying template1 to postgres ... ok\nsyncing data to disk ... ok\n\nWARNING: enabling \"trust\" authentication for local connections\nYou can change this by editing pg_hba.conf or using the option -A, or\n--auth-local and --auth-host, the next time you run initdb.\n\nSuccess. You can now start the database server using:\n\n    pg_ctl -D \/pgpool\/pgdata\/ -l logfile start\n<\/pre>\n<p>Startup:<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">\npostgres@centos7:\/home\/postgres\/ [pg954] mkdir \/pgpool\/pgdata\/pg_log\npostgres@centos7:\/home\/postgres\/ [pg954] sed -i 's\/logging_collector = off\/logging_collector = on\/g' \/pgpool\/pgdata\/postgresql.conf\npostgres@centos7:\/home\/postgres\/ [pg954] pg_ctl -D \/pgpool\/pgdata\/ start\npostgres@centos7:\/home\/postgres\/ [pg954] psql postgres\npsql (9.5.4 dbi services build)\nType \"help\" for help.\n\npostgres=\n<\/pre>\n<p>Ready. Lets reboot and check if the ZFS file system is mounted automatically:<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">\npostgres@centos7:\/home\/postgres\/ [pg954] df -h\nFilesystem               Size  Used Avail Use% Mounted on\n\/dev\/mapper\/centos-root   49G  1.8G   47G   4% \/\ndevtmpfs                 235M     0  235M   0% \/dev\ntmpfs                    245M     0  245M   0% \/dev\/shm\ntmpfs                    245M  4.3M  241M   2% \/run\ntmpfs                    245M     0  245M   0% \/sys\/fs\/cgroup\n\/dev\/sda1                497M  291M  206M  59% \/boot\ntmpfs                     49M     0   49M   0% \/run\/user\/1000\npostgres@centos7:\/home\/postgres\/ [pg954] lsmod | grep zfs\nzfs                  2713912  0 \nzunicode              331170  1 zfs\nzavl                   15236  1 zfs\nzcommon                55411  1 zfs\nznvpair                93227  2 zfs,zcommon\nspl                    92223  3 zfs,zcommon,znvpair\n<\/pre>\n<p>Gone. The kernel modules are loaded but the file system was not mounted. What to do?<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">\n[root@centos7 ~] zpool list\nno pools available\n[root@centos7 ~] zpool import pgpool\n[root@centos7 ~] zpool list\nNAME     SIZE  ALLOC   FREE  EXPANDSZ   FRAG    CAP  DEDUP  HEALTH  ALTROOT\npgpool  9.94G  39.3M  9.90G         -     0%     0%  1.00x  ONLINE  -\n[root@centos7 ~]# df -h\nFilesystem               Size  Used Avail Use% Mounted on\n\/dev\/mapper\/centos-root   49G  1.8G   47G   4% \/\ndevtmpfs                 235M     0  235M   0% \/dev\ntmpfs                    245M     0  245M   0% \/dev\/shm\ntmpfs                    245M  4.3M  241M   2% \/run\ntmpfs                    245M     0  245M   0% \/sys\/fs\/cgroup\n\/dev\/sda1                497M  291M  206M  59% \/boot\ntmpfs                     49M     0   49M   0% \/run\/user\/1000\npgpool                   9.6G     0  9.6G   0% \/pgpool\npgpool\/pgdata            9.7G   39M  9.6G   1% \/pgpool\/pgdata\n<\/pre>\n<p>Ok, how to auto mount?<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">\n[root@centos7 ~] systemctl enable zfs-mount\n[root@centos7 ~] systemctl enable zfs-import-cache\n[root@centos7 ~] reboot\n<\/pre>\n<p>I am not sure why this is necessary, should happen automatically. <\/p>\n<p>PS: There is an interesting discussion about PostgreSQL on ZFS on the <a href=\"https:\/\/www.postgresql.org\/message-id\/flat\/5974493a-6785-1d7f-3b06-ba36468763ae%40toco-domains.de#5974493a-6785-1d7f-3b06-ba36468763ae@toco-domains.de\" target=\"_blank\" rel=\"noopener\">PostgreSQL performance mailing<\/a> list currently.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>ZFS for Solaris is around for several years now (since 2015). But there is also a project called OpenZFS which makes ZFS available on other operating systems. For Linux the announcement for ZFS being production ready was back in 2013. So why not run PostgreSQL on it? ZFS provides many cool features including compression, snapshots [&hellip;]<\/p>\n","protected":false},"author":29,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[229],"tags":[611,73,77,935],"type_dbi":[],"class_list":["post-8985","post","type-post","status-publish","format-standard","hentry","category-database-administration-monitoring","tag-filesytem","tag-linux","tag-postgresql","tag-zfs"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.2 (Yoast SEO v27.2) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Running PostgreSQL on ZFS on Linux - dbi Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.dbi-services.com\/blog\/running-postgresql-on-zfs-on-linux\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Running PostgreSQL on ZFS on Linux\" \/>\n<meta property=\"og:description\" content=\"ZFS for Solaris is around for several years now (since 2015). But there is also a project called OpenZFS which makes ZFS available on other operating systems. For Linux the announcement for ZFS being production ready was back in 2013. So why not run PostgreSQL on it? ZFS provides many cool features including compression, snapshots [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dbi-services.com\/blog\/running-postgresql-on-zfs-on-linux\/\" \/>\n<meta property=\"og:site_name\" content=\"dbi Blog\" \/>\n<meta property=\"article:published_time\" content=\"2016-09-28T12:43:47+00:00\" \/>\n<meta name=\"author\" content=\"Daniel Westermann\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@westermanndanie\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Daniel Westermann\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"13 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/running-postgresql-on-zfs-on-linux\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/running-postgresql-on-zfs-on-linux\/\"},\"author\":{\"name\":\"Daniel Westermann\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/8d08e9bd996a89bd75c0286cbabf3c66\"},\"headline\":\"Running PostgreSQL on ZFS on Linux\",\"datePublished\":\"2016-09-28T12:43:47+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/running-postgresql-on-zfs-on-linux\/\"},\"wordCount\":386,\"commentCount\":0,\"keywords\":[\"filesytem\",\"Linux\",\"PostgreSQL\",\"ZFS\"],\"articleSection\":[\"Database Administration &amp; Monitoring\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/running-postgresql-on-zfs-on-linux\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/running-postgresql-on-zfs-on-linux\/\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/running-postgresql-on-zfs-on-linux\/\",\"name\":\"Running PostgreSQL on ZFS on Linux - dbi Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\"},\"datePublished\":\"2016-09-28T12:43:47+00:00\",\"author\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/8d08e9bd996a89bd75c0286cbabf3c66\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/running-postgresql-on-zfs-on-linux\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/running-postgresql-on-zfs-on-linux\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/running-postgresql-on-zfs-on-linux\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Accueil\",\"item\":\"https:\/\/www.dbi-services.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Running PostgreSQL on ZFS on Linux\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/\",\"name\":\"dbi Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/8d08e9bd996a89bd75c0286cbabf3c66\",\"name\":\"Daniel Westermann\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/31350ceeecb1dd8986339a29bf040d4cd3cd087d410deccd8f55234466d6c317?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/31350ceeecb1dd8986339a29bf040d4cd3cd087d410deccd8f55234466d6c317?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/31350ceeecb1dd8986339a29bf040d4cd3cd087d410deccd8f55234466d6c317?s=96&d=mm&r=g\",\"caption\":\"Daniel Westermann\"},\"description\":\"Daniel Westermann is Principal Consultant and Technology Leader Open Infrastructure at dbi services. He has more than 15 years of experience in management, engineering and optimization of databases and infrastructures, especially on Oracle and PostgreSQL. Since the beginning of his career, he has specialized in Oracle Technologies and is Oracle Certified Professional 12c and Oracle Certified Expert RAC\/GridInfra. Over time, Daniel has become increasingly interested in open source technologies, becoming \u201cTechnology Leader Open Infrastructure\u201d and PostgreSQL expert. \u00a0Based on community or EnterpriseDB tools, he develops and installs complex high available solutions with PostgreSQL. He is also a certified PostgreSQL Plus 9.0 Professional and a Postgres Advanced Server 9.4 Professional. He is a regular speaker at PostgreSQL conferences in Switzerland and Europe. Today Daniel is also supporting our customers on AWS services such as AWS RDS, database migrations into the cloud, EC2 and automated infrastructure management with AWS SSM (System Manager). He is a certified AWS Solutions Architect Professional. Prior to dbi services, Daniel was Management System Engineer at LC SYSTEMS-Engineering AG in Basel. Before that, he worked as Oracle Developper &amp;\u00a0Project Manager at Delta Energy Solutions AG in Basel (today Powel AG). Daniel holds a diploma in Business Informatics (DHBW, Germany). His branch-related experience mainly covers the pharma industry, the financial sector, energy, lottery and telecommunications.\",\"sameAs\":[\"https:\/\/x.com\/westermanndanie\"],\"url\":\"https:\/\/www.dbi-services.com\/blog\/author\/daniel-westermann\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Running PostgreSQL on ZFS on Linux - dbi Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.dbi-services.com\/blog\/running-postgresql-on-zfs-on-linux\/","og_locale":"en_US","og_type":"article","og_title":"Running PostgreSQL on ZFS on Linux","og_description":"ZFS for Solaris is around for several years now (since 2015). But there is also a project called OpenZFS which makes ZFS available on other operating systems. For Linux the announcement for ZFS being production ready was back in 2013. So why not run PostgreSQL on it? ZFS provides many cool features including compression, snapshots [&hellip;]","og_url":"https:\/\/www.dbi-services.com\/blog\/running-postgresql-on-zfs-on-linux\/","og_site_name":"dbi Blog","article_published_time":"2016-09-28T12:43:47+00:00","author":"Daniel Westermann","twitter_card":"summary_large_image","twitter_creator":"@westermanndanie","twitter_misc":{"Written by":"Daniel Westermann","Est. reading time":"13 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.dbi-services.com\/blog\/running-postgresql-on-zfs-on-linux\/#article","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/running-postgresql-on-zfs-on-linux\/"},"author":{"name":"Daniel Westermann","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/8d08e9bd996a89bd75c0286cbabf3c66"},"headline":"Running PostgreSQL on ZFS on Linux","datePublished":"2016-09-28T12:43:47+00:00","mainEntityOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/running-postgresql-on-zfs-on-linux\/"},"wordCount":386,"commentCount":0,"keywords":["filesytem","Linux","PostgreSQL","ZFS"],"articleSection":["Database Administration &amp; Monitoring"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.dbi-services.com\/blog\/running-postgresql-on-zfs-on-linux\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.dbi-services.com\/blog\/running-postgresql-on-zfs-on-linux\/","url":"https:\/\/www.dbi-services.com\/blog\/running-postgresql-on-zfs-on-linux\/","name":"Running PostgreSQL on ZFS on Linux - dbi Blog","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/#website"},"datePublished":"2016-09-28T12:43:47+00:00","author":{"@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/8d08e9bd996a89bd75c0286cbabf3c66"},"breadcrumb":{"@id":"https:\/\/www.dbi-services.com\/blog\/running-postgresql-on-zfs-on-linux\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dbi-services.com\/blog\/running-postgresql-on-zfs-on-linux\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.dbi-services.com\/blog\/running-postgresql-on-zfs-on-linux\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Accueil","item":"https:\/\/www.dbi-services.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Running PostgreSQL on ZFS on Linux"}]},{"@type":"WebSite","@id":"https:\/\/www.dbi-services.com\/blog\/#website","url":"https:\/\/www.dbi-services.com\/blog\/","name":"dbi Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/8d08e9bd996a89bd75c0286cbabf3c66","name":"Daniel Westermann","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/31350ceeecb1dd8986339a29bf040d4cd3cd087d410deccd8f55234466d6c317?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/31350ceeecb1dd8986339a29bf040d4cd3cd087d410deccd8f55234466d6c317?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/31350ceeecb1dd8986339a29bf040d4cd3cd087d410deccd8f55234466d6c317?s=96&d=mm&r=g","caption":"Daniel Westermann"},"description":"Daniel Westermann is Principal Consultant and Technology Leader Open Infrastructure at dbi services. He has more than 15 years of experience in management, engineering and optimization of databases and infrastructures, especially on Oracle and PostgreSQL. Since the beginning of his career, he has specialized in Oracle Technologies and is Oracle Certified Professional 12c and Oracle Certified Expert RAC\/GridInfra. Over time, Daniel has become increasingly interested in open source technologies, becoming \u201cTechnology Leader Open Infrastructure\u201d and PostgreSQL expert. \u00a0Based on community or EnterpriseDB tools, he develops and installs complex high available solutions with PostgreSQL. He is also a certified PostgreSQL Plus 9.0 Professional and a Postgres Advanced Server 9.4 Professional. He is a regular speaker at PostgreSQL conferences in Switzerland and Europe. Today Daniel is also supporting our customers on AWS services such as AWS RDS, database migrations into the cloud, EC2 and automated infrastructure management with AWS SSM (System Manager). He is a certified AWS Solutions Architect Professional. Prior to dbi services, Daniel was Management System Engineer at LC SYSTEMS-Engineering AG in Basel. Before that, he worked as Oracle Developper &amp;\u00a0Project Manager at Delta Energy Solutions AG in Basel (today Powel AG). Daniel holds a diploma in Business Informatics (DHBW, Germany). His branch-related experience mainly covers the pharma industry, the financial sector, energy, lottery and telecommunications.","sameAs":["https:\/\/x.com\/westermanndanie"],"url":"https:\/\/www.dbi-services.com\/blog\/author\/daniel-westermann\/"}]}},"_links":{"self":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/8985","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/users\/29"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/comments?post=8985"}],"version-history":[{"count":0,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/8985\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media?parent=8985"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/categories?post=8985"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/tags?post=8985"},{"taxonomy":"type","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/type_dbi?post=8985"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}