1. Start the database server (posgres user ):
- [S @ localhost bin] $ postgres-D/opt/postgresql/data/>/opt/postgresql/log/pg_server.log 2> & 1 &
- [1] 4508
Of course, if environment variables are set
- PGDATA=/Opt/postgresql/data
- Export PGDATA
You can use the pg_ctl tool to start:
- [S @ localhost log] $ pg_ctl start-l/opt/postgresql/log/pg_server.log
- Pg_ctl: another server might be running; trying to start server anyway
- Pg_ctl: cocould not start server
- Examine the log output.
- [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:
- [S @ localhost log] $ cat pg_server.log
- FATAL: lock file "postmaster. pid" already exists
- HINT: Is another postmaster (PID 4491) running in data directory "/opt/postgresql/data "?
- [S @ localhost log] $
Of course, the simplest startup method is:
- [S @ localhost ~] $ Pg_ctl start
- Server starting
- [S @ localhost ~] $ LOG: database system was shut down at 13:58:00 CST
- LOG: autovacuum launcher started
- 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:
- /Opt/postgresql/bin/pg_ctl start-l/opt/postgresql/log/pg_server.log-D/opt/postgresql/data
2. Disable the server
The simplest method:
- [S @ localhost ~] $ Pg_ctl stop
- Waiting for server to shut down... done
- Server stopped
Similar to Oracle, Oracle can also adopt different modes when it is disabled. The introduction is as follows:
- SIGTERM
- 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.
- SIGINT
- 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.
- SIGQUIT
- 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.
- SIGKILL
- 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:
- [S @ localhost ~] $ Pg_ctl stop-o SIGTERM
- LOG: received smart shutdown request
- LOG: autovacuum launcher shutting down
- Waiting for server to shut down... LOG: shutting down
- LOG: database system is shut down
- Done
- Server stopped
- [S @ localhost ~] $
KillPostgresProcess
- [S @ localhost ~] $ Kill-INT 'head-1/opt/postgresql/data/postmaster. pid'
- [S @ localhost ~] $ LOG: received fast shutdown request
- LOG: aborting any active transactions
- LOG: autovacuum launcher shutting down
- LOG: shutting down
- LOG: database system is shut down
Note: The processes after postgre is started are as follows:
- [S @ localhost ~] $ Ps-ef | grep post
- Root 4609 4543 0 00:00:00 pts/2 su-ipvs
- S 4610 4609 0 00:00:00 pts/2-bash
- Postgres 4724 1 0 00:00:00 pts/2/opt/postgresql/bin/postgres
- Postgres 4726 4724 0? 00:00:00 ipvs: writer process
- Postgres 4727 4724 0? 00:00:00 ipvs: wal writer process
- Postgres 4728 4724 0? 00:00:00 postgres: autovacuum launcher process
- Postgres 4729 4724 0? 00:00:00 postgres: stats collector process
- Postgres 4752 4610 0 00:00:00 pts/2 ps-ef
- Postgres 4753 4610 0 00:00:00 pts/2 grep post
- [S @ localhost ~] $