This article will show some alternative or the way to check whether the PostgreSQL service in a host, server or workstation is actually active or not.
It is an important thing to do before any other things can be done especially connecting to PostgreSQL Database Server on the machine either locally or remotely.
By detecting whether the status of the service is actually active or not, it doesn’t take any longer just to spend and wasting time whether the connection to the PostgreSQL Database server can be initiated or not.
First of all, check whether PostgreSQL Database Server has already installed or not. It is important but this step can be skipped if it has already ensured that it really has. Be sure to check it and in Ubuntu Linux operating system, it can be done by using ‘apt’ command which can be read in the article about ‘List Installed Program in Ubuntu Linux using apt command’, if the operating system used is Ubuntu or any variant of Debian operating system distribution.
After that, in order to check the service whether it is active or not, it is important to know the service name which represents PostgreSQL Database Server. It can be done in several Linux operating system distribution by checking the service configuration file which is normally located in /etc depends on the Linux variant used. Type the following command to do that :
cat /etc/service | grep 5432
If PostgreSQL database server has already installed and it is configured to listen and handle request in port 5432, below is the possible outcome which is going to be shown by executing the above command in the bash prompt terminal :
user@hostname:~# cat /etc/services | grep 5432 postgresql 5432/tcp postgres # PostgreSQL Database postgresql 5432/udp postgres user@hostname:~#
It is understandable from the output shown above where the service name is ‘postgresql’. The next thing to do is checking whether that service name called ‘postgresql’ is active or at least the port which is assigned to the service is active and listening for processing request.
This is how to check whether the service is active or not :
service postgresql status
This is when it is executed in the bash prompt terminal and turned out the service is active :
user@hostname:~$ service postgresql status ● postgresql.service - PostgreSQL RDBMS Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled) Active: active (exited) since Min 2016-09-25 16:51:50 WIB; 2h 5min ago Process: 13371 ExecStart=/bin/true (code=exited, status=0/SUCCESS) Main PID: 13371 (code=exited, status=0/SUCCESS) Tasks: 0 Memory: 0B CPU: 0 CGroup: /system.slice/postgresql.service Sep 25 16:51:50 hostname systemd[1]: Starting PostgreSQL RDBMS... Sep 25 16:51:50 hostname systemd[1]: Started PostgreSQL RDBMS. user@hostname:~$
The other thing which is an alternative way to do it is by checking whether a specific port assigned for service relates to PostgreSQL Database Server is actively listening or not by executing the following command :
netstat -tulpn | grep 5432
The possible outcome if the PostgreSQL Database Server is running and it is configured to listen incoming request in port 5432 is shown below :
user@hostname:~$ netstat -tulpn | grep 5432 (Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.) tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN - user@hostname:~$
It is stated by the output above that in there is an open port which is listen for incoming request in localhost at port 5432.
12 thoughts on “Check PostgreSQL Service Status”