Thread: pg_ctl

pg_ctl

From
Tatsuo Ishii
Date:
As I promised, I have written a small program called "pg_ctl" to
start/stop/restart postmaster. I have committed into src/bin/pg_ctl.
Please remember to pull the latest postmaster.c.

o How to use

pg_ctl has three modes:

1. startup mode

pg_ctl [-w][-D database_dir][-p path_to_postmaster][-o "postmaster_opts"] start

start postmaster. If -w is specified, pg_ctl will block until database
is in the production mode. -D sets path to the database directory,
which overrides the environment variable $PGDATA. pg_ctl finds
postmaster.pid and other files under the directory. -p specifies the
path to postmaster. If -p is not given, default path (generated as
$(BINDIR)/postmaster while making pg_ctl from pg_ctl.sh) will be used.
If -o option is not given, pg_ctl will take options for postmaster
from $PGDATA/postamster.opts.default. Note that this file is not
currently installed by "make install." So you have to make it by hand
or could copy from postmaster.opts that is made once pg_ctl starts
postmaster. Sample postmaster.opts.default looks like:

postmaster
-S

or you could write it in one line:

postmaster -S

2. stop mode

pg_ctl [-w][-D database_dir][-m s[mart]|f[ast]|i[mmediate]] stop

stop postmaster. -m specifies database shutdown method.  The default
is "-m smart".

3. restart mode

pg_ctl [-w][-D database_dir][-m s[mart]|f[ast]|i[mmediate]][-o "postmaster_opts"] restart

stop postmaster, then start it again. Options to start postmaster is
taken from $PGDATA/postmaster.opts unless -o is given.

4. status reporting mode

pg_ctl [-D database_dir] status

reports status of postmaster. Currently reported information is
relatively limited. Hopefully we could add the functionarity to report
more valuable info such as number of backend running.

o sample session

Here is an example session using pg_ctl:

$ pg_ctl stop    # stop postmaster
postmaster successfully shut down.
$ pg_ctl stop    # cannot stop postmaster if it is not running
pg_ctl: Can't find /usr/local/src/pgsql/current/data/postmaster.pid.
Is postmaster running?
$ pg_ctl start    # start postmaster
postmaster successfully started up.
$ pg_ctl status    # status report
$ pg_ctl status
pg_ctl: postmaster is running (pid: 736)
options are:
/usr/local/src/pgsql/current/bin/postmaster
-p 5432
-D /usr/local/src/pgsql/current/data
-B 64
-b /usr/local/src/pgsql/current/bin/postgres
-N 32
-S
$ pg_ctl restart    # stop postmaster then start it again
Waiting for postmaster shutting down...done.
postmaster successfully shut down.
postmaster successfully started up.
$ pg_ctl status        # see how the pid is different from before
pg_ctl: postmaster is running (pid: 761)
options are:
/usr/local/src/pgsql/current/bin/postmaster
-p 5432
-D /usr/local/src/pgsql/current/data
-B 64
-b /usr/local/src/pgsql/current/bin/postgres
-N 32
-S
$ pg_ctl -o "-S -B 1024 -N 128 -o -F" restart    # restart with different options
Waiting for postmaster shutting down...done.
postmaster successfully shut down.
postmaster successfully started up.
$ pg_ctl status
pg_ctl: postmaster is running (pid: 961)
options are:
/usr/local/src/pgsql/current/bin/postmaster
-p 5432
-D /usr/local/src/pgsql/current/data
-B 1024
-b /usr/local/src/pgsql/current/bin/postgres
-N 128
-S
-o '-F'
--
Tatsuo Ishii


Re: [HACKERS] pg_ctl

From
Peter Eisentraut
Date:
On Mon, 6 Dec 1999, Tatsuo Ishii wrote:

> pg_ctl [-w][-D database_dir][-p path_to_postmaster][-o "postmaster_opts"] start

> postmaster.pid and other files under the directory. -p specifies the
> path to postmaster. If -p is not given, default path (generated as
> $(BINDIR)/postmaster while making pg_ctl from pg_ctl.sh) will be used.

May I issue a complaint? The use of the configure time generated BINDIR
for finding binaries at run time is not only an explicitly discouraged
abuse of the whole autoconf concept, it might potentially lead to big
problems when packages are built in temporary trees. I'm currently working
on a portable "which" alternative. When I get it done, I'll suggest that
one to you.

-- 
Peter Eisentraut                  Sernanders vaeg 10:115
peter_e@gmx.net                   75262 Uppsala
http://yi.org/peter-e/            Sweden



Re: [HACKERS] pg_ctl

From
Tatsuo Ishii
Date:
> May I issue a complaint? The use of the configure time generated BINDIR
> for finding binaries at run time is not only an explicitly discouraged
> abuse of the whole autoconf concept, it might potentially lead to big
> problems when packages are built in temporary trees. I'm currently working
> on a portable "which" alternative. When I get it done, I'll suggest that
> one to you.

Ok. let me know if you finish the work.
--
Tatsuo Ishii