By Jignesh Shah on Nov 10, 2008
The New Sun Microsystems announced a new line of OpenStorage devices. The new Sun Storage 7000 Unified Storage Systems (code name Amber Road) are Storage appliances which uses ZFS as the core technology and DTrace as the means of "understanding" what's happening with the devices. This now allows systems which DO NOT have ZFS capabilities (ala Linux, Windows, etc) to use and gain benefit from the features of ZFS and DTrace (albeit limited to the "Storage" part only).
PostgreSQL (on Linux,Solaris, Windows) can use such systems through one of the standard protocols that these OpenStorage devices support
- CIFS (Only on Windows)
PostgreSQL on NFS is already discussed at length (both merits and also the demerits of using NFS with PostgreSQL ) in the PostgreSQL community. Also I haven't met anybody yet who said that they are using PostgreSQL with their database on CIFS mounted devices. So I think one might actually select iSCSI as the favorable protocol for such OpenStorage devices with PostgreSQL. (Correct me via comments if you think otherwise.)
Here are quick steps that I had used to configure the PostgreSQL server (running Solaris 10) to use iSCSI devices exported from Sun Storage 7000 Unified Storage Platform
In my case I had created two iSCSI LUN devices (one for PGDATA and one for pg_xlog) with file permissions for the postgres user. (This setup is generally done using the BUI - Browser User Interface of the OpenStorage "Amber Road" device.)
Now on the PostgreSQL Server I did the following to setup iSCSI initiators and LUNS:
Add and display iSCSI target discovery address by giving the IP of the "Amber Road" system.
# iscsiadm add discovery-address 10.9.168.93
# iscsiadm list discovery-address
Discovery Address: 10.9.168.93:3260
Display iSCSI targets discovered from the Amber Road system
# iscsiadm list discovery-address -v 10.9.168.93
Discovery Address: 10.6.140.151:3260
Target name: iqn.1986-03.com.sun:02:a4602145-85f8-64fa-c0ef-a059394d9a12
Target address: 10.9.168.93:3260, 1
Target name: iqn.1986-03.com.sun:02:0449398a-486f-4296-9716-bcba3c1be41c
Target address: 10.9.168.93:3260, 1
Enable and display static discovery.
# iscsiadm modify discovery --static enable
# iscsiadm list discovery
Send Targets: disabled
Adds a target to the list of statically configured targets. A connection to the target will not be attempted unless the static configuration method of discovery has been enabled.
Use Solaris devfsadm(1M) to create iSCSI device nodes.
# devfsadm -i iscsi
Use format(1M) command to access iSCSI disks. The disk(s) to be selected contain /scsi_vhci in their path name. Local disks are listed before iSCSI disks in the format command list. The following shows disk no. 4 and 5 are iSCSI disks.
Searching for disks...done
AVAILABLE DISK SELECTIONS:
0. c0t0d0 <DEFAULT cyl 17830 alt 2 hd 255 sec 63>
1. c0t1d0 <DEFAULT cyl 17830 alt 2 hd 255 sec 63>
2. c0t2d0 <DEFAULT cyl 17830 alt 2 hd 255 sec 63>
3. c0t3d0 <DEFAULT cyl 17830 alt 2 hd 255 sec 63>
4. c2t600144F04890703F0000144FA6CCAC00d0 <DEFAULT cyl 13051 alt 2 hd 255 sec 63>
5. c2t600144F0489070250000144FA6CCAC00d0 <DEFAULT cyl 13051 alt 2 hd 255 sec 63>
For UFS Follow the following procedure
Create file systems on iSCSI disks.
# newfs /dev/rdsk/c2t600144F04890703F0000144FA6CCAC00d0s0
# newfs /dev/rdsk/c2t600144F0489070250000144FA6CCAC00d0s0
# iscsiadm add static-config iqn.1986-03.com.sun:02:9e0b0e03-8823-eb7e-d449-f9c21930ba15,10.9.168.93
# iscsiadm add static-config iqn.1986-03.com.sun:02:2cc4fe10-c7ba-697f-d95f-fa75efe50239,10.9.168.93
Make the mount points.
# mkdir /pgdata
# mkdir /pglog
Mount the iSCSI LUNs
# mount -F ufs -o forcedirectio /dev/dsk/c2t600144F04890703F0000144FA6CCAC00d0s /pgdata
# mount -F ufs -o forcedirectio /dev/dsk/c2t600144F0489070250000144FA6CCAC00d0s0 /pglog
For ZFS Create zpool as follows:
# zpool create pgdata c2t600144F04890703F0000144FA6CCAC00d0s
# zpool create pglog c2t600144F0489070250000144FA6CCAC00d0s0
For ZFS with Read-Cache and Separate Intent Log (OpenSolaris 2008.05 and later) using local disks
# zpool create pgdata c2t600144F04890703F0000144FA6CCAC00d0s cache c0t1d0s1 log c0t1d0s0
# zpool create pglog c2t600144F0489070250000144FA6CCAC00d0s0 cache c0t2d0s1 log c0t2d0s0
Many times, UFS filesystems have “lost+found” directory which causes PostgreSQL's initdb command to fail as directory is not empty. Also major versions of database are incompatible and hence it makes sense to take a naming convention as follows and create a sub directory within /pgdata and /pglog depending on the version you are planning to use:
mkdir /pgdata/8.3 /pglog/8.3
mkdir /pgdata/8.2 /pglog/8.2
mkdir /pgdata/8.1 /pglog/8.1
Then for PostgreSQL 8.3 (Solaris 10 10/08) the step is as follows
/usr/postgres/8.3/bin/initdb -D /pgdata/8.3 -X /pglog/8.3/pg_xlog
As for 8.2 the steps are as follows:
/usr/postgres/8.2/bin/initdb -D /pgdata/8.2
mv /pgdata/8.2/pg_xlog /pglog/8.2/
ln -s /pglog/8.2/pg_xlog /pgdata/8.2/pg_xlog
And for the default 8.1 the steps are similar:
/usr/bin/initdb -D /pgdata/8.1
mv /pgdata/8.1/pg_xlog /pglog/8.1/
ln -s /pglog/8.1/pg_xlog /pgdata/8.1/pg_xlog
And then use the pg_ctl from the version of PostgreSQL being used to start and stop the server:
pg_ctl start -D /pgdata/8.3 -l /pgdata/8.3/server.log
pg_ctl stop -D /pgdata/8.3
In another blog post I will explain on how to take snapshots with PostgreSQL and the OpenStorage devices.