Postgresql On Solaris 10: Solaris™ 10 How To Guides
Postgresql On Solaris 10: Solaris™ 10 How To Guides
POSTGRESQL ON SOLARIS 10
TM
Contents
PostgreSQL for Solaris: Overview Starting PostgreSQL for the First Time Integrate PostgreSQL with Solaris Service Management Facility Configuring and Running PostgreSQL in Solaris Zones
Installing a Solaris Zone Creating, Installing and Booting a Zone Run PostgreSQL in Solaris Zone Mount filesystem in Zone
Page 10
Page 10 Page 10
Installing PostgreSQL on Earlier Versions of Solaris 10 Package File Locations Installing PostgreSQL for Solaris Packages Installing Solaris Patches Removing Solaris Patches Summary For More Information
1
Solaris 10 Operating System sun.com/solaris
2
Solaris 10 Operating System sun.com/solaris
4.
PostgreSQL is now ready to be started using the following command: $ pg_ctl -D /var/lib/pgsql/data -l postmaster.log start
5.
You can now test the running database. To connect to a database called postgres running on a default port, execute the following command: $ psql postgres
To configure the database, modify the postgresql.conf file in the database cluster directory used in step 3. For tuning tips on Solaris, visit http://www.sun.com/servers/coolthreads/tnb/applications_postgresql.jsp.
3
Solaris 10 Operating System sun.com/solaris
file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] CDDL HEADER END ident NOTE: "%Z%%M% %I% %E SMI"
This service manifest is not editable; its contents will Make customizations in a different
be overwritten by package or patch operations, including operating system upgrade. file. --> <service_bundle type='manifest' name='postgresql'> <service name='application/database/postgresql' type='service' version='1'> <!-Wait for network interfaces to be initialized. --> <dependency name='network' grouping='require_all' restart_on='none' type='service'> <service_fmri value='svc:/milestone/network:default' /> </dependency> <!-Wait for all local filesystems to be mounted. --> <dependency name='filesystem-local' grouping='require_all' restart_on='none' type='service'> <service_fmri value='svc:/system/filesystem/local:default' /> </dependency> <exec_method type='method' name='start' exec='/lib/svc/method/postgresql start' timeout_seconds='300' />
4
Solaris 10 Operating System sun.com/solaris
<exec_method type='method' name='stop' exec='/lib/svc/method/postgresql stop' timeout_seconds='300' /> <exec_method type='method' name='refresh' exec='/lib/svc/method/postgresql refresh' timeout_seconds='60' /> <!-We define two instances of PostgreSQL as examples. --> <instance name='default' enabled='false'> <method_context> <method_credential user='postgres' group='postgres' /> </method_context> <!-Make sure the data configurable property points to the appropriate database directory. --> <property_group name='postgresql' type='application'> <propval name='data' type='astring' value='/var/lib/pgsql/data' /> <propval name='log' type='astring' value='postmaster.log' /> </property_group> </instance> <instance name='postgres' enabled='false'> <method_context> <method_credential user='postgres' group='postgres' /> </method_context> <!-Make sure the data configurable property points to the appropriate database directory and port number in postgresql.conf is different than the first instance. --> <property_group name='postgresql' type='application'> <propval name='data' type='astring' value='/var/lib/pgsql/data2' /> <propval name='log' type='astring' value='postmaster.log' /> </property_group>
5
Solaris 10 Operating System sun.com/solaris
</instance> <stability value='Evolving' /> <template> <common_name> <loctext xml:lang='C'> PostgreSQL RDBMS </loctext> </common_name> <documentation> <manpage title='postgres' section='1M' /> <doc_link name='postgresql.org' uri='http://postgresql.org' /> </documentation> </template> </service> </service_bundle> The default instance of the manifest assumes that the database user is postgres, database cluster directory is /var/lib/pgsql/data and the postmaster log file is postmaster.log. If any of them is different, update the above XML accordingly or use the svccfg command to change this property after the manifest has been imported. See the examples below. 2. Save the following shell script to a file called postgresql. #!/sbin/sh # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # Copyright 2006 Sun Microsystems, Inc. # Use is subject to license terms. # # ident "%Z%%M% %I% %E SMI" All rights reserved.
6
Solaris 10 Operating System sun.com/solaris
. /lib/svc/share/smf_include.sh # SMF_FMRI is the name of the target service. This allows multiple instances # to use the same script. getproparg() { val=`svcprop -p $1 $SMF_FMRI` [ -n "$val" ] && echo $val } PGBIN=/usr/bin PGDATA=`getproparg postgresql/data` PGLOG=`getproparg postgresql/log` if [ -z $SMF_FMRI ]; then echo "SMF framework variables are not initialized." exit $SMF_EXIT_ERR fi if [ -z $PGDATA ]; then echo "postgresql/data property not set" exit $SMF_EXIT_ERR_CONFIG fi if [ -z $PGLOG ]; then echo "postgresql/log property not set" exit $SMF_EXIT_ERR_CONFIG fi case "$1" in 'start') $PGBIN/pg_ctl -D $PGDATA -l $PGDATA/$PGLOG start ;; 'stop') $PGBIN/pg_ctl -D $PGDATA stop ;; 'refresh') $PGBIN/pg_ctl -D $PGDATA reload ;; *) echo $"Usage: $0 {start|refresh}" exit 1 ;; esac exit $SMF_EXIT_OK
7
Solaris 10 Operating System sun.com/solaris
3. 4. 5.
Place the shell script postgresql in /lib/svc/method. Change the permission to 555. You need to have the appropriate write privileges to copy files into this directory. Import the SMF manifest by executing the following commands: # cd /var/svc/manifest/application/database # /usr/sbin/svccfg import postgresql.xml
6.
Initially both service instances are disabled. Use the following command to see the state. Note: The full service name or fault management resource identifier (FMRI) for both instances are svc:/application/database/postgresql:default and svc:/application/database/postgresql:postgres respectively, but they can be shortened to postgresql:default and postgresql:postgres: # svcs postgresql
7.
Start the service (e.g start PostgreSQL) for the default instance by executing the following command: # /usr/sbin/svcadm enable postgresql:default From this point on the PostgreSQL process is controlled by the Solaris SMF, and the administrator can change its state by using the svcadm command. If the service is terminated for some reason, the SMF restarter daemon will attempt to restart it, and at system reboot the service will be started automatically unless it is disabled. It is possible to change any of the configurable properties (user, data, or log) in postgresql.xml dynamically after the manifest has been imported. To do so, you need to (a) disable the service, (b) change the property value and refresh it, and (c) restart the service. Below are two examples for changing the administrative user and data directory. To change the Solaris administrative user to foo for the default instance, execute: # # # # svcadm svccfg svcadm svcadm disable postgresql:default -s postgresql:default setprop method_context/user = "foo" refresh postgresql:default enable postgresql:default
To change the database cluster directory to /pgdata for the default instance, execute: # # # # svcadm svccfg svcadm svcadm disable postgresql:default -s postgresql:default setprop postgresql/data = "/pgdata" refresh postgresql:default enable postgresql:default
For more details on how to use SMF, please read the smf(5) man page or online documentation at http://docs.sun.com/app/docs/doc/817-1985/6mhm8o5rh?a=view.
8
Solaris 10 Operating System sun.com/solaris
9
Solaris 10 Operating System sun.com/solaris
zone. You are now in the zonecfg shell that is identified by its prompt:"zonecfg:email-zone>". 2. Configuring the zone by executing the following commands: zonecfg:pg_zone> create zonecfg:pg_zone> set zonepath=/export/zones/pg_zone zonecfg:pg_zone> set autoboot=true zonecfg:pg_zone> add net zonecfg:pg_zone:net> set address=10.6.222.74/24 zonecfg:pg_zone:net> set physical=ipge0 zonecfg:pg_zone:net> end zonecfg:pg_zone> verify zonecfg:pg_zone> commit zonecfg:pg_zone> exit Note: Change address and physical to the appropriate IP address and name of interface card, respectively. At this point a zone configuration file is created in /etc/zones/pg_zone.xml 3. Install the zone using the following command: global# zoneadm -z pg_zone install
This can take a few minutes. 4. When installation completes, use the following command to list the status of the installed zones: global# zoneadm list -iv
5.
Booting a zone places the zone in the running state. A zone can be booted from the installed state or from the ready state using the following command: global# zoneadm -z pg_zone boot
6.
Use the following command to log onto the Zone console: global# zlogin -C pg_zone The first time you log in to the console, you are prompted to answer a series of questions.
At this point the newly created zone is ready to use. You can proceed to setup PostgreSQL in the zone.
10
Solaris 10 Operating System sun.com/solaris
Change the properties special, raw, and dir appropriately for your environment.
SUNWpostgr
SUNWpostgr-contrib
SUNWpostgr-devel
SUNWpostgr-docs
11
Solaris 10 Operating System sun.com/solaris
Package SUNWpostgr-server
Description The SUNWpostgr-server package includes the programs needed to create and run a PostgreSQL server, which will in turn allow you to create and maintain PostgreSQL databases. You should install SUNWpostgr-server if you want to create and maintain your own PostgreSQL databases and/or your own PostgreSQL server. You also need to install the SUNWpostgr package and its requirements. The SUNWpostgr-server-data package creates the default data directories and may contain demo database. The SUNWpostgr-tcl package contains the Pgtcl client library and its documentation. The SUNWpostgr-jdbc package includes the .jar files needed for Java programs to access a PostgreSQL database. The SUNWpostgr-pl package contains the the PL/Perl, and PL/Python procedural languages for the backend. PL/Pgsql is part of the core server package.
SUNWpostgr-server-data
SUNWpostgr-tcl
SUNWpostgr-jdbc
SUNWpostgr-pl
12
Solaris 10 Operating System sun.com/solaris
13
Solaris 10 Operating System sun.com/solaris
1. 2.
Download the patch, unzip and untar it into any directory (e.g. /var/tmp). Add the patch to the system. You must have root privileges to add a patch: # patchadd /var/tmp/121606-01 The above command will take a few minutes, so be patient. After the patch is installed successfully, you can proceed to use PL/Python. Note: If you encounter patchadd or patchrm problems, such as "wordlist too large" messages while installing this patch, you may need to install the following patch: 119254-02 (or newer) Install and Patch Utilities Patch
Summary
Fully integrated into Solaris 10 with flexible support offerings from Sun, PostgreSQL on Solaris 10 is an enterprise-class open source database. When combined with the reliable, stable Solaris Operating System, customers can use PostgreSQL for a majority of the commercial database needs. Customers now have the additional reassurance of world-class, global 24x7 support from Sun.
14
Solaris 10 Operating System sun.com/solaris
Solaris 10 Overview Solaris 10 FAQ Solaris 10 Datasheets and Resources Additional Solaris How to Guides Predictive Self-Healing Feature Information
PostgreSQL for Solaris Reference Materials
PostgreSQL for Solaris Service & Support Offering PostgreSQL for Solaris Web site
Community Resources
sun.com/service/osdb/index.xml sun.com/solaris/postgresql
PostgreSQL Documentation PostgreSQL for Solaris documentation PostgreSQL Packages for Solaris
15
Solaris 10 Operating System sun.com/solaris
sun.com/solaris
Sun Microsystems, Inc. 4150 Network Circle, Santa Clara, CA 95054 USA Phone 1-650-960-1300 or 1-800-555-9SUN Web sun.com
2005 Sun Microsystems, Inc. All rights reserved. Sun, Sun Microsystems, the Sun logo and Solaris are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries.