If you like DNray Forum, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...

 

PostgreSQL Overload Issues on DigitalOcean VPS Hosting

Started by cycoshas, May 10, 2023, 12:01 AM

Previous topic - Next topic

cycoshasTopic starter

Why is the processor heavily overloaded when using PostgreSQL? The user has a Django website with a database and about 100 daily visitors, hosted on DigitalOcean's VPS. However, the processor is being overloaded by PostgreSQL, with the server showing a load of 40+% per one request before rebooting. To prevent crashing, the user adjusted the settings as recommended by pgtune, but the site still experiences hangups.

The PostgreSQL logs show that there is insufficient memory, but the user cannot determine where the memory goes or why. The nginx-access logs do not indicate any unusual loads. The user seeks advice on how to locate the source of the problem and what to look for.

The pg config settings are mostly default except for several adjustments. Currently, things seem to be working fine, but the user is unsure when the issue will resurface.
  •  


timbarnard

One can speculate endlessly without achieving anything concrete, just like poking a finger in the sky.

To troubleshoot the issue at hand, first check the load on the screw and consider swapping it out if necessary.

Ensure that the keys are available in the respective fields before continuing with the task at hand.

If your device is running slow, investigate which programs and processes are consuming excessive memory to optimize performance.
  •  

brknny

It seems like the issue lies either in the code or in premature and hasty optimization of the database settings. On my end, I have a similar project using Django and Postgres9.1 on DigitalOcean, and I've never encountered such issues for years.

However, it's also possible that your system was hacked and malware was loaded onto it, causing the problems you're experiencing. The best way to diagnose the issue would be to provide logs, system metrics (such as top), and configuration details. Without these, it can be difficult to pinpoint the problem accurately.
  •  

burevestnik

To ensure optimal performance, adjust the parameters by replacing GB with MB and modifying work_mem. The shared_buffers should be 128MB and effective_cache_size at 384MB. Additionally, work_mem needs to be set at 4MB, while maintenance_work_mem requires setting to 32MB.

It has been noticed that VACUUM employs the maintenance_work_mem parameter, which currently stands at 2GB, as seen from the log. As a result of this error, the system's performance could be compromised.

To fix this, it is necessary to create a swap. This comes after identifying that there isn't any swap in the system from the htop output. Adding a swap would help to improve the system's overall performance and prevent potential crashes or lagging issues.
  •  

cAmoreme

It's important to consider the possibility of inefficient database queries causing the processor overload. The heavy load could be a result of poorly optimized queries, leading to excessive CPU usage when handling database requests. It would be beneficial to review the Django ORM queries and ensure they are efficiently utilizing PostgreSQL indexes and are not causing unnecessary strain on the processor.

Additionally, consider the memory allocation and usage within your VPS environment. As a hosting specialist, I would recommend closely monitoring the memory usage patterns of both Django and PostgreSQL processes. This involves analyzing the memory consumption of individual processes, identifying any memory leaks, and ensuring that the VPS has sufficient memory available to handle the workload. Tools such as htop or top can provide insights into memory usage and help pinpoint any processes that are consuming an excessive amount of memory.

I would suggest examining the PostgreSQL configuration settings in detail. While pgtune provides valuable recommendations, it's essential to tailor the settings to the specific requirements of your application and server environment. Focus on parameters such as shared_buffers, work_mem, and effective_cache_size to optimize memory usage and prevent resource exhaustion.

It's important to review the application code and database interactions for potential memory leaks or inefficient resource utilization. This includes inspecting the connection pooling configuration, object caching mechanisms, and use of database transactions within the Django application. Identifying and addressing any instances of resource contention or suboptimal memory usage is critical for stabilizing the performance of the website and PostgreSQL database.

It's vital to proactively monitor the website's performance and user engagement during peak traffic periods. This may involve leveraging tools such as Google Analytics to track user behavior and identify any slowdowns or interruptions that coincide with high processor loads. Understanding the impact of performance issues on user satisfaction and retention can underscore the urgency of addressing the PostgreSQL and memory-related challenges.
By approaching the issue from multiple perspectives, including database optimization, memory management, code review, and user experience analysis, you can gain a comprehensive understanding of the root causes behind the processor overload and memory constraints. This holistic approach will enable you to identify the source of the problem and implement targeted solutions to ensure the long-term stability and performance of your Django website and PostgreSQL database.
  •  


If you like DNray forum, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...