Actually, stopping the PostgreSQL database server can be done manually. There are several ways to do it. Those are using the ‘kill’ command to stop it completely. Stopping it using ‘kill’ command is the last resort to do it. One of the reason or the situation to use the ‘kill’ command is when the PostgreSQL database server starts using ‘postgres’ command. But in this context, stopping the PostgreSQL database server is using ‘pg_ctl’ which is defined in the service script. The manual way for stopping the PostgreSQL database server using ‘pg_ctl’ exist in the article in this link. That article has the title of ‘How to Stop PostgreSQL Database Server using pg_ctl execution in Linux’.
Stop PostgreSQL Database Server in Linux using Service Script
In this part, stopping the PostgreSQL database server is using service script in linux according to several context. The context is the installation environment and setting. It exist as in the article with the title of ‘How to Install PostgreSQL Database Server using compressed file in CentOS 8’ in this link. The base directory for the PostgreSQL database server in that article exist in ‘/opt/postgresql-12.0/app’. Another context is the data directory of the PostgreSQL database server. The data directory setting exist in the article with the title of ‘How to Initialize PostgreSQL Database in Linux’ in this link. In that context, the user responsible in the PostgreSQL database server management is ‘pgsql’.
Using the above context, stopping the PostgreSQL database server using ‘pg_ctl’ is possible just by execute a service script. Just read the article with the title of ‘How to Create a Service Script for PostgreSQL Database Server in Linux’ in this link. Basically, it is a line of service script where the main definition of it is using ‘pg_ctl’. In order to stop the PostgreSQL database server using service script, just execute the following command :
[root@10 yum.repos.d]# /etc/init.d/postgresql-12.0.service stop waiting for server to shut down.... done server stopped [root@10 yum.repos.d]#
The above file service script execution is using ‘postgresql-12.0.service to stop the PostgreSQL database server. It is obvious since the context of the file name is referring to the the article in this link. So, adjust the execution of the service script with the file name of the service script.