cari
Rumahpangkalan datatutorial mysql循序渐进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

Kenyataan
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
MySQL和PostgreSQL:在Web开发中的最佳实践MySQL和PostgreSQL:在Web开发中的最佳实践Jul 14, 2023 pm 02:34 PM

MySQL和PostgreSQL:在Web开发中的最佳实践引言:在现代的Web开发领域中,数据库是必不可少的组成部分。在选择数据库时,常见的选择是MySQL和PostgreSQL。本文将介绍在Web开发中使用MySQL和PostgreSQL的最佳实践,并提供一些代码示例。一、适用场景MySQL适用于大多数Web应用程序,特别是那些需要高性能、可扩展性和易于使

MySQL和PostgreSQL:性能对比与优化技巧MySQL和PostgreSQL:性能对比与优化技巧Jul 13, 2023 pm 03:33 PM

MySQL和PostgreSQL:性能对比与优化技巧在开发web应用程序时,数据库是不可或缺的组成部分。而在选择数据库管理系统时,MySQL和PostgreSQL是两个常见的选择。他们都是开源的关系型数据库管理系统(RDBMS),但在性能和优化方面有一些不同之处。本文将比较MySQL和PostgreSQL的性能,并提供一些优化技巧。性能对比在比较两个数据库管

学习Go语言中的数据库函数并实现PostgreSQL数据的增删改查操作学习Go语言中的数据库函数并实现PostgreSQL数据的增删改查操作Jul 31, 2023 pm 12:54 PM

学习Go语言中的数据库函数并实现PostgreSQL数据的增删改查操作在现代的软件开发中,数据库是不可或缺的一部分。Go语言作为一门强大的编程语言,提供了丰富的数据库操作函数和工具包,可以轻松地实现数据库的增删改查操作。本文将介绍如何学习Go语言中的数据库函数,并使用PostgreSQL数据库进行实际的操作。第一步:安装数据库驱动程序在Go语言中,每个数据库

MySQL和PostgreSQL:数据安全与备份策略MySQL和PostgreSQL:数据安全与备份策略Jul 13, 2023 pm 03:31 PM

MySQL和PostgreSQL:数据安全与备份策略引言:在现代社会中,数据成为了企业和个人生活中不可或缺的一部分。对于数据库管理系统来说,数据安全与备份策略是至关重要的,既能保护数据免受丢失或损坏,也能确保恢复数据的可靠性和完整性。本文将重点讨论MySQL和PostgreSQL两种主流关系型数据库系统的数据安全性和备份策略。一、数据安全性方面:(一)用户权

在Go语言中使用PostgreSQL:完整指南在Go语言中使用PostgreSQL:完整指南Jun 18, 2023 am 09:28 AM

Go语言是一种快速、高效的编程语言,适合构建Web服务和后端应用程序。而PostgreSQL是一个开源的关系型数据库管理系统,承诺提供更高的可靠性、可扩展性和数据安全性。在本文中,我们将深入探讨如何在Go语言中使用PostgreSQL,并提供一些实用的代码示例和技巧。安装和设置PostgreSQL首先,我们需要安装和设置PostgreSQL。可以在官方网

如何在PHP编程中使用PostgreSQL数据库?如何在PHP编程中使用PostgreSQL数据库?Jun 12, 2023 am 09:27 AM

随着数据库技术的发展,数据库管理系统也呈现出多种多样的选择,开发人员可以根据自己的需求和喜好选择最适合自己的数据库。而PostgreSQL作为一种先进的开源关系型数据库系统,越来越受到开发人员的关注和使用。那么,在PHP编程中如何使用PostgreSQL数据库呢?一、安装和配置PostgreSQL数据库在使用PostgreSQL之前,需要先安装和配置它。首先

PHP实现开源PostgreSQL关系型数据库PHP实现开源PostgreSQL关系型数据库Jun 18, 2023 am 08:40 AM

随着互联网的发展,数据量持续增长,数据管理的需求变得日益迫切。关系型数据库是数据管理的一种重要方式,而其中的PostgreSQL因其灵活性、可扩展性及安全性而备受欢迎。本文介绍了如何利用PHP语言实现一个开源的PostgreSQL关系型数据库,希望对有相应需求的开发者有所帮助。概述PostgreSQL是一种强大的关系型数据库系统,它是遵循SQL标准的且具有许

数据库容量规划和扩展:MySQL vs. PostgreSQL数据库容量规划和扩展:MySQL vs. PostgreSQLJul 12, 2023 pm 01:43 PM

数据库容量规划和扩展:MySQLvs.PostgreSQL引言:随着互联网的快速发展和大数据时代的到来,数据库的容量规划和扩展变得越来越重要。MySQL和PostgreSQL是两个流行的关系型数据库管理系统(RDBMS),它们在数据库容量规划和扩展方面有着不同的特点和适用场景。本文将对这两个数据库进行比较,并给出一些代码示例来展示它们的差异。一、MySQ

See all articles

Alat AI Hot

Undresser.AI Undress

Undresser.AI Undress

Apl berkuasa AI untuk mencipta foto bogel yang realistik

AI Clothes Remover

AI Clothes Remover

Alat AI dalam talian untuk mengeluarkan pakaian daripada foto.

Undress AI Tool

Undress AI Tool

Gambar buka pakaian secara percuma

Clothoff.io

Clothoff.io

Penyingkiran pakaian AI

AI Hentai Generator

AI Hentai Generator

Menjana ai hentai secara percuma.

Artikel Panas

R.E.P.O. Kristal tenaga dijelaskan dan apa yang mereka lakukan (kristal kuning)
3 minggu yang laluBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Tetapan grafik terbaik
3 minggu yang laluBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Cara Memperbaiki Audio Jika anda tidak dapat mendengar sesiapa
3 minggu yang laluBy尊渡假赌尊渡假赌尊渡假赌

Alat panas

MinGW - GNU Minimalis untuk Windows

MinGW - GNU Minimalis untuk Windows

Projek ini dalam proses untuk dipindahkan ke osdn.net/projects/mingw, anda boleh terus mengikuti kami di sana. MinGW: Port Windows asli bagi GNU Compiler Collection (GCC), perpustakaan import yang boleh diedarkan secara bebas dan fail pengepala untuk membina aplikasi Windows asli termasuk sambungan kepada masa jalan MSVC untuk menyokong fungsi C99. Semua perisian MinGW boleh dijalankan pada platform Windows 64-bit.

Pelayar Peperiksaan Selamat

Pelayar Peperiksaan Selamat

Pelayar Peperiksaan Selamat ialah persekitaran pelayar selamat untuk mengambil peperiksaan dalam talian dengan selamat. Perisian ini menukar mana-mana komputer menjadi stesen kerja yang selamat. Ia mengawal akses kepada mana-mana utiliti dan menghalang pelajar daripada menggunakan sumber yang tidak dibenarkan.

Penyesuai Pelayan SAP NetWeaver untuk Eclipse

Penyesuai Pelayan SAP NetWeaver untuk Eclipse

Integrasikan Eclipse dengan pelayan aplikasi SAP NetWeaver.

SublimeText3 versi Inggeris

SublimeText3 versi Inggeris

Disyorkan: Versi Win, menyokong gesaan kod!

mPDF

mPDF

mPDF ialah perpustakaan PHP yang boleh menjana fail PDF daripada HTML yang dikodkan UTF-8. Pengarang asal, Ian Back, menulis mPDF untuk mengeluarkan fail PDF "dengan cepat" dari tapak webnya dan mengendalikan bahasa yang berbeza. Ia lebih perlahan dan menghasilkan fail yang lebih besar apabila menggunakan fon Unicode daripada skrip asal seperti HTML2FPDF, tetapi menyokong gaya CSS dsb. dan mempunyai banyak peningkatan. Menyokong hampir semua bahasa, termasuk RTL (Arab dan Ibrani) dan CJK (Cina, Jepun dan Korea). Menyokong elemen peringkat blok bersarang (seperti P, DIV),