Editing Postgresql and shared memory

Jump to: navigation, search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 1: Line 1:
When running PostgreSQL or Oracle XE (APEX), some nuances of shared memory may arise.
+
I tried running PostgreSQL as one of my first experiments, and hit upon some nuances of shared memory, which may be helpful to relate here.
  
==== PostgreSQL ====
+
One of the easiest ways to increase Postgres's performance is to turn up the shared_buffers parameter in the postgresql.conf file; this is basically the amount of shared memory which the postmaster will use for buffering everything: table data, indexes, etc. The default value is really small, and if you have RAM to spare you may want to crank it up to 128MB (that's 16384 shared buffers, for pgsql 8.1 and earlier) or even more. But if it then complains that it couldn't allocate the shared memory, this page explains why.
One of the easiest ways to increase Postgres's performance is to turn up the shared_buffers parameter in the postgresql.conf file. This is basically the amount of shared memory which the postmaster will use for buffering everything: table data, indexes, etc. The default value is really small, and if you have RAM to spare you may want to crank it up to 128MB (16384 shared buffers, for pgsql 8.1 and earlier) or even more. After changing shared_buffers, it might complain that it couldn't allocate the shared memory, even though plenty of memory exists.
 
  
==== Oracle XE ====
+
PostgreSQL uses shared memory. As such, you have to check two things about the container.
A similar situation may occur when installing Oracle XE. The installation appears to succeed, but only the listener is running. No database instance is running. The database directory (/usr/lib/oracle/xe/oradata/XE) is empty. The log file /usr/lib/oracle/xe/app/oracle/admin/XE/bdump/alert_XE.log contains only a couple of lines that indicate success (but there should be many lines of output). Files in /usr/lib/oracle/xe/app/oracle/admin/XE/udump have an odd error "skgm warning: ENOSPC creating segment of size..." and suggest a change to the shared memory configuration, even though the shared memory values are what Oracle recommends. During installation, Oracle will add entries to /etc/sysctl.conf to set shared memory parameters.
 
  
==== Shared Memory ====
+
1. UBC's shmpages setting for this container. This dictates how many pages (one page is usually 4K, see [[memory page]] for more details) are available to the container, e.g. shmpages=16384 gives a limit of 64 MB of shared memory.
There are two things that control shared memory in a container.
 
  
1. The shmpages setting for this container (check [[UBC]]). This dictates how many pages (one page is usually 4K, see [[memory page]] for more details) are available to the container, e.g. shmpages=16384 gives a limit of 64 MB of shared memory.
+
2. "/sbin/sysctl kernel.shmmax"  This is the container's self-imposed limit on how much shared memory may be allocated in a single request, in bytes.
  
2. "/sbin/sysctl kernel.shmmax"  This is the container's self-imposed limit in bytes of how much shared memory may be allocated in a single request. You may check the shared memory configuration with "ipcs -l".
+
Get that? Not only does the HN impose a limit on the container's total shared memory usage, but the container itself has a setting for the maximum amount in a single chunk.
  
The HN imposes a limit on the container's total shared memory usage through shmpages, and the container itself imposes a limit on the container's total shared memory usage through kernel.shmmax. If the size of shmpages is less than kernel.shmmax, the database will not be able to allocate sufficient memory.
+
Some other notes:
  
==== Notes ====
+
* Note that shared memory is part of the container's overall memory usage. It is not a second memory pool.
* Shared memory is taken from the container's overall memory allocation. It is not a second memory pool.
 
  
* Other processes may be using shared memory, and shmpages includes things other than IPC shared memory (tmpfs, shmem, etc.). If this is the case for your container, set shmpages higher than the database requires.
+
* Note that processes other than PostgreSQL may be using shared memory, and also that shmpages includes stuff other than IPC shared memory (tmpfs, shmem, etc) So don't set shmpages to exactly the amount you want to give Postgres.
  
 
* The sysctl kernel.shmmax value set in the [[HN]]/[[CT0]] applies only to the [[HN]], not to [[container]]s.
 
* The sysctl kernel.shmmax value set in the [[HN]]/[[CT0]] applies only to the [[HN]], not to [[container]]s.

Please note that all contributions to OpenVZ Virtuozzo Containers Wiki may be edited, altered, or removed by other contributors. If you don't want your writing to be edited mercilessly, then don't submit it here.
If you are going to add external links to an article, read the External links policy first!

To edit this page, please answer the question that appears below (more info):

Cancel Editing help (opens in new window)