PostgreSQL Start,Stop And Control the PostgreSQL Server
- Pg_ctl Utility & Postgresql Service to do the same thing: Start the postgres server in the background. Without PGDATA set, "pg_ctl start" needs needs the additional -D /datadir argument in order to start.
- whether You can start postgres Server as "root user" or "postgres user".
- as postgres user "su - postgres:"run "pg_ctl start -D /opt/PostgreSQL/9.3/data"
three Methods To start, stop, or control a PostgreSQL server. they are
- Pg_ctl Utility
- Postgresl -9.3 Script
- Postgresql Service
pg_ctl -- initialize, start, stop, or control a PostgreSQL server
./pg_ctl stop -D /opt/PostgresPlus/9.3AS/data/
./pg_ctl start -D /opt/PostgresPlus/9.3AS/data/
./pg_ctl reload -D /opt/PostgresPlus/9.3AS/data/
./pg_ctl status -D /opt/PostgresPlus/9.3AS/data/
Examples Starting and Stopping the Postgresql Server Using pg_ctl is a utility
Starting the Server:
$ pg_ctl startTo start the server, waiting until the server is accepting connections:
$ pg_ctl -w stopTo start the server using port 5433, and running without
fsync
, use:$ pg_ctl -o "-F -p 5432" start
[postgres@r1 bin]$ ./pg_ctl start -m fast -D /opt/PostgreSQL/9.3/data server starting [postgres@r1 bin]$ 2017-01-25 17:06:07 EST LOG: redirecting log output to logging collector process 2017-01-25 17:06:07 EST HINT: Future log output will appear in directory "pg_log".Stopping the Server:
To stop the server, use
$ pg_ctl stop
The -m option allows control over how the server shuts down[postgres@r1 bin]$ ./pg_ctl stop -m fast -D /opt/PostgreSQL/9.3/data waiting for server to shut down... done server stoppedRestarting the Server:
Restarting the server is almost equivalent to stopping the server and starting it again, except that pg_ctl saves and reuses the command line options that were passed to the previously running instance. To restart the server in the simplest form, use
$ pg_ctl restart
To restart the server, waiting for it to shut down and restart[postgres@r1 bin]$ ./pg_ctl -w restart -D /opt/PostgreSQL/9.3/data
waiting for server to shut down... done
server stopped
2017-01-25 17:03:54 EST LOG: redirecting log output to logging collector process
2017-01-25 17:03:54 EST HINT: Future log output will appear in directory "pg_log".
waiting for server to start.... done
server started
To restart using port 5433, disabling fsync
upon restart[postgres@r1 bin]$ ./pg_ctl -o "-F -p 5432" restart -D /opt/PostgreSQL/9.3/data
waiting for server to shut down.... done
server stopped
2017-01-25 17:01:41 EST LOG: redirecting log output to logging collector process
2017-01-25 17:01:41 EST HINT: Future log output will appear in directory "pg_log".
server starting
Showing the Server Status:Here is sample status output from pg_ctl
[postgres@r1 bin]$ ./pg_ctl status pg_ctl: no database directory specified and environment variable PGDATA unset Try "pg_ctl --help" for more information.Solution:
[postgres@r1 bin]$ ./pg_ctl status -D /opt/PostgreSQL/9.3/data pg_ctl: server is running (PID: 5188) /opt/PostgreSQL/9.3/bin/postgres "-D" "/opt/PostgreSQL/9.3/data"2.postgresql-9.3 script:
/etc/init.d/postgresql-9.3 start
/etc/init.d/postgresql-9.3 stop
/etc/init.d/postgresql-9.3 restart
/etc/init.d/postgresql-9.3 reload
/etc/init.d/postgresql-9.3 status
Examples Starting and Stopping the Postgresql Server Using "/etc/init.d/postgresql9.3 options" is a utility
Here we run as "Postgres" user
[postgres@r1 bin]$ /etc/init.d/postgresql-9.3 start
Starting PostgreSQL 9.3:
Password:
waiting for server to start.... done
server started
touch: cannot touch `/var/lock/subsys/postgresql-9.3': Permission denied
PostgreSQL 9.3 started successfully
Here we run as "root" user[root@r1 ~]# /etc/init.d/postgresql-9.3 start Starting PostgreSQL 9.3: waiting for server to start.... done server started PostgreSQL 9.3 started successfully3.Postgres service:
Service postgresql start
Service postgresql stop
Service postgresql restart
Service postgresql status
Comments
Post a Comment