Introduction to PostgreSQL server startup and Shutdown

Source: Internet
Author: User

1. Start the database server (posgres user ):

  1. [S @ localhost bin] $ postgres-D/opt/postgresql/data/>/opt/postgresql/log/pg_server.log 2> & 1 &
  2. [1] 4508

Of course, if environment variables are set

  1. PGDATA=/Opt/postgresql/data
  2. Export PGDATA

You can use the pg_ctl tool to start:

  1. [S @ localhost log] $ pg_ctl start-l/opt/postgresql/log/pg_server.log
  2. Pg_ctl: another server might be running; trying to start server anyway
  3. Pg_ctl: cocould not start server
  4. Examine the log output.
  5. [S @ localhost log] $

Because it has already been started, print "another server might be running ". In this case, view the log with the following information:

  1. [S @ localhost log] $ cat pg_server.log
  2. FATAL: lock file "postmaster. pid" already exists
  3. HINT: Is another postmaster (PID 4491) running in data directory "/opt/postgresql/data "?
  4. [S @ localhost log] $

Of course, the simplest startup method is:

  1. [S @ localhost ~] $ Pg_ctl start
  2. Server starting
  3. [S @ localhost ~] $ LOG: database system was shut down at 13:58:00 CST
  4. LOG: autovacuum launcher started
  5. LOG: database system is ready to accept connections

If you want to start PG when the operating system is started, you can/Etc/rc. d/rc. localAdd the following statement to the file:

  1. /Opt/postgresql/bin/pg_ctl start-l/opt/postgresql/log/pg_server.log-D/opt/postgresql/data

2. Disable the server

The simplest method:

  1. [S @ localhost ~] $ Pg_ctl stop
  2. Waiting for server to shut down... done
  3. Server stopped

Similar to Oracle, Oracle can also adopt different modes when it is disabled. The introduction is as follows:

  1. SIGTERM
  2. New connections are no longer allowed, but all active sessions are allowed to complete their work normally. They are closed only after all sessions end the task. This is smart shutdown.
  3. SIGINT
  4. No longer allow new connections, send SIGTERM to all active servers (so that they exit immediately), and wait for all sub-processes to exit and shut down the database. This is quick close.
  5. SIGQUIT
  6. Enable ipvs to send SIGQUIT to all sub-processes and immediately exit (all sub-processes also exit immediately) without properly shutting down the database system. This is disabled immediately. This will cause recovery at the next startup (by replaying WAL logs ). We recommend that you use this method only in emergencies.
  7. SIGKILL
  8. This option should not be used as much as possible, which will prevent the server from cleaning up shared memory and Traffic Signal resources. In this way, you can only do this manually before starting the server. In addition, SIGKILL directly kills ipvs without waiting for it to relay the signal to its sub-processes. Therefore, we also need to manually kill each independent sub-process.

Example:

  1. [S @ localhost ~] $ Pg_ctl stop-o SIGTERM
  2. LOG: received smart shutdown request
  3. LOG: autovacuum launcher shutting down
  4. Waiting for server to shut down... LOG: shutting down
  5. LOG: database system is shut down
  6. Done
  7. Server stopped
  8. [S @ localhost ~] $

KillPostgresProcess

  1. [S @ localhost ~] $ Kill-INT 'head-1/opt/postgresql/data/postmaster. pid'
  2. [S @ localhost ~] $ LOG: received fast shutdown request
  3. LOG: aborting any active transactions
  4. LOG: autovacuum launcher shutting down
  5. LOG: shutting down
  6. LOG: database system is shut down

Note: The processes after postgre is started are as follows:

  1. [S @ localhost ~] $ Ps-ef | grep post
  2. Root 4609 4543 0 00:00:00 pts/2 su-ipvs
  3. S 4610 4609 0 00:00:00 pts/2-bash
  4. Postgres 4724 1 0 00:00:00 pts/2/opt/postgresql/bin/postgres
  5. Postgres 4726 4724 0? 00:00:00 ipvs: writer process
  6. Postgres 4727 4724 0? 00:00:00 ipvs: wal writer process
  7. Postgres 4728 4724 0? 00:00:00 postgres: autovacuum launcher process
  8. Postgres 4729 4724 0? 00:00:00 postgres: stats collector process
  9. Postgres 4752 4610 0 00:00:00 pts/2 ps-ef
  10. Postgres 4753 4610 0 00:00:00 pts/2 grep post
  11. [S @ localhost ~] $

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.