Кстати, не забудьте поменять (назначить) пароль пользователя postgres командой passwd
Создание каталога для данных PostgreSQL
Каталог, в котором будут размещаться данные PostgreSQL может находиться в произвольно выбранной файловой системе. В производственной среде при выборе каталога нужно исходить из соображений доступности, призводительности и безопасности. Мы же осуществляем просто базовую настройку, поэтому и будем использовать каталог по умолчанию.
Каталог по умолчанию для данных размещен в /var/lib/pgsql/data. Отдадим его во
владение пользователю postgres и выставим правильные права доступа:
Для тестирования соединения с БД, названной postgres выполним следующую команду:
$ psql postgres
Интеграция с Service Management Facility (SMF)
PostgreSQL может быть интегрирована в Solaris Service Management Facility -
механизм управления сервисами Solaris. Для этого необходимо создать файл
манифеста (в формате XML) для импорта описания сервиса и его активизации,
а также shell-скрипт для управления сервисом.
Следующие даействия должны быть выполнены пользователем root.
Файл манифеста PostgreSQL.xml
Файл манифеста должен иметь следующий вид:
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1"> <!-- Copyright 2006 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.
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
ident "%Z%%M% %I% %E SMI"
NOTE: This service manifest is not editable; its contents will be overwritten by package or patch operations, including operating system upgrade. Make customizations in a different file. -->
<!-- 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>
<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> </instance>
Назовите этот файл PostgreSQL.xml и поместите его в каталог /var/svc/manifest/application/database.
Если этого каталога не существует - нужно создать его.
Управляющий скрипт 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. All rights reserved.
# Use is subject to license terms.
#
# ident "%Z%%M% %I% %E SMI"
. /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
Файл нужно поместить в каталог /lib/svc/method и выставить разрешения на него 555.
Импортирование манифеста
Теперь нужно импортировать файл манифеста PostgreSQL.xml в систему SMF
# cd /var/svc/manifest/application/database
# /usr/sbin/svccfg import PostgreSQL.xml
После импорта сервис PostgreSQL запрещен. Статус сервиса можно посмотреть выполнив команду
Полное наименование сервиса и идентификатор ресурса (fault management resource identifier (FMRI))
svc:/application/database/PostgreSQL:default и svc:/application/database/PostgreSQL:postgres соответственно.
Но информацию о них можно получить по короткому имени.
Разрешение и старт сервиса
Разрешим выполнение сервиса и, соответственно, стартуем его командой
Теперь при загрузке сервера автоматически будет запускаться служба сервера PostgreSQL.
Более того, если сервис по какой-то причине аварийно завершится, то SMF рестартует его.
Дополнительные возможности SMF
Механизм SMF позволяет динамически изменять параметры выполнения сервиса, например,
запретить или разрешить сервис, поменять каталог БД, поменять пользователя или
какое-либо другое свойство сервиса.
Пример смены пользователя, под которым запускается сервис на пользователя foo: