In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
PostgreSQL starts with the system
The document describe how to configure automatic start PostgreSQL when the system starts.
The ways suitable for systemd on CentOS 7.0 or latest release.
1. Create and configure postgresql.service
# vim / usr/lib/systemd/system/postgresql.service
[Unit]
Description=PostgreSQL database server
After=remote-fs.target nss-lookup.target
After=network.target sshd.service
After=proc-fs-nfsd.mount
After=network.target local-fs.target
After=nfs-config.service
After=nfs-mountd.service
After=nfs-blkmap.service
After=nfs-client.target
After=nfs-config.service
After=nfs-idmapd.service
After=nfs-idmap.service
After=nfs-lock.service
After=nfslock.service
After=nfs-mountd.service
After=nfs-secure-server.service
After=nfs-secure.service
After=nfs.service
After=nfs-utils.service
[Service]
Type=forking
User=postgres
Group=appuser
Environment=PGPORT=5432
Environment=PGDATA=/data/01/local/pgsql/data
ExecStart=/data/01/local/pgsql/bin/pg_ctl start-D ${PGDATA}-s-o "- p ${PGPORT}"-w-t 300
ExecStop=/data/01/local/pqsql/bin/pg_ctl stop-D ${PGDATA}-s-m fast
ExecReload=/data/01/local/pgsql/bin/pg_ctl reload-D ${PGDATA}-s
TimeoutSec=300
[Install]
WantedBy=remote-fs.target
# chmod 644 / usr/lib/systemd/system/postgresql.service
2. Reload systemd and enable postgresql.service
# systemctl daemon-reload
# systemctl enable postgresql.service
Created symlink from / etc/systemd/system/multi-user.target.wants/postgresql.service to / usr/lib/systemd/system/postgresql.service.
# systemctl is-enabled postgresql.service
Enabled
# systemctl start postgresql.service
# systemctl status postgresql.service
● postgresql.service-PostgreSQL database server
Loaded: loaded (/ usr/lib/systemd/system/postgresql.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2018-02-23 22:48:49 KST; 28min ago
Main PID: 2506 (postgres)
CGroup: / system.slice/postgresql.service
├─ 2506 / data/01/local/pgsql/bin/postgres-D / data/01/local/pgsql/data-p 5432
├─ 2508 postgres: logger process
├─ 2510 postgres: checkpointer process
├─ 2511 postgres: writer process
├─ 2512 postgres: wal writer process
├─ 2513 postgres: autovacuum launcher process
└─ 2514 postgres: stats collector process
Feb 23 22:48:47 ec5d-pbfcompilation-02 systemd [1]: Starting PostgreSQL database server...
Feb 23 22:48:48 ec5d-pbfcompilation-02 pg_ctl [1414]:
< 2018-02-23 22:48:48.671 KST >LOG: redirecting log output to logging collector process
Feb 23 22:48:48 ec5d-pbfcompilation-02 pg_ctl [1414]:
< 2018-02-23 22:48:48.671 KST >HINT: Future log output will appear in directory "pg_log".
Feb 23 22:48:49 ec5d-pbfcompilation-02 systemd [1]: Started PostgreSQL database server.
Note: CentOS7.x not support / etc/rc.local script file, Detailed description as following:
# cat / etc/rc.local
#! / bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
# it is wise to create a systemd service or udev rule to run scripts when the system is restarted, instead of using / etc/rc.local
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
# compared with previous system versions, / etc/rc.local will not run after other services are started because services are running in parallel when the system is started
#
# Please note that you must run 'chmod + x / etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
Although it is said here that the script can be executed using chmod + x / etc/rc.local, the author adds a line to the file: su-postgres-c 'pg_ctl start-D / usr/local/pgsql/data'
Then reboot tests many times, and postgres does not boot successfully with the system, so it is no longer recommended (and officially not recommended) to start postgres using / etc/rc.local file. It is the same to start other services. It is best to configure a systemd service.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.