How to Start PostgreSQL Database Server in Linux using Service Script

Posted on

Introduction

In this article, the focus of the content is for starting the PostgreSQL database server. By default, it can be done manually. But it can also using a service script. Manually, it is using either ‘pg_ctl’ or ‘postgres’ command. But in the context of the service script, it is actually using ‘pg_ctl’ command. Check the article with the title of ‘How to Create a Service Script for PostgreSQL Database Server in Linux’ in this link.  So, after creating the service script, try to start the PostgreSQL database server using it. Actually, starting the PostgreSQL database server directly also exist in the article in this link. The article has a title of ‘How to Start PostgreSQL Database Server using pg_ctl execution in Linux’.

Start PostgreSQL Database Server in Linux using Service Script

So, this part is showing how to start PostgreSQL database server. The environment or the setting of the PostgreSQL database server for the installation as an example is using the one available in an article in this link. It is an article with the title of ‘How to Install PostgreSQL Database Server using compressed file in CentOS 8’. Another important part is the initialization part in the article in this link. That article has the title of ‘How to Initialize PostgreSQL Database in Linux’. So, the location of the application of the PostgreSQL database server as an example is in ‘/opt/postgresql-12.0/app’. Moreover, the location of the data directory of the PostgreSQL database server as an example is in ‘/opt/postgresql-12.0/db’. It is using a separate user account to manage the PostgreSQL database server which is ‘pgsql’.

The location of the PostgreSQL database server is in ‘/etc/init.d/’. The file is using the one given in the example in the article mentioned before. The one exist in this link with the title of ‘How to Create a Service Script for PostgreSQL Database Server in Linux’. The file representing the PostgreSQL service script is ‘postgresql-12.0.service’ as an example. So, the execution to start PostgreSQL database server using the service script exist as follows :

[root@10 ~]# /etc/init.d/postgresql-12.0.service start
waiting for server to start.... done
server started
[root@10 ~]#

Why is the above file service script execution is using ‘postgresql-12.0.service ?. That is because in the context of the article in this link is using that file name. Adjust the execution of the service script with the file name of the service script.

Leave a Reply