How to shutdown postgres through psql?
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
2
down vote
favorite
The recommended way to shutdown postgres
is to send a signal representing the different shutdown modes (fast, smart, immediate). In a containerized environment it's sometimes more convenient to gain access through psql
than docker exec
and thus more convenient to stop the server through psql
. Is there a way to do that (given that the privileges have been granted)?
The solution can be hacky since this will mostly be used to stop a postgres
to delete a PostgreSQL data directory in a development environment.
postgresql psql shutdown
New contributor
Karl Richter is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
up vote
2
down vote
favorite
The recommended way to shutdown postgres
is to send a signal representing the different shutdown modes (fast, smart, immediate). In a containerized environment it's sometimes more convenient to gain access through psql
than docker exec
and thus more convenient to stop the server through psql
. Is there a way to do that (given that the privileges have been granted)?
The solution can be hacky since this will mostly be used to stop a postgres
to delete a PostgreSQL data directory in a development environment.
postgresql psql shutdown
New contributor
Karl Richter is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
The recommended way to shutdown postgres
is to send a signal representing the different shutdown modes (fast, smart, immediate). In a containerized environment it's sometimes more convenient to gain access through psql
than docker exec
and thus more convenient to stop the server through psql
. Is there a way to do that (given that the privileges have been granted)?
The solution can be hacky since this will mostly be used to stop a postgres
to delete a PostgreSQL data directory in a development environment.
postgresql psql shutdown
New contributor
Karl Richter is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
The recommended way to shutdown postgres
is to send a signal representing the different shutdown modes (fast, smart, immediate). In a containerized environment it's sometimes more convenient to gain access through psql
than docker exec
and thus more convenient to stop the server through psql
. Is there a way to do that (given that the privileges have been granted)?
The solution can be hacky since this will mostly be used to stop a postgres
to delete a PostgreSQL data directory in a development environment.
postgresql psql shutdown
postgresql psql shutdown
New contributor
Karl Richter is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Karl Richter is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 29 mins ago
New contributor
Karl Richter is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 1 hour ago
Karl Richter
1113
1113
New contributor
Karl Richter is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Karl Richter is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Karl Richter is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
2
down vote
The documentation tells you to send a signal to the master postgres
process, or to let pg_ctl
do this.
In SQL, you can extract the PID of the master process from pg_read_file('postmaster.pid')
, but pg_cancel_backend()
does not accept this PID.
However, you should be able to execute these commands with COPY (depending on what rights the postgres OS user has):
COPY (SELECT 1) TO PROGRAM 'kill -INT `head -1 /usr/local/pgsql/data/postmaster.pid`';
COPY (SELECT 1) TO PROGRAM 'pg_ctl -D /usr/local/pgsql/data stop';
add a comment |Â
up vote
1
down vote
No, that's not possible, you can not shutdown Postgres using psql
.
You can only shut it down through pg_ctl
or - preferrably - the "service control" of the underlying operating system, e.g. in CentOS that would be systemctl stop ...
in Ubuntu it would be service postgresql stop
or pg_ctlcluster 11 main stop
in Windows net stop ...
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
The documentation tells you to send a signal to the master postgres
process, or to let pg_ctl
do this.
In SQL, you can extract the PID of the master process from pg_read_file('postmaster.pid')
, but pg_cancel_backend()
does not accept this PID.
However, you should be able to execute these commands with COPY (depending on what rights the postgres OS user has):
COPY (SELECT 1) TO PROGRAM 'kill -INT `head -1 /usr/local/pgsql/data/postmaster.pid`';
COPY (SELECT 1) TO PROGRAM 'pg_ctl -D /usr/local/pgsql/data stop';
add a comment |Â
up vote
2
down vote
The documentation tells you to send a signal to the master postgres
process, or to let pg_ctl
do this.
In SQL, you can extract the PID of the master process from pg_read_file('postmaster.pid')
, but pg_cancel_backend()
does not accept this PID.
However, you should be able to execute these commands with COPY (depending on what rights the postgres OS user has):
COPY (SELECT 1) TO PROGRAM 'kill -INT `head -1 /usr/local/pgsql/data/postmaster.pid`';
COPY (SELECT 1) TO PROGRAM 'pg_ctl -D /usr/local/pgsql/data stop';
add a comment |Â
up vote
2
down vote
up vote
2
down vote
The documentation tells you to send a signal to the master postgres
process, or to let pg_ctl
do this.
In SQL, you can extract the PID of the master process from pg_read_file('postmaster.pid')
, but pg_cancel_backend()
does not accept this PID.
However, you should be able to execute these commands with COPY (depending on what rights the postgres OS user has):
COPY (SELECT 1) TO PROGRAM 'kill -INT `head -1 /usr/local/pgsql/data/postmaster.pid`';
COPY (SELECT 1) TO PROGRAM 'pg_ctl -D /usr/local/pgsql/data stop';
The documentation tells you to send a signal to the master postgres
process, or to let pg_ctl
do this.
In SQL, you can extract the PID of the master process from pg_read_file('postmaster.pid')
, but pg_cancel_backend()
does not accept this PID.
However, you should be able to execute these commands with COPY (depending on what rights the postgres OS user has):
COPY (SELECT 1) TO PROGRAM 'kill -INT `head -1 /usr/local/pgsql/data/postmaster.pid`';
COPY (SELECT 1) TO PROGRAM 'pg_ctl -D /usr/local/pgsql/data stop';
answered 48 mins ago
CL.
2,35011114
2,35011114
add a comment |Â
add a comment |Â
up vote
1
down vote
No, that's not possible, you can not shutdown Postgres using psql
.
You can only shut it down through pg_ctl
or - preferrably - the "service control" of the underlying operating system, e.g. in CentOS that would be systemctl stop ...
in Ubuntu it would be service postgresql stop
or pg_ctlcluster 11 main stop
in Windows net stop ...
add a comment |Â
up vote
1
down vote
No, that's not possible, you can not shutdown Postgres using psql
.
You can only shut it down through pg_ctl
or - preferrably - the "service control" of the underlying operating system, e.g. in CentOS that would be systemctl stop ...
in Ubuntu it would be service postgresql stop
or pg_ctlcluster 11 main stop
in Windows net stop ...
add a comment |Â
up vote
1
down vote
up vote
1
down vote
No, that's not possible, you can not shutdown Postgres using psql
.
You can only shut it down through pg_ctl
or - preferrably - the "service control" of the underlying operating system, e.g. in CentOS that would be systemctl stop ...
in Ubuntu it would be service postgresql stop
or pg_ctlcluster 11 main stop
in Windows net stop ...
No, that's not possible, you can not shutdown Postgres using psql
.
You can only shut it down through pg_ctl
or - preferrably - the "service control" of the underlying operating system, e.g. in CentOS that would be systemctl stop ...
in Ubuntu it would be service postgresql stop
or pg_ctlcluster 11 main stop
in Windows net stop ...
edited 57 mins ago
answered 1 hour ago
a_horse_with_no_name
37.2k772110
37.2k772110
add a comment |Â
add a comment |Â
Karl Richter is a new contributor. Be nice, and check out our Code of Conduct.
Karl Richter is a new contributor. Be nice, and check out our Code of Conduct.
Karl Richter is a new contributor. Be nice, and check out our Code of Conduct.
Karl Richter is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f221063%2fhow-to-shutdown-postgres-through-psql%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password