How to Start PostgreSQL Database Server manually in Linux

Posted on

Introduction

This article is an article which is the continuation of several previous articles. The main focus is to be able to start the PostgreSQL database server. The previous article available is an article with the title of ‘How to Install PostgreSQL Database Server using compressed file in CentOS 8’ in this link. That article is focusing only on the installation. Another related article also exist in the article with the title of ‘How to Initialize PostgreSQL Database in Linux’ in this link. The focus of that article is to initialize the PostgreSQL database server.

Starting PostgreSQL Database Server manually

The following are the steps for starting the PostgreSQL database server manually :

  1. First of all, switch to the user for managing PostgreSQL database server’s data. In order to manage the PostgreSQL database server’s data in appropriate manner, create a specific user account to do it. In the article in this link where the title is ‘How to Initialize PostgreSQL Database in Linux’, there is a new user created with the name of ‘pgsql’. Just switch to it by executing the following command :

    [root@10 ~]# su - pgsql
    Last login: Wed Jun 16 19:53:35 EDT 2021 on pts/1
    [pgsql@10 ~]$
  2. Do not forget to initialize the data of the PostgreSQL database server. Check the article in this link with the title of ‘How to Initialize PostgreSQL Database in Linux’ in order to do it.

  3. Following after, execute the following command to start the PostgreSQL server :

    [pgsql@10 ~]$ /opt/postgresql-12.0/app/bin/pg_ctl -D /opt/postgresql-12.0/data -l /opt/postgresql-12.0/data/startup.log start
    waiting for server to start.... done
    server started
    [pgsql@10 ~]$ 
    
  4. Another important part, just check the PostgreSQL database server’s process. It is to figure out whether the PostgreSQL database server is currently running or not. Just execute the following command to make sure of it :

    [pgsql@10 ~]$ ps -ef | grep postgres
    pgsql      85870       1  0 20:44 ?        00:00:00 /opt/postgresql-12.0/app/bin/postgres -D /opt/postgresql-12.0/data
    pgsql      85872   85870  0 20:44 ?        00:00:00 postgres: checkpointer
    pgsql      85873   85870  0 20:44 ?        00:00:00 postgres: background writer
    pgsql      85874   85870  0 20:44 ?        00:00:00 postgres: walwriter
    pgsql      85875   85870  0 20:44 ?        00:00:00 postgres: autovacuum launcher
    pgsql      85876   85870  0 20:44 ?        00:00:00 postgres: stats collector
    pgsql      85877   85870  0 20:44 ?        00:00:00 postgres: logical replication launcher
    pgsql      85879   85686  0 20:44 pts/1    00:00:00 grep --color=auto postgres
    [pgsql@10 ~]$ 
    
  5. Last but not least, just try to login to the PostgreSQL Command Line Console. Execute the following command :

    [pgsql@10 bin]$ psql -Upgsql postgres
    psql (12.0)
    Type "help" for help.
    postgres=#
    

As in the above output in the last step, the login process is a success. In other words, the process of starting the PostgreSQL database server is a success.

Leave a Reply