免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1464 | 回复: 0

solaris10安装postgresql9(SMF) [复制链接]

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
发表于 2011-12-19 13:55 |显示全部楼层
1.下载 postgresql
http://www.postgresql.org/ftp/binary/v9.0.0/solaris/solaris10/i386/

2.解压安装
cat /etc/passwd,检查是否已有postgres用户(默认已建好)
usermod -d /export/home/postgres postgres

groupadd -g 90 postgres
useradd -u 90 -g postgres -d /export/home/postgres -s /usr/bin/bash postgres
passwd postgres
密码设为:post
cd /export/home
bzcat /export/home/feifan/soft/postgresql-9.0.3-S10.i386-32.tar.bz2 | tar -xvf -

3.配制环境变量
#su - postgres
.profile
  1. PGLIB=$HOME/pgsql/lib;export PGLIB
  2. PGDATA=$HOME/data;export PGDATA
  3. PATH=$PATH:$HOME/pgsql/bin;export PATH
  4. umask 022
4.初始化数据库
#su - postgres
$ln -s 9.0-pgdg pgsql
$cd pgsql/bin
$ ./initdb --encoding=utf8 -D $PGDATA
  1. The files belonging to this database system will be owned by user "postgres".
  2. This user must also own the server process.

  3. The database cluster will be initialized with locale C.
  4. The default text search configuration will be set to "english".

  5. creating directory /export/home/postgres/data ... ok
  6. creating subdirectories ... ok
  7. selecting default max_connections ... 100
  8. selecting default shared_buffers ... 32MB
  9. creating configuration files ... ok
  10. creating template1 database in /export/home/postgres/data/base/1 ... ok
  11. initializing pg_authid ... ok
  12. initializing dependencies ... ok
  13. creating system views ... ok
  14. loading system objects' descriptions ... ok
  15. creating conversions ... ok
  16. creating dictionaries ... ok
  17. setting privileges on built-in objects ... ok
  18. creating information schema ... ok
  19. loading PL/pgSQL server-side language ... ok
  20. vacuuming database template1 ... ok
  21. copying template1 to template0 ... ok
  22. copying template1 to postgres ... ok

  23. WARNING: enabling "trust" authentication for local connections
  24. You can change this by editing pg_hba.conf or using the -A option the
  25. next time you run initdb.

  26. Success. You can now start the database server using:

  27. ./postgres -D /export/home/postgres/data
  28. or
  29. ./pg_ctl -D /export/home/postgres/data -l logfile start


  30. cd /export/home/postgres/pgsql/bin
  31. ./pg_ctl -D $PGDATA -l $PGDATA/pg_log start
5.启动脚本
vi /lib/svc/method/postgres

  1. #!/sbin/sh
  2. #
  3. # Copyright 2008 Sun Microsystems, Inc. All rights reserved.
  4. # Use is subject to license terms.
  5. #
  6. #ident "@(#)postgresql 9.0.3 2011/02/15 SMI"

  7. . /lib/svc/share/smf_include.sh

  8. # SMF_FMRI is the name of the target service. This allows multiple instances
  9. # to use the same script.

  10. getproparg() {
  11.         val=`svcprop -p $1 $SMF_FMRI`
  12.         [ -n "$val" ] && echo $val
  13. }

  14. check_data_dir() {
  15.         if [ ! -d $PGDATA ]; then
  16.                 echo "Error: postgresql/data directory $PGDATA does not exist"
  17.                 exit $SMF_EXIT_ERR_CONFIG
  18.         fi

  19.         if [ ! -w $PGDATA ]; then
  20.                 echo "Error: postgresql/data directory $PGDATA is not writable by postgres"
  21.                 exit $SMF_EXIT_ERR_CONFIG
  22.         fi

  23.         if [ ! -d $PGDATA/base -o ! -d $PGDATA/global -o ! -f $PGDATA/PG_VERSION ]; then
  24.                 # If the directory is empty we can create the database files
  25.                 # on behalf of the user using initdb
  26.                 if [ `ls -a $PGDATA | wc -w` -le 2 ]; then
  27.                         echo "Notice: postgresql/data directory $PGDATA is empty"
  28.                         echo "Calling '$PGBIN/initdb -D $PGDATA' to initialize"

  29.                         $PGBIN/initdb -D $PGDATA
  30.                         if [ $? -ne 0 ]; then
  31.                                 echo "Error: initdb failed"
  32.                                 exit $SMF_EXIT_ERR
  33.                         fi
  34.                 else
  35.                         echo "Error: postgresql/data directory $PGDATA is not empty, nor is it a valid PostgreSQL data directory"
  36.                         exit $SMF_EXIT_ERR_CONFIG
  37.                 fi
  38.         fi
  39. }

  40. PGBIN=`getproparg postgresql/bin`
  41. PGDATA=`getproparg postgresql/data`
  42. PGLOG=`getproparg postgresql/log`

  43. if [ -z $SMF_FMRI ]; then
  44.         echo "Error: SMF framework variables are not initialized"
  45.         exit $SMF_EXIT_ERR
  46. fi

  47. if [ -z $PGDATA ]; then
  48.         echo "Error: postgresql/data property not set"
  49.         exit $SMF_EXIT_ERR_CONFIG
  50. fi

  51. if [ -z $PGLOG ]; then
  52.         echo "Error: postgresql/log property not set"
  53.         exit $SMF_EXIT_ERR_CONFIG
  54. fi

  55. case "$1" in
  56. 'start')
  57.         check_data_dir
  58.         $PGBIN/pg_ctl -D $PGDATA -l $PGDATA/$PGLOG start
  59.         ;;

  60. 'stop')
  61.         $PGBIN/pg_ctl -D $PGDATA stop
  62.         ;;

  63. 'refresh')
  64.         $PGBIN/pg_ctl -D $PGDATA reload
  65.         ;;

  66. *)
  67.         echo "Usage: $0 {start|stop|refresh}"
  68.         exit 1
  69.         ;;

  70. esac
  71. exit $SMF_EXIT_OK
chown root:bin /lib/svc/method/postgres
chmod 555 /lib/svc/method/postgres

6.加入SMF
mkdir /var/svc/manifest/application/database
cd /var/svc/manifest/application/database
vi postgresql.xml

  1. <?xml version="1.0"?>
  2. <!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
  3. <!--
  4.         ident "@(#)postgresql.xml 9.0.3 11/02/15 SMI"
  5.         By feifan@CU
  6. -->

  7. <service_bundle type='manifest' name='postgresql'>

  8. <service
  9.         name='application/database/postgresql'
  10.         type='service'
  11.         version='1'>   

  12.         <!--
  13.            Wait for all local filesystems to be mounted.
  14.         -->
  15.         <dependency
  16.                 name='filesystem-local'
  17.                 grouping='require_all'
  18.                 restart_on='none'
  19.                 type='service'>
  20.                 <service_fmri value='svc:/system/filesystem/local:default' />
  21.         </dependency>

        <!--
           Wait for network loopback to be initialized.
        -->
        <dependency
                name='loopback'
                grouping='require_all'
                restart_on='none'
                type='service'>
                <service_fmri value='svc:/network/loopback' />
        </dependency>

  1.         <exec_method
  2.                 type='method'
  3.                 name='start'
  4.                 exec='/lib/svc/method/postgres start'
  5.                 timeout_seconds='200' />

  6.         <exec_method
  7.                 type='method'
  8.                 name='stop'
  9.                 exec='/lib/svc/method/postgres stop'
  10.                 timeout_seconds='200' />

  11.         <exec_method
  12.                 type='method'
  13.                 name='refresh'
  14.                 exec='/lib/svc/method/postgres refresh'
  15.                 timeout_seconds='60' />

  16.         <property_group name='general' type='framework'>
  17.                 <propval name='value_authorization' type='astring'
  18.                         value='solaris.smf.value.postgres' />
  19.                 <propval name='action_authorization' type='astring'
  20.                         value='solaris.smf.manage.postgres' />
  21.         </property_group>

  22.         <instance name='pgsql_32bit' enabled='false'>

  23.                 <method_context>
  24.                         <method_credential user='postgres' group='postgres' />
  25.                 </method_context>

  26.                 <property_group name='postgresql' type='application'>
  27.                         <propval name='bin' type='astring' value='/export/home/postgres/pgsql/bin' />
  28.                         <propval name='data' type='astring' value='/export/home/postgres/data' />
  29.                         <propval name='log' type='astring' value='postmaster.log' />
  30.                         <propval name='value_authorization' type='astring' value='solaris.smf.value.postgres' />
  31.                 </property_group>

  32.         </instance>

  33.         <stability value='Evolving' />

  34.         <template>
  35.                 <common_name>
  36.                         <loctext xml:lang='C'>
  37.                                 PostgreSQL RDBMS
  38.                         </loctext>
  39.                 </common_name>
  40.                 <documentation>
  41.                         <manpage title='postgres' section='5' />
  42.                         <doc_link name='postgresql.org'
  43.                                 uri='http://postgresql.org' />
  44.                 </documentation>
  45.         </template>

  46. </service>
  47. </service_bundle>

chown root:sys /var/svc/manifest/application/database/postgresql.xml
chmod 444 /var/svc/manifest/application/database/postgresql.xml
#检查文件格式
svccfg -v validate postgresql.xml
#导入smf数据库
svccfg -v import postgresql.xml

#启动
svcadm enable postgresql

7.修改配制(重启应用生效)
#postgresql.conf
vi $PGDATA/postgresql.conf
修改
  1. listen_addresses = '*'


#pg_hba.conf
添加
  1. host mdcpg mdcts 192.168.195.0/24 md5


数据库部分
1.创建角色(用户)
创建角色ftp,不允许此角色创建其他角色,不允许此角色创建数据库;不允许此角色创建角色,角色不是超级用户
  1. createuser -D -R -S -P ftp
注:程序 createuser 和 dropuser 提供了对了CREATE ROLE和DROP ROLE SQL 命令的封装,createuser命令默认用户具有login权限,create role没有,需指定

  1. postgres=# create role mdcts login password 'mdc';
2.建表空间
  1. postgres=# create tablespace mdc_data owner mdcts location '/export/home/postgres/data/pg_tblspc';
3.建库
  1. postgres=# create database mdcpg owner=mdcts tablespace mdc_data;

4.建模式--模式(schema)是对数据库(database)逻辑分割
用mdcts用户登录建schema
  1. mdcpg=> create schema mdcts authorization mdcts;

选项 AUTHORIZATION:
1、当创建SCHEMA时,可以包含创建对象的子命令,这个命令是分离的,和你先建SCHEMA,后建对象是一样的效果;
2、如果有指定AUTHORIZATION user_name,所有创建的对象(包括子命令的对象)都属于user_name, 否则属于执行该语句的用户


参考文档
819-5150.pdf
solaris-smf-manifest-wp-167902.pdf
PostgreSQL-9-Admin-Cookbook.pdf

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP