循序渐进PostgreSQL:实现PostgreSQL自启动
循序渐进PostgreSQL:实现PostgreSQL自启动 在手动安装(针对源码编译PG或者是解压缩版安装PG的情形)情况下,PG并不是在开机的情况下自动启动,在关机的情况下自动停止,作为DBA人员来说,显然这样的情形是无法接受的。 www.2cto.com 1. windows下的服务自启
循序渐进PostgreSQL:实现PostgreSQL自启动
在手动安装(针对源码编译PG或者是解压缩版安装PG的情形)情况下,PG并不是在开机的情况下自动启动,在关机的情况下自动停止,作为DBA人员来说,显然这样的情形是无法接受的。
www.2cto.com
1. windows下的服务自启动
在Windows下, 可以使用pg_ctl命令生成PostgreSQL服务,并让它自启动。实际上,安装版本也是这么做的。 我们不妨看看pg_ctl命令的详细帮助先:
D:\pg921>pg_ctl --help
pg_ctl is a utility to initialize, start, stop, or control a PostgreSQL server.
Usage:
pg_ctl init[db] [-D DATADIR] [-s] [-o "OPTIONS"]
pg_ctl start [-w] [-t SECS] [-D DATADIR] [-s] [-l FILENAME] [-o "OPTIONS"]
pg_ctl stop [-W] [-t SECS] [-D DATADIR] [-s] [-m SHUTDOWN-MODE]
pg_ctl restart [-w] [-t SECS] [-D DATADIR] [-s] [-m SHUTDOWN-MODE]
[-o "OPTIONS"]
pg_ctl reload [-D DATADIR] [-s]
pg_ctl status [-D DATADIR]
pg_ctl promote [-D DATADIR] [-s]
pg_ctl kill SIGNALNAME PID
pg_ctl register [-N SERVICENAME] [-U USERNAME] [-P PASSWORD] [-D DATADIR]
[-S START-TYPE] [-w] [-t SECS] [-o "OPTIONS"]
pg_ctl unregister [-N SERVICENAME]
Common options:
-D, --pgdata=DATADIR location of the database storage area
-s, --silent only print errors, no informational messages
-t, --timeout=SECS seconds to wait when using -w option
-V, --version output version information, then exit
-w wait until operation completes
-W do not wait until operation completes
-?, --help show this help, then exit
(The default is to wait for shutdown, but not for start or restart.)
If the -D option is omitted, the environment variable PGDATA is used.
Options for start or restart:
-c, --core-files not applicable on this platform
-l, --log=FILENAME write (or append) server log to FILENAME
-o OPTIONS command line options to pass to postgres
(PostgreSQL server executable) or initdb
-p PATH-TO-POSTGRES normally not necessary
Options for stop or restart:
-m, --mode=MODE MODE can be "smart", "fast", or "immediate"
Shutdown modes are:
smart quit after all clients have disconnected
fast quit directly, with proper shutdown
immediate quit without complete shutdown; will lead to recovery on restart
Allowed signal names for kill:
ABRT HUP INT QUIT TERM USR1 USR2
Options for register and unregister:
-N SERVICENAME service name with which to register PostgreSQL server
-P PASSWORD password of account to register PostgreSQL server
-U USERNAME user name of account to register PostgreSQL server
-S START-TYPE service start type to register PostgreSQL server
Start types are:
auto start service automatically during system startup (default)
demand start service on demand
Report bugs to
从上边可以看出,pg_ctl register用于生成服务,而pg_ctl unregister -N 用于删除一个服务。
如:
D:\pg921>pg_ctl register -N pg921 -D d:\pg921\data -S auto -w -t 10 -l d:/pg921/log/pg921.log -o "-p 5433"
此命令,即是要生成一个服务:pg921, 启动方式: -S auto, 自启动,如果想生成手动启动,就用-S demand来指定。
-t 10,意指等待10秒钟, 实际上可以设定的长一些(在生产环境中).
-l d:/pg921/log/pg921.log, 指定生成的日志文件的位置。
-o "-p 5433", 将服务端口号改为5433。
验证一下上述命令生成的效果:
D:\pg921>net start pg921
The pg921 service is starting.
The pg921 service was started successfully.
D:\pg921>psql -p 5433 iihero
psql (9.2.1)
Type "help" for help.
iihero=# \q
2. Linux下的服务自启动
在Linux下,我们需要写一个自启动的脚本,至少支持两个命令选项: start 和 stop,并将这个脚本建立适当的链接。我们就以Ubuntu10为例,
先看看系统有没有chkconfig命令工具: www.2cto.com
xionghe@seanlinux2:~$ chkconfig
程序“chkconfig”尚未安装。 您可以使用以下命令安装:
sudo apt-get install chkconfig
xionghe@seanlinux2:~$ sudo apt-get install chkconfig
脚本内容如下: 放入目录/etc/init.d目录下边
#! /bin/sh
# Installation prefix
prefix=/home/xionghe/pgsql
# Data directory
PGDATA="/home/xionghe/pgsql/data"
# Who to run the postmaster as, usually "postgres". (NOT "root")
PGUSER=xionghe
# Where to keep a log file
PGLOG="$PGDATA/serverlog"
# It's often a good idea to protect the postmaster from being killed by the
# OOM killer (which will tend to preferentially kill the postmaster because
# of the way it accounts for shared memory). Setting the OOM_ADJ value to
# -17 will disable OOM kill altogether. If you enable this, you probably want
# to compile PostgreSQL with "-DLINUX_OOM_ADJ=0", so that individual backends
# can still be killed by the OOM killer.
#OOM_ADJ=-17
## STOP EDITING HERE
# The path that is to be used for the script
PATH=/home/xionghe/pgsql/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# What to use to start up the postmaster. (If you want the script to wait
# until the server has started, you could use "pg_ctl start -w" here.
# But without -w, pg_ctl adds no value.)
DAEMON="$prefix/bin/postmaster"
# What to use to shut down the postmaster
PGCTL="$prefix/bin/pg_ctl"
set -e
# Only start if we can find the postmaster.
test -x $DAEMON ||
{
echo "$DAEMON not found"
if [ "$1" = "stop" ]
then exit 0
else exit 5
fi
}
# Parse command line parameters.
case $1 in
start)
echo -n "Starting PostgreSQL: "
test x"$OOM_ADJ" != x && echo "$OOM_ADJ" > /proc/self/oom_adj
su - $PGUSER -c "$DAEMON -D '$PGDATA' &" >>$PGLOG 2>&1
echo "ok"
;;
stop)
echo -n "Stopping PostgreSQL: "
su - $PGUSER -c "$PGCTL stop -D '$PGDATA' -s -m fast"
echo "ok"
;;
restart)
echo -n "Restarting PostgreSQL: "
su - $PGUSER -c "$PGCTL stop -D '$PGDATA' -s -m fast -w"
test x"$OOM_ADJ" != x && echo "$OOM_ADJ" > /proc/self/oom_adj
su - $PGUSER -c "$DAEMON -D '$PGDATA' &" >>$PGLOG 2>&1
echo "ok"
;;
reload)
echo -n "Reload PostgreSQL: "
su - $PGUSER -c "$PGCTL reload -D '$PGDATA' -s"
echo "ok"
;;
status)
su - $PGUSER -c "$PGCTL status -D '$PGDATA'"
;;
*)
# Print help
echo "Usage: $0 {start|stop|restart|reload|status}" 1>&2
exit 1
;;
esac
exit 0
建立相应链接:
root@seanlinux2:/etc# ln -s /etc/init.d/postgresql /etc/rc0.d/K02postgresql
root@seanlinux2:/etc# ln -s /etc/init.d/postgresql /etc/rc1.d/K02postgresql
root@seanlinux2:/etc# ln -s /etc/init.d/postgresql /etc/rc2.d/K02postgresql
root@seanlinux2:/etc# ln -s /etc/init.d/postgresql /etc/rc3.d/K98postgresql
root@seanlinux2:/etc# ln -s /etc/init.d/postgresql /etc/rc4.d/K98postgresql
root@seanlinux2:/etc# ln -s /etc/init.d/postgresql /etc/rc5.d/K98postgresql

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

wps是使用非常广泛的办公软件,包括了文档、表格和PPT,且支持多端同步。如果在编辑wps时出现提示“不能启动此对象的源应用程序”,要如何解决?出现这个问题可能是因为你正在尝试打开一个链接或文件,但是它的源应用程序已经不存在或者被删除了。 以下是一些修复方法: 1、重新安装WPS软件:尝试重装WPSOffice来修复该问题,确保您使用的是最新版本。 2、手动更改默认程序:试着将默认程序更改为WPS,可以按右键单击需要打开的文件,选择“打开方式”,然

华为手机如何实现双微信登录?随着社交媒体的兴起,微信已经成为人们日常生活中不可或缺的沟通工具之一。然而,许多人可能会遇到一个问题:在同一部手机上同时登录多个微信账号。对于华为手机用户来说,实现双微信登录并不困难,本文将介绍华为手机如何实现双微信登录的方法。首先,华为手机自带的EMUI系统提供了一个很便利的功能——应用双开。通过应用双开功能,用户可以在手机上同

wallpaperengine启动时,有4种不同的选项,有很多用户不知道wallpaperengine启动选哪一个,一般wallpaperengine启动时选择第一个:启动32位即可。wallpaperengine启动选哪一个答:启动32位。1、一般wallpaperengine启动时选择第一个:启动32位即可。2、wallpaperengine启动时,有4种不同的选项:启动32位;启动64位。3、启动32位:这是一般推荐的选项,适用于大多数用户。4、启动64位:如果系统支持64位,可以选择此选

随着科技的不断发展,使用不同操作系统的需求也越来越普遍。对于苹果用户来说,有时可能需要在一台设备上安装并使用两个不同的操作系统,如macOS和Windows。在这种情况下,设置双系统的启动顺序就显得尤为重要。本文将介绍如何设置苹果设备在开机时优先启动双系统。首先,我们需要确保已经在苹果设备上成功安装了两个操作系统。你可以使用BootCamp这个苹

如何在华为手机上实现微信分身功能随着社交软件的普及和人们对隐私安全的日益重视,微信分身功能逐渐成为人们关注的焦点。微信分身功能可以帮助用户在同一台手机上同时登录多个微信账号,方便管理和使用。在华为手机上实现微信分身功能并不困难,只需要按照以下步骤操作即可。第一步:确保手机系统版本和微信版本符合要求首先,确保你的华为手机系统版本已更新到最新版本,以及微信App

编程语言PHP是一种用于Web开发的强大工具,能够支持多种不同的编程逻辑和算法。其中,实现斐波那契数列是一个常见且经典的编程问题。在这篇文章中,将介绍如何使用PHP编程语言来实现斐波那契数列的方法,并附上具体的代码示例。斐波那契数列是一个数学上的序列,其定义如下:数列的第一个和第二个元素为1,从第三个元素开始,每个元素的值等于前两个元素的和。数列的前几个元

在当今的软件开发领域中,Golang(Go语言)作为一种高效、简洁、并发性强的编程语言,越来越受到开发者的青睐。其丰富的标准库和高效的并发特性使它成为游戏开发领域的一个备受关注的选择。本文将探讨如何利用Golang来实现游戏开发,并通过具体的代码示例来展示其强大的可能性。1.Golang在游戏开发中的优势作为一种静态类型语言,Golang在构建大型游戏系统

PHP游戏需求实现指南随着互联网的普及和发展,网页游戏的市场也越来越火爆。许多开发者希望利用PHP语言来开发自己的网页游戏,而实现游戏需求是其中一个关键步骤。本文将介绍如何利用PHP语言来实现常见的游戏需求,并提供具体的代码示例。1.创建游戏角色在网页游戏中,游戏角色是非常重要的元素。我们需要定义游戏角色的属性,比如姓名、等级、经验值等,并提供方法来操作这些
