Wednesday, November 13, 2019

How to start/stop postgres services

How to start/stop postgres services 


Services are not running:

-bash-4.1$ ps -ef | egrep "pg|postgres"
root      85717  79705  0 20:35 pts/0    00:00:00 su - postgres
postgres  85718  85717  0 20:35 pts/0    00:00:00 -bash
postgres  85777  85718  1 20:35 pts/0    00:00:00 ps -ef
postgres  85778  85718  0 20:35 pts/0    00:00:00 egrep pg|postgres


Using postgres user try to start using below :

-bash-4.1$ cd /u01/postgres/bin

-bash-4.1$ ./pg_ctl -D /u01/postgres/data -l /u01/postgres/server.log start
pg_ctl: another server might be running; trying to start server anyway
waiting for server to start.... stopped waiting
pg_ctl: could not start server
Examine the log output.

-bash-4.1$

When searched got below error in logfile:

2017-08-06 20:35:26.620 IST [85781] FATAL:  data directory "/u01/postgres/data" has group or world access
2017-08-06 20:35:26.620 IST [85781] DETAIL:  Permissions should be u=rwx (0700).


-bash-4.1$ chmod -R 700 /u01/postgres/data

-bash-4.1$ ./pg_ctl -D /u01/postgres/data -l /u01/postgres/server.log start
pg_ctl: another server might be running; trying to start server anyway
waiting for server to start.... done
server started

-bash-4.1$  ps -ef | egrep "pg|postgres"
root      85717  79705  0 20:35 pts/0    00:00:00 su - postgres
postgres  85718  85717  0 20:35 pts/0    00:00:00 -bash
postgres  85834      1  0 20:36 pts/0    00:00:00 /u01/postgres/bin/postgres -D /u01/postgres/data
postgres  85835  85834  0 20:36 ?        00:00:00 postgres: logger process
postgres  85837  85834  0 20:36 ?        00:00:00 postgres: checkpointer process
postgres  85838  85834  0 20:36 ?        00:00:00 postgres: writer process
postgres  85839  85834  0 20:36 ?        00:00:00 postgres: wal writer process
postgres  85840  85834  0 20:36 ?        00:00:00 postgres: autovacuum launcher process
postgres  85841  85834  0 20:36 ?        00:00:00 postgres: stats collector process
postgres  85842  85834  0 20:36 ?        00:00:00 postgres: bgworker: logical replication launcher
postgres  85846  85718  0 20:36 pts/0    00:00:00 ps -ef
postgres  85847  85718  0 20:36 pts/0    00:00:00 egrep pg|postgres


-bash-4.1$ ./pg_ctl -D /u01/postgres/data -l /u01/postgres/server.log stop
waiting for server to shut down.... done
server stopped

-bash-4.1$ ps -ef | egrep "pg|postgres"
root      85717  79705  0 20:35 pts/0    00:00:00 su - postgres
postgres  85718  85717  0 20:35 pts/0    00:00:00 -bash
postgres  88181  85718  1 21:17 pts/0    00:00:00 ps -ef

postgres  88182  85718  0 21:17 pts/0    00:00:00 egrep pg|postgres


========================================================


Another way we can do using below:


-bash-4.1$ export PGDATA=/u01/postgres/data

-bash-4.1$ ./pg_ctl stop
waiting for server to shut down.... done
server stopped

-bash-4.1$ ps -ef | egrep "pg|postgres"
root      85717  79705  0 20:35 pts/0    00:00:00 su - postgres
postgres  85718  85717  0 20:35 pts/0    00:00:00 -bash
postgres  89097  85718  1 21:33 pts/0    00:00:00 ps -ef
postgres  89098  85718  0 21:33 pts/0    00:00:00 egrep pg|postgres

-bash-4.1$ ./pg_ctl start
waiting for server to start....2017-11-13 21:33:17.087 IST [89101] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2017-11-13 21:33:17.088 IST [89101] LOG:  listening on IPv6 address "::", port 5432
2017-11-13 21:33:17.098 IST [89101] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
2017-11-13 21:33:17.106 IST [89101] LOG:  redirecting log output to logging collector process
2017-11-13 21:33:17.106 IST [89101] HINT:  Future log output will appear in directory "log".
 done
server started





Thanks,

No comments:

Post a Comment