Skip to main content

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 Vacuum and Vacuum full are not two different processes

  PostgreSQL’s   VACUUM   and   VACUUM FULL   are not separate processes but rather different operational modes of the same maintenance command. Here’s why: Core Implementation Both commands share the same underlying codebase and are executed through the  vacuum_rel()  function in PostgreSQL’s source code ( src/backend/commands/vacuum.c ). The key distinction lies in the  FULL  option, which triggers additional steps: Standard  VACUUM : Removes dead tuples (obsolete rows) and marks space reusable  within PostgreSQL Updates the visibility map to optimize future queries Runs concurrently with read/write operations VACUUM FULL : Rewrites the entire table into a new disk file, compressing it and reclaiming space for the  operating system Rebuilds all indexes and requires an  ACCESS EXCLUSIVE  lock, blocking other operations Key Differences in Behavior Aspect Standard VACUUM VACUUM FULL Space Reclamation Internal reuse onl...

PostgreSQL Health Check - Performance Audit and Recommendations

   PostgreSQL Server Capacity Planning and Optimization: Conduct a thorough assessment of current and projected workload demands on the database server's critical resources. This evaluation should cover key factors such as CPU utilization, RAM consumption, storage requirements, I/O performance, and network bandwidth usage. Consider both short-term fluctuations and long-term usage patterns to accurately forecast future needs and potential bottlenecks. Collect and analyze performance metrics over extended periods, including peak and off-peak hours, to gain a comprehensive understanding of server behavior. Use appropriate monitoring tools to gather detailed data on query execution times, resource utilization patterns, and system responsiveness under varying loads. Identify recurring performance issues, resource contention points, or capacity limitations that may affect the overall efficiency of the PostgreSQL environment. Based on this analysis, develop actionable recommendations...

PostgreSQL - Architecture

When you start PostgreSQL`s instance (via pg_ctl start) the main process of the databases is started. In the past versions it was known as the postmaster process and now days it is called postgres. When this processes is started it allocates memory for two main things : shared memory and other background processes. The shared memory is a memory that the database uses mainly for cashing. Its main goal is to reduce the I/O operations and as a result of that improve the performance of the database. The other processes that the postgres process starts are responsible for the ongoing work of the database.  PostgreSQL`s architecture is based on a client/server communication. In the server side there is a server process that manages the files, database operations, connection and so on.. On the client side there is a tool/program which can be a graphical tool (gui)  like pgAdmin or a command line tool(cli) like psql  that is repnsible for connection the database and all...