pg_ctl

Name

pg_ctl -- ������ֹͣ������ PostgreSQL

Synopsis

pg_ctl start [-w] [-s] [-D datadir] [-l filename] [-o options] [-p path]
pg_ctl stop [-W] [-s] [-D datadir] [-m s[mart] | f[ast] | i[mmediate] ]
pg_ctl restart [-w] [-s] [-D datadir] [-m s[mart] | f[ast] | i[mmediate] ] [-o options]
pg_ctl reload [-s] [-D datadir]
pg_ctl status [-D datadir]
pg_ctl kill [signal_name] [process_id]

����

pg_ctl ��һ������������ֹͣ�� �������� PostgreSQL ��˷�������postmaster���� ������ʾһ�������ŵķ�������״̬�Ĺ��ߣ� �������ǿ����ֶ����������������� pg_ctl ��װ�����¶�����־����� ���ն˺ͽ����������룬�Լ������ṩ��һ��ѡ�������п��ƵĹرա�

�� start ģʽ�������һ���µķ������� ���������ں�̨�����ģ���׼���뱻���ŵ��� /dev/null �ϡ����ʹ���� -l����ô��׼����ͱ�׼���󱻶���һ����־�ļ��� Ҫô�������¶��� pg_ctl �ı�׼����������DZ�׼���󣩡� ���û��ѡ����־�ļ���pg_ctl �ı�׼���Ӧ�����¶���һ���ļ������ùܵ�������� rotatelogs ��������־��ת���򣬷���postmaster �����������д�������նˣ��ں�̨�����ҽ��������� shell �Ľ����顣

�� stop ģʽ�£��Ǹ������ض�����Ŀ¼���еķ��������رա� ������� -m ѡ��ѡ�����ֲ�ͬ�Ĺر�ģʽ��"Smart" ģʽ�ȴ����пͻ����ж����ӡ� �����ȱʡ��"Fast" ģʽ�����ȴ��ͻ����ж����ӡ� ���л�Ծ���񶼱��ؾ��ҿͻ��˶�ǿ�ƶϿ��� "Immediate" ģʽ����û�иɾ��رյ�������˳�����ô��������������������ʱ��Ļָ���

restart ʵ��������ִ��һ��ֹͣ��Ȼ�����һ��������������任postmaster�����е�ѡ�

reload ģʽ�򵥵ظ�postmaster����һ�� SIGHUP �źţ����������¶�ȡ���������ļ� ��postgresql.conf��pg_hba.conf �ȵȣ� �����������޸������ļ�ѡ���������ȫ����ϵͳ��ʹ֮��Ч��

status ģʽ���һ���������Ƿ���ָ��������Ŀ¼���У� ����ǣ���ô��ʾ�� PID �͵�������������ѡ�

kill ģʽ�������һ��ָ���Ľ��̷����źš� ������ܶ� Microsoft Windows �ر����ã���Ϊ����û�� kill ��� ʹ�� --help �鿴֧�ֵ��źŵ����ֵ��б�

ѡ��

-D datadir

���������ݿ��ļ����ļ�ϵͳλ�á� ����������ѡ�ʹ�û������� PGDATA��

-l filename

�ѷ�������־��������� filename �ļ��ϡ� ������ļ������ڣ���ô��������umask����Ϊ 077�� ���ȱʡʱ�Dz�����������û�����־�ļ����ʵġ�

-m mode

�����ر�ģʽ��mode ������smart, fast, ���� immediate��������������֮һ�ĵ�һ����ĸ��

-o options

����Ҫֱ�Ӵ��ݸ�postmaster ��ѡ�

����ͨ�����õ�����˫���Ű�Χ�Ա�֤������Ϊһ�����崫�ݡ�

-p path

���� postmaster ��ִ���ļ���λ�á� ȱʡʱ postmaster �ǴӺ�pg_ctl��ͬ��Ŀ¼ȡ����������ǣ� ��ô����д���İ�װĿ¼����������ɵ�ʲô�ر�����飬���ҵõ�����û���ҵ� postmaster�����Ĵ��� ����û�б�Ҫʹ�����ѡ�

-s

ֻ��ӡ���󣬶�����ӡ��ʾ����Ϣ��

-w

�ȴ��������߹رյ���ɡ��� 60 ���ʱ�� ��������ǹر�ʱ��ȱʡֵ�� �ɹ��Ĺر�����ɾ�� PID �ļ�Ϊ��־�ġ������������ԣ� һ�γɹ��� psql -l �ͱ�־�ųɹ��� pg_ctl ����ͼʹ�ö� psql ���ʵĶ˿ڣ�������ڻ������� PGPORT����ô������ �����������ҿ����� postgresql.conf �ļ������Ƿ�������һ���˿ڡ� �����û�У�����ʹ�� PostgreSQL ����ʱ��ȱʡ�˿ڣ�ȱʡ�� 5432���� �ڵȴ���ʱ��pg_ctl �������������߹رյijɹ�״������һ��׼ȷ���˳����롣

-W

���ȴ���������ֹͣ����ɡ����������������ȱʡ��

����

PGDATA

ȱʡ����Ŀ¼λ��

PGPORT

psql ��ȱʡ�˿ڣ��� -w ѡ��ʹ�ã���

�����Ļ������������� postmaster��

�ļ�

postmaster.pid

����ļ�����������Ŀ¼����Ϊ�˰��� pg_ctl �жϷ�������ǰ�Ƿ������С�

postmaster.opts.default

�������ļ�����������Ŀ¼��pg_ctl���� start ģʽ�£������ļ������ݵ������ݸ� postmaster �����ѡ��ݹ�ȥ�����DZ� -o ѡ��ǡ�

postmaster.opts

�������ļ�����������Ŀ¼��pg_ctl����start ģʽ�£� �����ļ������ݵ������ݸ�postmaster �����ѡ��ݹ�ȥ�� ���DZ� -o ѡ��ǡ�����ļ�������Ҳ���� status ģʽ����ʾ������

postgresql.conf

����ļ�������Ŀ¼�У���������Բ��Һ� psql һ���õĺ��ʵĶ˿ڣ��� start ģʽ����� -w ��ʱ�򡣣�

���������Ŀ¼����� postmaster.opts.default �ļ�����ô���ļ�����Ϊѡ��ݸ� postmaster�� ���DZ� -o ѡ��ǡ�

ע��

�ȴ���ȫ����������һ������ú������IJ����� ������ʿ�������Ϊ���ؿͻ�����û���ֹ�����������²��ܷ��ʵĻ������ܻ�ʧЧ�������磬������֤����

����

����������

������������

$ pg_ctl start

������������һ�����ӣ� �ȵ������� �����˲��˳���

$ pg_ctl -w start

����һ�� postmaster ʹ�ö˿� 5433�����Ҳ��� fsync ���У�ʹ�ã�

$ pg_ctl -o "-F -p 5433" start

ֹͣ������

$ pg_ctl stop

ֹͣ��������ʹ�� -m �����������ǿ�������Ѻ��ͣ������ -w�ȴ�������ֹͣ��-m ������˵�ֹͣģʽ��

���������

��������������ֹͣ postmaster Ȼ������������ֻ����pg_ctl���沢����ʹ����һ������ postmaster �������в������������������򵥵ķ����ǣ�

$ pg_ctl restart

������������ȴ���ֹͣ������

$ pg_ctl -w restart

ʹ�� 5433 �����������ر� fsync��

$ pg_ctl -o "-F -p 5433" restart

��ʾ������״̬

���������� pg_ctl ��״̬��������ӣ�

$ pg_ctl status
pg_ctl: postmaster is running (pid: 13718)
Command line was:
/usr/local/pgsql/bin/postmaster '-D' '/usr/local/pgsql/data' '-p' '5433' '-B' '128'

����������ģʽ��ʹ�õ������С�

�ּ�

postmaster