Postgresql - Automatic database startup

 Colleagues hello to all.

In today's article, I will tell you how to set up automatic startup of the Postgresql database. As you remember, in the last article, I showed you how to install the Postgresql database from the source files. But if you restart the server or the server crashes, your database will not start after the server starts.

Download and install Postgresql 14 on Linux CentOS/RHEL 8/7 TAR

The first thing we will start with is to create a script that will be executed after the server is restarted.

$. vim /home/postgres/pgsql_autostart.sh

postgresql_autostart

 

After creating the  pgsql_autostart.sh file, add the following contents to it:

#!/bin/bash
#Automatic database start after server reboot
export PGHOME=/app/postgresql
export LD_LIBRARY_PATH=/app/postgresql/lib
export PGDATA=/app/postgresql/pgdatabase/data
export PATH=$PGHOME/bin:$PGDATA:$PATH
pg_ctl start

postgresql_autostart

 

Next, we assign the necessary rights to this file.

$. chmod +x pgsql_autostart.sh

postgresql_autostart

 

Now add this file to crontab.

$. crontab -e

postgresql_autostart

$. @reboot /home/postgres/admin_scripts/pgsql_autostart.sh

postgresql_autostart

 

That's it, now after restarting the server we will always run the script and start the database.

Comments

  1. Why dont we just use the default one? systemctl enable postgresql-14

    ReplyDelete

Post a Comment

Popular posts from this blog

PostgreSQL - Architecture

PostgreSQL - Backup & Point In Time Recovery

Installing pgbadger on Linux for PostgreSQL log analysis