Postgresql - Automatic database startup

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.


 

Thank you all, I hope that my article helped you in some way.

SIMILAR ARTICLES

PostgreSQL - How to determine which files on disk correspond to tables in a database
PostgreSQL - How to determine which files on disk correspond to tables in a database
POSTGRESQL
Read more
PostgreSQL - How to find out the size of tables in a database
PostgreSQL - How to find out the size of tables in a database
POSTGRESQL
Read more
PostgreSQL - How to check user privileges
PostgreSQL - How to check user privileges
POSTGRESQL
Read more