@@ -237,37 +237,19 @@ def ConfigureAndRestart(vm, run_uri, buffer_size):
237237 )
238238 vm .RemoteCommand (f'sudo cp /tmp/queries.sql { database_queries_path } ' )
239239 vm .RemoteCommand (f'sudo chmod 755 { database_queries_path } ' )
240- vm .RemoteCommand (
241- 'sudo sysctl -w'
242- f' vm.nr_hugepages={ SHARED_BUFFERS_CONF [buffer_size_key ]["nr_hugepages" ]} '
243- )
244- vm .RemoteCommand (
245- 'sudo sysctl -w vm.hugetlb_shm_group=$(getent group postgres | cut -d:'
246- ' -f3)'
247- )
248- vm .RemoteCommand ('cat /proc/meminfo | grep -i "^hugepage"' )
249- vm .RemoteCommand ('sudo cat /proc/sys/vm/hugetlb_shm_group' )
240+ # changes made to /proc do not persist after a reboot
241+ vm .RemoteCommand ('sudo sync; echo 3 | sudo tee /proc/sys/vm/drop_caches' )
250242 postgres_service_name = GetOSDependentDefaults (vm .OS_TYPE )[
251243 'postgres_service_name'
252244 ]
253- vm .RemoteCommand (
254- 'sudo systemctl set-property'
255- f' { postgres_service_name } .service'
256- f' MemoryMax={ SHARED_BUFFERS_CONF [buffer_size_key ]["max_memory" ]} '
257- )
245+ UpdateHugePages (vm , buffer_size_key )
246+
258247 if IsUbuntu (vm ):
259- vm .RemoteCommand (
260- 'sudo systemctl set-property'
261- f' { GetOSDependentDefaults (vm .OS_TYPE )["postgres_template_service_name" ]} .service'
262- f' MemoryMax={ SHARED_BUFFERS_CONF [buffer_size_key ]["max_memory" ]} '
263- )
264248 postgres_service_name = GetOSDependentDefaults (
265249 vm .OS_TYPE
266250 )['postgres_template_service_name' ]
267- vm .RemoteCommand ('sudo sync; echo 3 | sudo tee /proc/sys/vm/drop_caches' )
268- vm .RemoteCommand (
269- f'cat /etc/systemd/system.control/{ postgres_service_name } .service.d/50-MemoryMax.conf'
270- )
251+ UpdateMaxMemory (vm , buffer_size_key , postgres_service_name )
252+
271253 vm .RemoteCommand (
272254 'sudo su - postgres -c "openssl req -new -x509 -days 365 -nodes -text'
273255 f' -out { data_path } /server.crt -keyout'
@@ -284,6 +266,30 @@ def ConfigureAndRestart(vm, run_uri, buffer_size):
284266 )
285267
286268
269+ def UpdateHugePages (vm , buffer_size_key ):
270+ vm .RemoteCommand (
271+ 'sudo sysctl -w'
272+ f' vm.nr_hugepages={ SHARED_BUFFERS_CONF [buffer_size_key ]["nr_hugepages" ]} '
273+ )
274+ vm .RemoteCommand (
275+ 'sudo sysctl -w vm.hugetlb_shm_group=$(getent group postgres | cut -d:'
276+ ' -f3)'
277+ )
278+ vm .RemoteCommand ('cat /proc/meminfo | grep -i "^hugepage"' )
279+ vm .RemoteCommand ('sudo cat /proc/sys/vm/hugetlb_shm_group' )
280+
281+
282+ def UpdateMaxMemory (vm , buffer_size_key , postgres_service_name ):
283+ vm .RemoteCommand (
284+ 'sudo systemctl set-property'
285+ f' { postgres_service_name } .service'
286+ f' MemoryMax={ SHARED_BUFFERS_CONF [buffer_size_key ]["max_memory" ]} '
287+ )
288+ vm .RemoteCommand (
289+ f'cat /etc/systemd/system.control/{ postgres_service_name } .service.d/50-MemoryMax.conf'
290+ )
291+
292+
287293def SetupReplica (primary_vm , replica_vm , replica_id , run_uri , buffer_size ):
288294 """Setup postgres replica."""
289295 buffer_size_key = f'SIZE_{ buffer_size } GB'
@@ -318,28 +324,20 @@ def SetupReplica(primary_vm, replica_vm, replica_id, run_uri, buffer_size):
318324 'sudo echo -e "\n include = postgresql-custom.conf" | sudo tee -a'
319325 f' { os .path .join (conf_path , "postgresql.conf" )} '
320326 )
321- # vm.RemoteCommand('sudo chmod 660 postgresql.conf ')
322- replica_vm .RemoteCommand (
323- 'sudo sysctl -w'
324- f' vm.nr_hugepages={ SHARED_BUFFERS_CONF [buffer_size_key ]["nr_hugepages" ]} '
325- )
326- replica_vm .RemoteCommand (
327- 'sudo sysctl -w vm.hugetlb_shm_group=$(getent group postgres | cut -d:'
328- ' -f3)'
329- )
330- replica_vm .RemoteCommand ('cat /proc/meminfo |grep -i "^hugepage"' )
331- replica_vm .RemoteCommand ('sudo cat /proc/sys/vm/hugetlb_shm_group' )
332- replica_vm .RemoteCommand (
333- 'sudo systemctl set-property'
334- f' { GetOSDependentDefaults (replica_vm .OS_TYPE )["postgres_service_name" ]} .service'
335- f' MemoryMax={ SHARED_BUFFERS_CONF [buffer_size_key ]["max_memory" ]} '
336- )
327+ postgres_service_name = GetOSDependentDefaults (replica_vm .OS_TYPE )[
328+ 'postgres_service_name'
329+ ]
330+ UpdateHugePages (replica_vm , buffer_size_key )
331+ UpdateMaxMemory (replica_vm , buffer_size_key , postgres_service_name )
337332 replica_vm .RemoteCommand (
338333 'sudo sync; echo 3 | sudo tee -a /proc/sys/vm/drop_caches'
339334 )
340- replica_vm .RemoteCommand (
341- f'cat /etc/systemd/system.control/{ GetOSDependentDefaults (replica_vm .OS_TYPE )["postgres_service_name" ]} .service.d/50-MemoryMax.conf'
342- )
335+ if IsUbuntu (replica_vm ):
336+ postgres_service_name = GetOSDependentDefaults (
337+ replica_vm .OS_TYPE
338+ )['postgres_template_service_name' ]
339+ UpdateMaxMemory (replica_vm , buffer_size_key , postgres_service_name )
340+
343341 replica_vm .RemoteCommand (f'sudo chown -R postgres:root { data_path } ' )
344342 replica_vm .RemoteCommand (f'sudo chown -R postgres:root { conf_path } ' )
345343 replica_vm .RemoteCommand (
0 commit comments